LoadString(nID) Problem and Solution

来源:互联网 发布:日程管理app 知乎 编辑:程序博客网 时间:2024/04/28 10:14


CString::LoadString(UINT nID)
Conclusion: the correct way to load string resource by ID is to call CString::LoadString(HINSTANCE hInstance,UINT nID), specifying the dll handler you want to search for.

Problem
CString::LoadString(UINT nID) will first use the instance handle of the main application to search for a string with the given ID. Failing that, it will look in DLLs in the order they were loaded until there is a match. If DLL A is loaded, then B and C, calling LoadString from DLL C will first find a matching resource in DLL A before finding its own resource. 

Solution
Use CString::LoadString(HINSTANCE hInstance,UINT nID) or ::LoadString() function.
Another seem-to-work way (not suggested):
CString strTemp;
AFX_MANAGE_STATE(AfxGetStaticModuleState()); 
strTemp.LoadString(uID);
原创粉丝点击