我知道这有点棘手,但我需要用于应用程序. 通常,我们使用LoadString函数从语言资源中加载字符串,并指定DLL的HINSTANCE. 我尝试过的事情: 我正在寻找一种方法,该方法通过知道字符串和在何处查找以检索ID的HINSTANCE来反转此方法.
I know it''s a little bit tricky but I need it for an application. Generally we use LoadString function to load a string from a resource in language, specifying the HINSTANCE of the dll. What I have tried: I''m looking for a way to reverse this method by knowing the string and the HINSTANCE where to look in to retrieve the ID.
推荐答案通过代码可以迭代可能的ID. 基于现有代码的未测试示例,用于扫描DLL中的字符串资源: If you need to do this by code just iterate over the possible IDs. Untested example based on existing code to scan string resources in DLLs: int GetID(HMODULE hModule, LPCTSTR str) { // Declare CString object outside the loop to avoid // memory allocation with each call to LoadString(). CString strItem; for (unsigned long i = 0; i <= 0xFFFF; i++) { if (strItem.LoadString(hModule, i)) { if (strItem == str) return i; } } return -1; }
如果尚未加载DLL,请使用带有参数DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE的LoadLibraryEx将其作为数据文件加载.
If the DLL is not already loaded, load it as data file using LoadLibraryEx with parameters DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE.
这是一个简单的技巧:在Visual Studio中将dll作为资源文件打开. (打开文件" +选择资源"作为文件类型) 比您看到的字符串列表表还可以搜索它. It is an easy trick: open the dll in Visual Studio as resource file. ("Open File" + select "resource" as file type) Than you see the string list table and can search for it.
更多推荐
知道完整字符串的资源的ID
发布评论