1、異常提示資訊為:函數調用導緻堆棧不對稱。原因可能是托管的 PInvoke 簽名與非托管的目标簽名不比對。
2、出現場景:這種異常大多出現在C#調用C++的動态庫時。
3、處理方法
把 [DllImport("winmm.dll", EntryPoint = "sndPlaySoundA",)]
改為[DllImport("winmm.dll", EntryPoint = "sndPlaySoundA" , CallingConvention = CallingConvention.Cdecl)]
//C#中引入C++ DLL庫
//[DllImport("bq80xrw.dll", EntryPoint = "GetAdapterFWVersion")]
[DllImport("bq80xrw.dll", EntryPoint = "GetAdapterFWVersion, CallingConvention = CallingConvention.Cdecl)]
public static extern int GetAdapterFWVersion([MarshalAs(UnmanagedType.LPStr)]string FWVersion);