簡體   English   中英

我是否正確地調用了這個C ++ DLL?

[英]Am I calling this C++ DLL correctly?

我需要從C#調用C ++ DLL函數,C ++函數定義是

DWORD Init(char*[],int,int,int);

而我正在用C#這樣稱呼它

[DllImport("DLLTest.dll")]
unsafe public static extern int Init(string[] detailsarray, int amount, int ID1, int ID2);

//then in main...

string[] details = new string[3];
details[0] = "blahblah";
details[1] = "bloobloo";
details[2] = "1234";

int result = Init(details, 1, 16, 170);

當我運行它時,我得到一個類型為System.BadImageFormatException的未處理異常。 我相信當C ++ DLL期待char *時可以通過字符串,我也認為可以在C#中使用int來代替C ++中的DWORD,但如果我是正確的,請告訴我。

謝謝。

編輯 - 我應該補充一點,我已經在C ++應用程序中測試了DLL,它運行正常。

如果您嘗試將32位DLL加載到64位進程中,則通常會發生BadImageFormatException,反之亦然。 如果DLLTest.dll是32位DLL,則需要為x86平台編譯C#DLL,而不是任何CPU

http://msdn.microsoft.com/en-us/library/zekwfyz4(v=vs.100).aspx

http://davidstechtips.com/wp-content/uploads/2010/06/VisualStudioPlatformTargetx86.png

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM