检测到PInvokeStackUnbalance

检测到PInvokeStackUnbalance

本文介绍了检测到PInvokeStackUnbalance的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试使用第三方本机dll.在我的.net应用程序中.我正在使用c#.本机dll中的功能.具有以下声明:

Hi
I am trying to use a third party native dll. in my .net application. I am using c#. The function in native dll. has the following declaration:

void _stdcall pir_learnCCF( const char * serial, unsigned char state );



使用PInvoke Interop助手,我可以进行以下导入:



With the PInvoke Interop assistant I get the following import:

[DllImport("PIRLIB.dll", EntryPoint = "pir_learnCCF")]
public static extern void pir_learnCCF(
[InAttribute()] [MarshalAsAttribute(UnmanagedType.LPStr)] string serial,
byte state);



我有以下问题.使用PInvoke互操作助手时,我必须从非托管函数定义中删除"_stdcall",否则助手会生成错误.在删除"_stdcall"之后,助手会生成上述使用语句,但是当我尝试调用该函数时,会检测到PInvokeStackUnbalance.第三方dll.具有其他功能,这些功能通常可以与Interop Assistant生成的导入语句一起使用.任何建议将不胜感激.

Uroš



I have the following questions. When using PInvoke interop assistant I have to remove the "_stdcall" from unmanaged function definition, otherwise the assistant generates an error. After I remove the "_stdcall" the assistant generates the above using sentence but when I try to call the function I get the PInvokeStackUnbalance detected. The third party dll. has other functions which work normally with import sentences generated by the Interop Assistant. Any advice will be appreciated.

Uroš

推荐答案

DllImport("PIRLIB.dll", EntryPoint = "pir_learnCCF", CallingConvention = CallingConvention.Cdecl)]
public static extern void pir_learnCCF(string serial, byte state);



参见:
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.callingconvention.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system. runtime.interopservices.callingconvention.aspx [ ^ ].

—SA



See:
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.callingconvention.aspx[^],
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.callingconvention.aspx[^].

—SA


这篇关于检测到PInvokeStackUnbalance的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 15:01