从本机C ++ exe调用ADO .NET的托管堆损坏 [英] managed heap corruption calling ADO .NET from native C++ exe
问题描述
在发行中比调试更频繁,当我包含C ++/CLR lib文件时,出现堆损坏错误.错误可能在可执行文件的第一行执行之前引发.
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.
void _stdcall Execute_Query(const char * const Connection_String,
const char * const Query_Text,
bool const & Read_Only,
long & ErrorCode);
无法将CLR与我在其他项目中使用的两个单独的库一起使用,因此我将所有CLR代码隔离在一个单独的dll中.
上面的Execute_Query函数在内部使用ADO .NET,但是所有输入都是本机C ++.直接从Native C ++调用上面的函数是否不正确,还是我需要使用PInvoke或其他方法?
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?
推荐答案
本地c ++使用的是cdecl调用约定.这是有关这些调用约定的通俗易懂的文章.这已经可以使您对该问题有所了解.
已解密的呼叫约定 [易于为示例使用英特尔OpenCV库的包装器(DLL) [
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!
当我将编译器选项更改为不使用整个程序优化"时,此问题消失了.
This problem disappeared when I changed the compiler options to not use Whole Program Optimization.
这篇关于从本机C ++ exe调用ADO .NET的托管堆损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!