windows FindResource 失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5807554/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
FindResource fails
提问by cprogrammer
I have a piece of code like this
我有一段这样的代码
IDB_PNG1 PNG "images\list-back.png"
HRSRC hrsrc = FindResource(module, MAKEINTRESOURCE(IDB_PNG1), TEXT("PNG"));
this works fine,
But I can not make it work any of the variants below
这很好用,
但我不能让它在下面的任何变体中工作
hrsrc = ::FindResource(module, L"images\list-back.png", L"PNG");
hrsrc = ::FindResource(module, L"images\list-back", L"PNG");
hrsrc = ::FindResource(module, L"list-back.png", L"PNG");
hrsrc = ::FindResource(module, L"list-back", L"PNG");
GetlastError returns 0x00000716 The specified resource name cannot be found in the image file.
What is the right string format/ way for searching with a string ?
GetlastError 返回 0x00000716 在图像文件中找不到指定的资源名称。
使用字符串搜索的正确字符串格式/方式是什么?
Edit: .rc will be generated and will contain .html and .png files. I want to be able to locate and Load that files without recompiling the exe. I need to be able to identify somehow in .html what .png is using, in exe I will receive that path/id than FindResource and loading. Can this be done ?
编辑:将生成 .rc 并将包含 .html 和 .png 文件。我希望能够在不重新编译 exe 的情况下定位和加载该文件。我需要能够在 .html 中以某种方式识别 .png 正在使用什么,在 exe 中我将收到该路径/id,而不是 FindResource 和加载。这能做到吗?
回答by Erik
The first entry in a RCDATA line is the name (or ID). The last entry simply is "what should the resource compiler use to create this entry" - the name isn't stored in the executable.
RCDATA 行中的第一个条目是名称(或 ID)。最后一个条目只是“资源编译器应该使用什么来创建这个条目”——名称没有存储在可执行文件中。
FOO RCDATA "images\list-back.png"
...
::FindResource(module, L"FOO", RT_RCDATA);
回答by EFraim
Additionally you can store the resource with a string ID, instead of a numeric ID, like this:
此外,您可以使用字符串 ID 而不是数字 ID 来存储资源,如下所示:
list-back PNG "images\\list-back.png"
list-back PNG "images\\list-back.png"
Then you can indeed do:
那么你确实可以这样做:
hrsrc = ::FindResource(module, L"list-back", L"PNG");
hrsrc = ::FindResource(module, L"list-back", L"PNG");
This is less efficient than the solution supplied by Erik, but can be more manageable if you are trying to access some resource from say, static library, whereas the resource itself gets embedded into the DLL/EXE at a later stage. (You don't have to know the numeric ID then, just agree on the symbolic name across your modules)
这比 Erik 提供的解决方案效率低,但如果您尝试从静态库访问某些资源,而资源本身在稍后阶段嵌入到 DLL/EXE 中,则可以更易于管理。(然后您不必知道数字 ID,只需在模块中就符号名称达成一致即可)