To the PInvoke function "winvideo! Winvideo.webcam::sendmessage "calls result in stack asymmetry

Source: Internet
Author: User

The pinvokestackimbalance error that occurs when upgrading from. NET1.1 to. NET2.0 Microsoft Official Explanation (http://msdn2.microsoft.com/zh-cn/library/0htdy0k3.aspx) if The pInvokeStackImbalance managed debugging assistant (MDA) is activated when the CLR detects that the stack depth after the platform call does not match the expected stack depth provided in the calling convention specified by the DllImportAttribute property and in the parameter declaration of the managed signature. Here is a concrete example of the Pccamera class (UserLib.Device.PCCamera camera Class) in the slave. NET1.1 an pinvokestackimbalance error occurred while upgrading to. NET2.0: Pinvokestackimbalancemessage detected: PInvoke function windowsapplication1! Userlib.device.pccamera::sendmessage "calls result in stack asymmetry. The reason may be that the managed PInvoke signature does not match the unmanaged target signature. Please check that the calling convention and parameters of the PInvoke signature match the unmanaged target signature. The error first occurred in this line of code: SendMessage (HWNDC, wm_cap_set_callback_videostream, 0, 0); The analysis found that all calls to the SendMessage function appear in the above error and then view Dllimport:[dllimport ("User32.dll")] private static extern bool SendMessage ( INTPTR hWnd, int wmsg, int wParam, long lParam); originally because the long type of WINAPI is 32-bit, and C # 's long is 64-bit www.dgdaming.com, which leads to stack asymmetry, Raises an error. Reason: (http://discuss.develop.com/archives/wa.exe?A2=ind0512c&L=dotnet-winforms&D=0&T=0&am

New starting point for 3G video phone

P p=8094) added MDA (Managed debugging assistant) in. NET2.0, which checks the stack pointer after the platform call, and throws a pInvokeStackImbalance exception if the imbalance is found; And in. NET1.1 will not be checked, so exceptions will not be caught, but will cause instability at run time. Workaround: Change the last "long LParam" to "int wParam" because int is 32-bit in C #. And then there will be a parameter that involves the SendMessage function is properly converted to an int type. However, the information was then consulted http://www.pinvoke.net/default.aspx/user32/ Sendmessage.html found that the previous solution was inappropriate, and that the types of the "Wparm" and "lparm" parameters should be converted to the INTPTR type, and "0" to "IntPtr.Zero" of the parameters to be referred to later. Because if you use the int type, this code will not work correctly on 64-bit Windows. Summary: We should be very careful when calling WINAPI, because WINAPI and C # data types are not exactly the same, As if the long type in WINAPI is an int type in C #, it is likely to cause an imbalance in the stack and throw a pinvokestackimbalance error if the type problem is not handled, but such errors are in. NET1.1 will not be exposed, so in from. NET1.1 when upgrading to. NET2.0 pay special attention to such issues.

To the PInvoke function "winvideo! Winvideo.webcam::sendmessage "calls result in stack asymmetry

Related Article

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.