FindResource (Win32) help .cpp

Started by
8 comments, last by Fredericvo 9 years, 10 months ago

I am trying to load a resource which is a .dll to the main application (project type is .cpp)

inside resource.h i have

define IDC_DLL 110

inside the application.rc i have IDC_DLL RT_RCDATA "Plugin.dll"

Plugin.dll is inside the source code directory

hrsrc = FindResource(NULL,MAKEINTRESOURCE(110),RT_RCDATA);

hrsrc is always NULL

:)
Advertisement
Have you checked with a resource editing tool to make sure your raw data is actually embedded in your .EXE file? My guess is the resource is actually missing. (Resource editors are a dime a dozen and many freebies can be found all over the internet with a quick search.)

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

The first parameter to FindResource is the instance where the resource is expected to be. A .exe and the Dlls it loads have different resource pools.

A Dll has a different instance handle. Passing NULL uses the instance that started the process( the .exe).

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

The first parameter to FindResource is the instance where the resource is expected to be. A .exe and the Dlls it loads have different resource pools.

A Dll has a different instance handle. Passing NULL uses the instance that started the process( the .exe).


While this is true, I suspect what the OP is trying to do is embed a DLL in the EXE as a resource, and extract and load it.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Have you called GetLastError() to get the error information?


I am trying to load a resource which is a .dll to the main application

Do you mean you have already imbedded the dll in your RC file, or are you trying to open the DLL for binary access?

FYI, RT_RCDATA is a binary resource which you must imbed in the RC file yourself. It will not load any data itself.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

If you are trying to embed the DLL in the executable you can use a tool like ResHacker to inspect your .exe.

It will show all included resources, their IDs and types.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

If you are trying to embed the DLL in the executable you can use a tool like ResHacker to inspect your .exe.

It will show all included resources, their IDs and types.

Why would i inspect my exe when i cant figure out how to add one :)

:)

Ah, the point is, it was not very clear where you had the problems.

To embed any file as binary blob, go to the resource view.

Right click your file, "Add resource"

For the first file, choose "custom".

Choose a descriptive name in the next dialog (e.g. "TEMPLATE")

Choose a file to import.

For additional files, choose the name you entered the first time.

Click "import".

Choose a file to import.

To access the file's data:

Call FindResource

Use the returned handle from FindResource to call LoadResource

Use the returned handle from LoadResource to call LockResource

LockResource returns a pointer to the binary data.

SizeOfResource returns the size of the resource in bytes.

Note that this is used for accessing any binary data in your resources.

From the used names you want to do that with a DLL. There are no in built functions to load a DLL from a resource.

Here's a site describing how to do that, note that this is not commonly used though: http://www.joachim-bauch.de/tutorials/loading-a-dll-from-memory/

If you simply want to access code from a DLL, call LoadLibrary and GetProcAddress.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

I believe I've had this problem some time ago and the reason was that RT_RCDATA wasn't defined (as 10 IIRC)

This topic is closed to new replies.

Advertisement