1

I'm using visual studio 2013 and i'm making a dll file that extracts an executable file embed in it to a directory. First I imported the .exe file as a resource and changed the type to "Application". I can see in solution explorer that embed.exe is located under "Source Files". 2 new files have been created automaticly: Project.rc and resource.h. The .rc file includes this line:

IDR_APPLICATION1        Application             "embed.exe"

And the .h includes:

#define IDR_APPLICATION1                101

The problem is the following function fails

hrsrc = FindResource(NULL, (LPCWSTR)IDR_APPLICATION1, RT_RCDATA);

And GetLastError() returns 1813 which means, according to previous threads I visited, that the type (RT_RCDATA) is invalid. I've seen many threads but nothing helpful. I also tried to list resources but I ended up with a too complicated code where I couldn't find the problem.

Thanks in advance.

EDIT:

I tried each of these lines individually but none of them worked and each time GetLastError() returned 1813.

hrsrc = FindResource(NULL, (LPCWSTR)IDR_APPLICATION1, (LPCWSTR)L"Application");
hrsrc = FindResource(NULL, MAKEINTRESOURCE(IDR_APPLICATION1), _T("Application"));
hrsrc = FindResource(NULL, (LPCWSTR)IDR_APPLICATION1, _T("Application")); //mix of both

Here are 3 possible issues:

1 - The first parameter (argument) of FindResource() is the instance of the application, but I'm coding a DLL file, so I set it to NULL. The .exe file running the application has no resource of type "Application", but the .dll file does.

2 - The resource named "embed.exe" was automaticly added to the "Sources" filter/folder, maybe it should be in the "Resources" filter/folder?

3 - When I right click "embed.exe" from Solution Explorer, the properties have not been changed, and here they are:

Excluded from build: (empty)
Content: (empty)
Item type: Does not participate in build

Coding_King
  • 79
  • 2
  • 9
  • 1
    What is `IDR_APPL` and how does it in any way relate to `IDR_APPLICATION1` ? And stop casting, let MS do that for you via `MAKEINTRESOURCE`. Finally, `"Application"` is your resource type. That is going to come in to this picture eventually. – WhozCraig Feb 11 '15 at 20:06
  • Iow, `FindResource(NULL, MAKEINTRESOURCE(IDR_APPLICATION1), _T("Application"));` is probably what you're looking for. You declared a custom resource type in the resource script; that type has to be called out by-name in your search. What you have will work if the resource script had `IDR_APPLICATION1 RCDATA "embed.exe"`, assuming you fixed the id as-shown. – WhozCraig Feb 11 '15 at 20:13
  • @WhozCraig Thank you for checking out the edits made to the question – Coding_King Feb 12 '15 at 16:12
  • 1
    When you pass `NULL` as the first parameter you're searching the .exe, not the DLL. See http://stackoverflow.com/questions/2396328/get-hmodule-from-inside-a-dll – Mark Ransom Feb 12 '15 at 17:14
  • @MarkRansom It works now, you should have posted an answer – Coding_King Feb 12 '15 at 18:00

0 Answers0