知道完整字符串的资源的ID

编程入门 行业动态 更新时间:2024-10-28 10:35:53
本文介绍了知道完整字符串的资源的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_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

本文发布于:2023-11-22 08:43:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616737.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   完整   资源   ID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!