[問題] C# 使用C產生的DLL

作者: hardman1110 (笨小孩)   2015-12-08 13:30:51
目前已完成:
1. 已使用C在a專案產生DLL,並且在b專案(cpp)載入並使用
2. 在專案c(c# form)裡加入a專案的dll
[DllImport("Win32Project2.dll", EntryPoint = "Add")]
public static extern int Add(int a, int b);
3. 直接點c專案的.exe (dll也放在一起) 可以正常執行
問題:
用偵錯模式(F5)跑到dll中的function時會出現以下錯誤:
Managed Debugging Assistant 'PInvokeStackImbalance'
has detected a problem in
'D:\test_code\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe'.
wsFormsApplication1.vshost.exe'
Additional information: 對 PInvoke 函式 'WindowsFormsApplication1!
我應該是載入成功了但為何只有debug模式會出錯呢? 懇請各位大大賜教
作者: fo40225   2015-12-08 21:51:00
C++的function加上 __stdcall 或CallingConvention.Cdecl
作者: hardman1110 (笨小孩)   2015-12-08 22:35:00
請問是加在dll的專案嗎? 敢問原理是?
作者: james732 (好人超)   2015-12-09 10:44:00
拿一樓的關鍵字去google看看?

Links booklink

Contact Us: admin [ a t ] ucptt.com