C#学习教程:“运行时检查失败#0-在从C++代码成功进行C#回调后,ESP的值未在函数调用中正确保存”在代码成功执行C#回调后,函数调用未正确保存”我正在制作一个使用GameSpyC代码的C#应用程序(GP部分)。C代码成功调用回调(它是C#代码),但我收到此错误Run-TimeCheckFailure#0-ESP的值未正确保存在回调完成后的函数调用运行时检查中Failure#0-ESP的值未在函数调用中正确保存。我用C代码制作了一个DLL,如下所示://GPCallback////////////__declspec(dllexport)typedefvoid(*GPCallback)(GPConnection*connection,void*arg,void*参数);//gpConnect///////////__declspec(dllexport)GPResultgpConnect(GPConnection*connection,constgsi_charnick[GP_NICK_LEN],constgsi_charemail[GP_EMAIL_LEN],constgsi_charpassword[GP_PASSWORD_LEN],GPEnumfirewall,GPEnum阻塞,GPCallback回调,void*param);C#就像这样调用它:unsafepublicdelegatevoidGPCallback(GPConnection*connection,//GPConnectResponseArgarg,IntPtrarg,IntPtrparam);[DllImport("saketestd.dll")]unsafestaticexternGPResultgpConnect(GPConnection*connection,gsi_charnick,gsi_charemail,gsi_charpassword,GPEnumfirewall,GPEnumblocking,GPCallbackcallback,IntPtrparam);不安全的公共布尔gpConnectE(){boolret=false;尝试{GPResultres;debug.AddLine(this.getMethodName()+":"+"连接前的连接:"+connection.ToString("x"));fixed(int*pconn=&connection){res=gpConnect(pconn,this.NICK,this.EMAIL,this.PASSWORD,GPEnum.GP_NO_FIREWALL,GPEnum.GP_BLOCKING,newGPCallback(this.ConnectResponse),IntPtr.Zero);}debug.AddLine(this.getMethodName()+":"+"connectionafterconnect:"+connection.ToString("x"));if(res!=GPResult.GP_NO_ERROR){debug.AddLine(this.getMethodName()+":"+"失败:"+res);}else{debug.AddLine(this.getMethodName()+":"+"OK");ret=true;}}catch(Exceptionex){debug.Text+=ex.ToString();}returnret;}unsafepublicvoidConnectResponse(GPConnection*connection,//GPConnectResponseArgarg,IntPtrargPtr,IntPtrparam){debug.AddLine(this.getMethodName()+"调用了connection:"+(*connection).ToString("x"));GPConnectResponseArgarg;arg=(GPConnectResponseArg)Marshal.PtrToStructure(argPtr,typeof(GPConnectResponseArg));if(arg.result==GPResult.GP_NO_ERROR){调试.AddLine(this.getMethodName()+":连接到GP");this.profileid=arg.profile;}else{debug.AddLine(this.getMethodName()+":failed");debug.AddLine(this.getMethodName()+":结果:"+arg.result);debug.AddLine(this.getMethodName()+":profile:"+arg.profile);debug.AddLine(this.getMethodName()+":uniquenick:"+arg.uniquenick);我相信我需要清除回调中的堆栈或更改DLL中的调用约定(可能吗?)还有其他想法吗?检查您正在使用的调用约定。[UnmanagedFunctionPointer(CallingConvention.Cdecl)]参考其他相关问题:CallbackfromCfunction-CrashProblemsolvedbymyselfaccidently(after5hoursofgoogling)。我已经怀疑调用约定错误,但我不知道如何正确切换它。我在此处建议的C代码中更改了它(http://computerarts.com.cn/dotnet-tech/1691/):以上是C#学习教程:“Runtimecheckfailed#0-successfromC++codeAftertheC#callback,函数调用中ESP的值没有正确保存》所有内容分享,如果对大家有用,需要了解更多C#学习教程,希望大家多多关注—//GPCallback//////////////__declspec(dllexport)typedefvoid(*GPCallback)(//typedef__declspec(dllexport)void(*GPCallback)(typedefvoid(_stdcall*GPCallback)(GPConnection*connection,void*arg,void*param);本文采集自网络,不代表立场,如涉及侵权,请点击右边联系管理员删除,转载请注明出处:
