Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
More frequently in release than debug, I have a heap corruption error when I include a C++/CLR lib file. The error may be thrown before the first line in my executable executes.

C#
void _stdcall Execute_Query(const char * const Connection_String,
                            const char * const Query_Text,
                            bool const & Read_Only,
                            long & ErrorCode);


CLR can not be utilized with two separate libraries that I use in other projects, so I am isolating all CLR code in a separate dll.

The function Execute_Query above internally uses ADO .NET, but all of it's inputs are native C++. Is it incorrect to call the function above from Native C++ directly or do I need to use PInvoke or something else?
Posted

Native c++ is using the cdecl calling convention. Here an atricle about those calling conventions. This will already give some insight in the problem.
Calling Conventions Demystified[^]

Wrapper dll example:
Easy to use Wrapper (DLL) for Intel's OpenCV Library with Examples[^]

Good luck!
 
Share this answer
 
Comments
T2102 27-Sep-10 1:21am    
The Wrapper dll example is C# code. I am trying to find out if I need to do anything special to call function in a C++ dll that utilized ADO .NET, but whose function inputs are all native C++ types. I am able to call the function directly like I would any other native C++ dll function, however I want to know whether or not this could cause managed heap corruption.
T2102 27-Sep-10 1:22am    
Note that I mainly work with native C++ and C++/CLI is incompatible with two other libraries I utilize, so I cannot use mixed programming. I also do not want to add the overhead of using C#.
This problem disappeared when I changed the compiler options to not use Whole Program Optimization.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900