C # calling C++dll Library calling convention issues

Source: Internet
Author: User

DEBUG Error Symptom alert run-time Check Failure #0-the value of ESP is not properly saved across a function call. This was usually a result of calling a function declared with one calling convention with a function pointer declared with A different calling convention release version of the application disappears without any information. C # and C + + both explicitly define __stdcall as the function calling convention, but debug version debugging still prompts the above phenomenon, the effect is that the callback function of the calling convention is inconsistent. The troubleshooting is not the calling convention inconsistency, but the parameter of the callback function is inconsistent, causing the callback function to release the stack memory is an exception. The callback function in the C++dll Library defines typedef void (CALLBACK *prhmessagecallback) (int ivk_value, int iflag, void* puserdata); This should be the correct definition in C #:

[Unmanagedfunctionpointer (Callingconvention.stdcall)]
public delegate void Prhmessagecallback (int ivk_value, int iflag, IntPtr userData);

and cannot be defined as

[Unmanagedfunctionpointer (Callingconvention.stdcall)]
public delegate void Prhmessagecallback (int ivk_value, int iflag, object userData);

C # calling C++dll Library calling convention issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.