[問題] GetProcAddress與namespace

看板C_and_CPP (C/C++)作者 (NEWLYMOON)時間10年前 (2015/11/05 12:05), 10年前編輯推噓2(207)
留言9則, 4人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) c++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 使用GetProcAddress無法抓到正確的函式位址 餵入的資料(Input): 預期的正確結果(Expected Output): result=-151 錯誤結果(Wrong Output): result=NULL 程式碼(Code):(請善用置底文網頁, 記得排版) //呼叫dll typedef int (*testonly)(int); int main() { testonly result ; HINSTANCE hLibrary = LoadLibrary("IntimeDllCpp.dll"); if(hLibrary) { result = (testonly)GetProcAddress(hLibrary, "IntimeDllCpp::CGMCU::GetMode"); if(result) { std::cout << result(0) << std::endl; } FreeLibrary(hLibrary); } else { std::cout << "Failed To Load Library" << std::endl; } system("pause"); return 0; } //dll函式 namespace IntimeDll2UI { public ref class CGMCU //A00254 104.03.19 { public: LONG GetMode(LONG iIndex); }; } 補充說明(Supplement): 請問一下因為我的函式在namespace下,該如何 設定GetProcAddress內的參數呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 219.87.179.165 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1446696347.A.ECC.html ※ 編輯: newlymoon (219.87.179.165), 11/05/2015 12:07:25 ※ 編輯: newlymoon (219.87.179.165), 11/05/2015 12:08:08

11/05 12:49, , 1F
用dll工具確認真正的函式名給GetProcAddress使用,例如
11/05 12:49, 1F

11/05 12:50, , 2F
bcb的impdef或vs的dumpbin之類的
11/05 12:50, 2F

11/05 13:08, , 3F
DLL中有匯出函式嗎??
11/05 13:08, 3F

11/05 13:09, , 4F
如果沒匯出函式,在輸出表跟本找不到啊
11/05 13:09, 4F

11/05 13:15, , 5F
沒有dllexport 可是我同事用c#可以直接操作這個dll
11/05 13:15, 5F

11/05 13:21, , 6F
可以直接DLL基址+偏移操作呀,打開ollydbg,載入DLL
11/05 13:21, 6F

11/05 13:24, , 7F
把函式入口找出來,減掉DLL基址,就知道函式在哪了
11/05 13:24, 7F

11/05 13:27, , 8F
嗯 我試試看 謝謝
11/05 13:27, 8F

11/05 20:51, , 9F
mangled name 跟直接的 name 不一樣,要查一下
11/05 20:51, 9F
文章代碼(AID): #1MEjMRxC (C_and_CPP)
文章代碼(AID): #1MEjMRxC (C_and_CPP)