对PInvoke函数函数调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。

对PInvoke函数函数调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。

C#引入外部非托管类库时,有时候会出现“对PInvoke函数调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配”的报错。

通常在DllImport标签内加入属性CallingConvention=CallingConvention.Cdecl即可解决该问题。

如:     
  [DllImport("AutoAnalyse.dll", EntryPoint="Measure", CallingConvention=CallingConvention.Cdecl)]  
       public static extern string Measure(string baseKey, string project);