1

I am trying to do internationalization in a WTL GUI application .. in my drop down selection change handler (which is used for language selection I do something like this):

int selected = (int)::SendMessage(m_cbLang, CB_GETCURSEL,0,0);
HMODULE hmod;
int retCode = 0;
switch(selected)
{
case 0:
    retCode =::GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_PIN, NULL, &hmod);
    ATL::_AtlBaseModule.SetResourceInstance(hmod);
    break;
case 1:

    retCode =::GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_PIN, L"GuiLibOther.dll", &hmod);
    ATL::_AtlBaseModule.SetResourceInstance(hmod);
    break;
}
return S_OK;

Now, I really don't know how to use this function, although it is here , I don t know what the lpModuleName represents. The "GuiLibOther.dll" is a dll which contains the entire interface in another language.. all resources translated to another language.. I want the interface to change the language imediatelly after another language is selected. is this the right way? Case 0 return hmod = NULL

4

1 回答 1

1

GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS首先,除非您传递 DLL 中某些项目的地址,否则您不想使用该标志,在这种情况下您不是。

其次,文档暗示 DLL 必须在您调用之前已加载GetModuleHandleEx。如果您尚未将其链接到 .exe 以使其自动加载,则必须使用LoadLibrary.

需要使用LoadLibrary建议简化:

static HMODULE hmodExe = INVALID_HANDLE;
static HMODULE hmodDLL1 = INVALID_HANDLE;
switch(selected)
{
case 0:
    if (hmodExe == INVALID_HANDLE)
        retCode =::GetModuleHandleEx(0, NULL, &hmodExe);
    ATL::_AtlBaseModule.SetResourceInstance(hmodExe);
    break;
case 1:
    if (hmodDLL1 == INVALID_HANDLE)
        hmodDLL1 = LoadLibrary(L"GuiLibOther.dll");
    ATL::_AtlBaseModule.SetResourceInstance(hmodDLL1);
    break;

这应该使您可以动态切换资源库而无需额外开销。

于 2013-08-21T22:22:53.803 回答