WTL方式强制从非mfc应用程序中的dll加载资源? (我们使用的是WTL/ATL,而不是直接的win32)
我发布了 这个问题以前和现在都已加载本地化字符串(我们使用 LoadString() 获得的字符串),但我还需要从卫星 DLL 加载所有其他资源。
MFC 有 AfxSetResourceHandle () 调用,但我需要非 MFC 应用程序的等效内容?我怀疑我必须在初始化代码中的某个地方进行设置,以便我的所有资源都从另一个 DLL 加载。如何在 WTL(Windows 模板库)上下文中执行此操作?
编辑:
我们不使用直接的 win32,而是使用 ATL 和 WTL for windows stuff。因此我们不能依赖 MFC 的东西,并且我们对菜单和对话框资源的加载没有低级控制。
编辑: 嗯... 这似乎有一个答案,但我希望有更好的东西比那个。例如 - SetResourceInstance() 方法类似于 CAppModule 对象中的 GetResourceInstance()。
I posted this question previously and now have the localized strings loaded (the ones we get with LoadString()) but I also need to load all the other resources from the satellite DLL.
MFC has the AfxSetResourceHandle () call, but I need something equivalent for a non-mfc app? I suspect I have to set that in the initialization code somewhere so all my resources are loaded from another DLL. How do I do that in a WTL (windows template library) context?
EDIT:
We are not using straight win32, but ATL and WTL for windows stuff. So we can't rely on the MFC stuff and we don't have low level control of the loading of menus and dialog resources.
EDIT:
Hmmm...
This seems to have an answer, but I was hoping for something better than that. For example - a SetResourceInstance() method analog to GetResourceInstance() in a CAppModule object.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
资源函数(FindResource、LoadResource)将模块句柄作为参数之一。
使用 GetModuleHandleEx 获取 DLL 的模块句柄。
编辑: ATL/WTL 的附加信息。
WTL 在其 Win32 调用中使用
ATL::_AtlBaseModule.GetResourceInstance()
作为模块句柄。您可以调用一个SetResourceInstance
函数来更改所使用的模块。像这样的事情应该在程序开始时起作用:The resource functions (FindResource, LoadResource) take a handle to a module as one of the parameters.
Use
GetModuleHandleEx
to get the module handle for the DLL.Edit: Additional info for ATL/WTL.
WTL uses
ATL::_AtlBaseModule.GetResourceInstance()
for the module handle in its Win32 calls. There's aSetResourceInstance
function that you can call to change the module that's used. Something like this should work at the beginning of your program:有时上述方法不可用,例如当由于某种原因您仍然必须支持Windows 2000时。在这种情况下,最好使用以下技巧。
我们声明一个静态变量,这意味着它的地址将位于它所链接的模块内部。然后,我们使用该变量的地址来查询该分配区域的基地址,这就是
HMODULE
。这绝不会使马克的回答无效!如果您需要程序在古老的系统上运行,请记住它作为后备选项。
Occasionally the above method is not usable, such as when you still have to support Windows 2000 for some reason. In such case it's good to have the following trick handy.
We declare a static variable, which means that its address will be inside the module into which it was linked. We then use the address to that variable to query for the base address of that allocated area, which is what the
HMODULE
is.This does by no means invalidate Mark's answer! Just keep it in mind as a fallback option if you need your programs to run on ancient systems.