知道完整字符串的资源的ID [英] Retrieving id of the resource knowing the full string

查看:201
本文介绍了知道完整字符串的资源的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这有点棘手,但我需要用于应用程序.
通常,我们使用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_DATAFILELoadLibraryEx将其作为数据文件加载.


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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆