FindResource fails

1

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 ?

c++
windows
sfx
asked on Stack Overflow Apr 27, 2011 by cprogrammer • edited Apr 27, 2011 by cprogrammer

2 Answers

6

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);
answered on Stack Overflow Apr 27, 2011 by Erik • edited Apr 27, 2011 by Erik
0

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)

answered on Stack Overflow Aug 30, 2015 by EFraim

User contributions licensed under CC BY-SA 3.0