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 ?

cprogrammer
  • 5,503
  • 3
  • 36
  • 56
  • 1
    just had similar problem - was trying to findresource with MAKEINTRESOURCE(ID) and this was not working, but when changed to FindResource(TEXT("ID"),..) it miraculously worked. similar to what @EFraim suggested – estoy Jan 13 '17 at 17:16

2 Answers2

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);
Erik
  • 88,732
  • 13
  • 198
  • 189
  • Doesn't work and anyway is not useful for me because I cannot get IDB_PNG1 string or int. I receive images\\list-back.png in callback for resource – cprogrammer Apr 27 '11 at 16:51
  • @cprogrammer: Use RCDATA and it works. The filename used to create a resource isn't stored in the resource table - the name/identifier is. – Erik Apr 27 '11 at 17:02
  • 1
    I still must use MAKEINTRESOURCE(FOO), doesn't work with "FOO". At least if the resource is in a dll and the call is in exe. I have looked with an PEExplorer and you are right, path isn't stored in the resource table - was a dead way, but I need to find a way to link a resource in .rc (rc will be generated) in a way that I can "Find" that resource from exe (without recompiling exe). – cprogrammer Apr 27 '11 at 17:34
1

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)

EFraim
  • 12,811
  • 4
  • 46
  • 62