MFC:如何获取DLL文件名?
我有一个由第 3 方应用程序加载的 MFC DLL。如何从 DLL 代码中获取 DLL 文件名?也就是说,例如,如果 DLL 的名称是 mycode.dll,那么我希望能够在代码中检索字符串“mycode.dll”。
我应该补充一点,如果磁盘上的 DLL 文件名发生更改,那么我想获取磁盘上的当前名称(我的意思不是在运行时更改,而是在主程序的调用之间更改)。
我的 DLL 是作为 CWinApp 类实现的,我的代码没有显式的 DllMain。
I have an MFC DLL that is loaded by a 3rd party application. How can I get the DLL filename from within the code of the DLL? That is, for example, if the DLL's name is mycode.dll, in code I want to be able to retrieve the string "mycode.dll".
I should add that if the DLL file name is changed on disk then I would like to get the current name on disk (I don't mean changed during run-time but changed between invocations of the main program).
My DLL is implemented as a CWinApp class, my code has no explicit DllMain.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以调用
AfxGetStaticModuleState
来获取指针到AFX_MODULE_STATE
结构,该结构有一个包含模块名称的成员m_lpszCurrentAppName
(应用程序或 DLL,具体取决于它所在的位置)调用自)。You can call
AfxGetStaticModuleState
to get a pointer to anAFX_MODULE_STATE
structure, which has a memberm_lpszCurrentAppName
containing the module name (app or DLL depending on where it's called from).请参阅获取 GetModuleFileName 功能。
当您为第一个参数传递 NULL 时,它将仅使用当前进程的句柄。
See the Get GetModuleFileName function.
When you pass in NULL for the first parameter, it will just use the handle for the current process.
GetModuleFileName 函数肯定返回加载 DLL 的 EXE...而不是 DLL 本身。我本来想将此作为评论发布在上面,但我还没有足够的积分,嗯。
GetModuleFileName function definitely returns the EXE THAT LOADED THE DLL... not the DLL itself. I would have posted this as a comment above but I don't have enough points yet, meh.