Sign in to follow this  
Anddos

FindResource (Win32) help .cpp

Recommended Posts

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

Edited by Anddos

Share this post


Link to post
Share on other sites
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.)

Share this post


Link to post
Share on other sites

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).

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites


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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 :)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this