FindResource fails

99封情书 提交于 2019-12-11 07:44:40

问题


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 ?

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 ?


回答1:


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.

FOO  RCDATA  "images\\list-back.png"

...

::FindResource(module, L"FOO", RT_RCDATA);



回答2:


Additionally you can store the resource with a string ID, instead of a numeric ID, like this:

list-back PNG "images\\list-back.png"

Then you can indeed do:

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)



来源:https://stackoverflow.com/questions/5807554/findresource-fails

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!