作者newlymoon (NEWLYMOON)
看板C_and_CPP
標題[問題] GetProcAddress與namespace
時間Thu Nov 5 12:05:45 2015
開發平台(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
→ serikafan: 用dll工具確認真正的函式名給GetProcAddress使用,例如 11/05 12:49
→ serikafan: bcb的impdef或vs的dumpbin之類的 11/05 12:50
推 stupid0319: DLL中有匯出函式嗎?? 11/05 13:08
→ stupid0319: 如果沒匯出函式,在輸出表跟本找不到啊 11/05 13:09
→ newlymoon: 沒有dllexport 可是我同事用c#可以直接操作這個dll 11/05 13:15
推 stupid0319: 可以直接DLL基址+偏移操作呀,打開ollydbg,載入DLL 11/05 13:21
→ stupid0319: 把函式入口找出來,減掉DLL基址,就知道函式在哪了 11/05 13:24
→ newlymoon: 嗯 我試試看 謝謝 11/05 13:27
→ yoco: mangled name 跟直接的 name 不一樣,要查一下 11/05 20:51