Re: [問題] 匯入c++寫的dll檔

看板C_Sharp (C#)作者 (躂躂..)時間18年前 (2007/07/09 10:28), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《ireullin (raison detre)》之銘言: : 請問各位我要把c++寫成的dll檔在c#中使用 : 可是一直遇到 "找不到名稱為 fnLibEncrypt 的進入點 (在 DLL LibEncrypt.dll 中)"的 因為在C++時(考慮到overloading), 所以 fnLibEncrypt 不會直接變成 fnLibEncrypt 這個symbol. (依不同的compiler), 會變成像 fnLibEncrypt_void 之類的symbol. Visual Studio本身有提供一個命列令小工具(dumpbin)可以看被簽什麼樣, 不然你也可以用 http://www.dependencywalker.com/ 這個視窗介面的工具檢視 該 DLL exports 出的symbol.. (VC簽出來應該是 ?fnLibEncrypt@@YAPADXZ 之類的東西吧..不確定..) : [DllImport( : "LibEncrypt.dll",EntryPoint="fnLibEncrypt",CharSet=CharSet.Auto,CallingConvention=CallingConvention.StdCall)] : public static extern int fnLibEncrypt(); 所以, 解決方法有兩種 1. (不建議.) 把 EntryPoint 改成 "?fnLibEncrypt@@YAPADXZ" (請自行查明他被簽成什麼) btw, EntryPoint可以不寫(如果和method name一樣的話..) 2. 在你的DLL那邊在 fnLibEnctrypt的最前面加入 extern "C" 讓 compiler 知道要把他編成 C-function. 編出來的東西就會像其他的c-function 一樣.. 那EntryPoint就會是 fnLibEncrypt 了~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.139.136.137 ※ 編輯: cole945 來自: 220.139.136.137 (07/09 10:33)
文章代碼(AID): #16aPrdE0 (C_Sharp)
討論串 (同標題文章)
文章代碼(AID): #16aPrdE0 (C_Sharp)