我在一个C++ dll中定义了一个回调机制,如下typedef void (*InfoReceiverCallBack)(const char* pInfo);InfoReceiverCallBack lpInfoCallback = NULL;HRESULT RegisterInfoReceiveCallBack(InfoReceiverCallBack callBack)
{
lpInfoCallback = callBack;
return S_OK;
}//其他函数调用
void TraceInfo(const char* c)
{
TRACE(c);
if(lpInfoCallback != NULL)
{
lpInfoCallBack(c);
}
}在C#中定义如下: public delegate void InfoReceiveDelegate(
string info);
[DllImport("XXX.dll", CallingConvention = CallingConvention .Cdecl)]
public static extern int RegisterInfoReceiveCallBack(
InfoReceiveDelegate infoReceiver);然后有一个显示函数:
void Output(string info)
{
//XXXXXXXXX
}每次设置断点后信息正常,但是跳出函数时出现如下错误:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call, This is usually a result of calling a function declared with one calling conversion with a function pointer declared with a different calling convertion.我的C++类库是用_Cdecl调用约定,改为_Stdcall编译不过去,因为有一个第三方的lib.
我写了一个C++测试程序,是没有问题的。
到底是什么问题??
请指教,多谢多谢
{
lpInfoCallback = callBack;
return S_OK;
}//其他函数调用
void TraceInfo(const char* c)
{
TRACE(c);
if(lpInfoCallback != NULL)
{
lpInfoCallBack(c);
}
}在C#中定义如下: public delegate void InfoReceiveDelegate(
string info);
[DllImport("XXX.dll", CallingConvention = CallingConvention .Cdecl)]
public static extern int RegisterInfoReceiveCallBack(
InfoReceiveDelegate infoReceiver);然后有一个显示函数:
void Output(string info)
{
//XXXXXXXXX
}每次设置断点后信息正常,但是跳出函数时出现如下错误:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call, This is usually a result of calling a function declared with one calling conversion with a function pointer declared with a different calling convertion.我的C++类库是用_Cdecl调用约定,改为_Stdcall编译不过去,因为有一个第三方的lib.
我写了一个C++测试程序,是没有问题的。
到底是什么问题??
请指教,多谢多谢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货