Click here to Skip to main content
15,914,225 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am writing a shell extension for Windows Explorer. The resource loads perfectly if I drop the code into an exe and run it. But NOT in the DLL.
I have verified the resource is there (in both the copiled exe AND compiled dll).
The code segment (in GoAsm syntax) is; {error checking removed}
// Now find Header resource Block
invoke FindResource,[hInstance], BlankStream,8"STDATA"
cmp eax,NULL
je >>.failure

mov [hResource],eax

// Pull Resource into memory
invoke LoadResource,NULL,[hResource]
cmp eax,NULL
je >>.failure

mov [hHeader],eax

// Get a pointer to Resource
invoke LockResource,[hHeader]
cmp eax,NULL
je >>.failure

mov [pHeader], eax


Find Resource fails with "..resource type cannot be found in the image file."
The hInstance is the one passed in the DLLmain loda sequence. I have also tried using a pseuudo handle gotten from GetModuleHandleEx, and even tried loading the dll itself by doing a LoadLibrary call.

The resource file has
C++
#define BlankStream 300
BlankStream STDATA Res\BlankStream.dat


And like I said, it IS THERE in the compiled dll and is correct, as far as I can tell.
Resource Hacker shows
STDATA
  300
    1033  [correct hex data]


Any ideas? Is it because the code is part of a COM routine? I am stumped <again>.
Posted
Updated 16-Jul-12 17:51pm
v2
Comments
Mohibur Rashid 17-Jul-12 0:36am    
how do you load resource in a DLL? it does not have any Instance?
ZapSpam 8034167 17-Jul-12 1:44am    
Although the variable name is hInstance, the value is taken from the handle to the Dll instance passed into the DLLmain routine when it is loaded. As I have been using the code in an exe project as well as the intended dll project, the name has not changed. "What is in a name? Would not a rose by any other name smell as sweet?"
nv3 17-Jul-12 3:25am    
Calling the right version of FindResource (A/W) and with the right type of argument for the resource type?

Also: If all works fine when you place the resource in your exe file, it actually can only be the hInstance that is making trouble. Could you check whether hInstance is the same as when determining the module handle by an address of your DLL with GetModuleHandle? The hInstance is identical to the load address of your DLL into your virtual address space.
ZapSpam 8034167 18-Jul-12 2:00am    
I did a check by using a msgbox to display the value of hInstance and also the value returned by GetModuleHandle. They were the same.

Have you tried using FindResourceEx and explicitly setting the lang? - ISTR having a similar problem with Chrome and my NPAPI plugin
 
Share this answer
 
Comments
ZapSpam 8034167 17-Jul-12 1:46am    
That didn't yield any different result. I tried the default system ID, as well as Language neutral, and American english. Thanks for the suggestion though.
barneyman 17-Jul-12 1:54am    
ok - grandmother/eggs ...

- Is handle you get from DLLmain the same the procExp reports
- if you copy your DLL to another name, explicitly LoadAsResource do (a) the handles match, and (b) does ProcMon catch the open/read
- What do you get if you enum all the resources in the dll

:)

Here is some further info, Since the handle is the same, and since I do have a mix of ANSI and unicode (although forcing either mode with either text BlankStream, and STDATA got same results as before) I figured to just bypass text. I added a line to the resource file
#define BlankStream 300
#define STDATA 666
and changed the line in code to
invoke FindResource,[hInstance], 300, 666


I also fixed the LoadResource to use the [hInstance]
Result is that it no longer fails at the FindResource, and code flows as it should. Hmmmm, maybe I should have tried L instead of 8 (UTF-16 not UTF-8) at this point I just want to go to bed.
Thanks for your help everyone!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900