在Message Box Husing手柄中显示DLL的路径

Show path to a dll in a MessageBox husing handle

本文关键字:显示 DLL 路径 Message Box Husing      更新时间:2023-10-16

i用此命令加载dll

HINSTANCE DllEconovent = LoadLibrary(_T("Econovent.dll"));

我想从磁盘上加载DLL的位置...在此假案例中

C:TFS_FWGAconOembinEconovent.20140130_3200Econovent64Econovent.dll

,只需显示消息框

MessageBox(_T("No valid ProcAddress"), _T("Error"), MB_ICONINFORMATION);

这是如何以最佳方式完成的?

有一个查看GetModuleFileName:此功能"检索包含指定模块的文件的完全合格的路径。"

DWORD WINAPI GetModuleFileName(
  _In_opt_  HMODULE hModule,
  _Out_     LPTSTR lpFilename,
  _In_      DWORD nSize
);

它应该接收您的HINSTANCE对象并给您一个文件名。


一个简单的示例

int main()
{
    HINSTANCE test = LoadLibrary("test.dll");
    char buffer[MAX_PATH];
    GetModuleFileName(test, buffer, MAX_PATH);
    std::cout << buffer << std::endl;
    return 0;
}

将其调整到MessageBox,只需使用std::cout删除线并放置

MessageBox(buffer, _T("Error"), MB_ICONINFORMATION);