A while ago WHY asked for help/examples for placing resource information into a DLL. The discussion fizzled on the methods to place it in the executable exe. I know this, because Hiro's search feature which worked quite well for this topic. But unfortunately the topic itself was left unanswered :( . Myself, I would like to find out how to complile a resources into an .dll and if there is any funny tricks to load them out of the dll. I want to experiment with a Pro-start type idea with writing resourced code to disk. Hutch earlier told me that MASM isnt well suited to this for large resource information as it would become teedious to manage, but my thoughts was if i can understand the problem, then maybe i could write ANOTHER program to take the teedousness out of the problem... (wood workers call this a 'jig' :D ) At anyrate, if i can or can not do this specific case is less to the point of learning how in the first place. I also tried the MSDN, but the search keeps pullin up abstract topics.. (its as if it assumes i should know how to do this..) If someone knows of a site to see, or can anwswer this outright i thanx you in advance. Im always acepting e-mail as well! (Hint Hint, I get so much xxx from hotmail a little code would be a change of venue :P ) NaN
Posted on 2001-02-22 00:02:00 by NaN
I might be missing the point, but whenever you need a resource you have to specify the hInstance. When you load a DLL using LoadLibrary it returns the hInstance of the DLL, just use that instead of your hInstance from WinMain. Like This:-

 invoke LoadLibrary,szDllName
 mov hDll,eax
 invoke LoadString,hDll,ID_MY_STRING,addr szBuffer,10
That should do it. umbongo
Posted on 2001-02-22 05:20:00 by umbongo
First off, I've never created a resource-only dll, but have frequently used resources in dll's. When loading a dll, it first executed DllMain in the dll, At this point, your dll can grab it's instance handle, it is passed in there:

DllMain PROC PUBLIC hModule:HANDLE, dwReason:DWORD, pReserved:DWORD
Save hModule is a dll global variable (one of the few instances where globals are not only correct, but essential). Do this save when dwReason == DLL_PROCESS_ATTACH Now, for a resource only dll, I had to peek inside MSDN having not done this, but it seems straightforward. Link with the following option: /NOENTRY This option is required for creating a resource-only DLL. Used to prevent LINK from linking a reference to _main into the DLL. Now, to get resources out of the dll, you need an instance handle to this dll inside your .exe. Try LoadLibraryEx with dwFlags set to LOAD_LIBRARY_AS_DATAFILE. MSDN claims: "Use this flag when you want to load a DLL only to extract messages or resources from it." Looks like what you want, huh? :-)
Posted on 2001-02-22 09:58:00 by Ernie
Thanx again Umbongo and Ernie, this is exactly the start i was looking for. Ernie, im stightly enbarassed you are able to find this on the msdn so easily, i am using this link MSDN SEARCH to "try" and find new topics such as this (Is there a better way?) Also, to continue on this question, the discussion so far assumes I have the dll properly compiled. Would this a suitable command line such that the resource is compiled into a dll?

For DLL's With resources and procs:

Link /SUBSYSTEM:WINDOWS /DLL /DEF:withProcs.def withProcs.obj withProcs.res

For DLL's With only resources:


Thanx again. NaN This message was edited by NaN, on 2/22/2001 12:02:21 PM
Posted on 2001-02-22 11:00:00 by NaN
You're going to need an entry point for the DLL. It doesn't have to do anything. like this :-

LibMain proc hInstDLL:DWORD, reason:DWORD, unused:DWORD
    return TRUE
LibMain Endp

Thats should do it, then link like normal but use /DLL umbongo
Posted on 2001-02-22 11:23:00 by umbongo
First, resource-only dll's are just that: resources only. No code. No DllMain required. It's never run. Second, I browse MSDN so fast because it's on my hard disk, I have the MSDN CD installed there. I've put a few bookmarks in there too, for those things I always forget. It's index browser is damn fast, should I give it an API method name I'm right to it, click and get my choice of a few enviroments it's used in (I always pick the most basic one, that's what we want.) Also, these pages most always have links at the bottom for related API methods, and the group of methods it's from. These are great to check in case you only know a method that 'sort of' does what you need. (This is what lead me to LoadLibraryEx from LoadLibrary). Finally, on building dll's, with the previous caveot that I've never used a resource only dll, here's my blddll.bat code. I keep it in my /masm32/bin/ folder, and have a menu for it in place in Quick Editor. (We really should bug hutch to add this importaint build product to his standard MASM32 release)

@echo off
echo Build ALL for Dynamic Link Library
if not exist rsrc.rc goto over1
\masm32\bin\rc /v rsrc.rc
\masm32\bin\cvtres /machine:ix86 rsrc.res

if exist %1.dll del %1.dll
if exist %1.obj del %1.obj

\masm32\bin\ml /c /Fl /Sn /coff %1.asm /Sa
if errorlevel 1 goto errasm

if not exist rsrc.obj goto nores

echo Resources were found

\masm32\bin\Link /DLL /SUBSYSTEM:WINDOWS /DEF:%1.def /LIBPATH:c:\masm32\lib %1.obj rsrc.obj 
if errorlevel 1 goto errlink
goto TheEnd

echo No resources found
\masm32\bin\Link /DLL /SUBSYSTEM:WINDOWS /DEF:%1.def /LIBPATH:c:\masm32\lib %1.obj 
if errorlevel 1 goto errlink
goto TheEnd

echo _
echo >> Link error
goto alldone

echo _
echo >> Assembly Error
goto alldone

dir %1

Posted on 2001-02-22 13:31:00 by Ernie
hmm... perhaps I should start reading the messages before posting replies :) umbongo
Posted on 2001-02-22 15:06:00 by umbongo
Doh !!!
Posted on 2001-02-22 15:19:00 by Ernie
Thanx again Ernie, (I should put that phase in a Macro... ) :P You've inspired me to actually dig up my vb5 cd's (that was holding up my couch) and give a fresh attempt at understanding the MSDN... After 20min of dinkin around i found what you just stated.. (I hope i will get faster at this.. ). Im finding it hard to like this approach to learning. Thanx again for the help/advice NaN This message was edited by NaN, on 2/22/2001 8:10:18 PM
Posted on 2001-02-22 19:20:00 by NaN
I dunno how many people are interested (if any), but i figured out the source for basic resoured text. I will post the code for anyone else who is looking for some example like this in the future: THE RESOURCE FILE (data.dll)

        "Lets see what happens....",0x0a0d, /* 0x0a0d == ",13,10,"
        "Hope Jaymeson Can get it right!!"
The compile line for the resource:

> Resource.bat data.rc
Needed code fragment in WinProc (or where ever)

     szText libname,"data.dll"
     invoke LoadLibraryEx, addr libname, NULL, LOAD_LIBRARY_AS_DATAFILE
     mov hDll, eax  ; store the module handle

     szText rsrcName, "TESTDATA"
     invoke FindResource, eax, addr rsrcName, RT_RCDATA
     mov hData, eax  ; store the resource handle
     invoke LoadResource, hDll, eax
     mov lpData, eax ; store the Global Memory pointer

     ; Test it's effective use...
     invoke MessageBox,hWin,lpData,ADDR szDisplayName,MB_OK
     invoke SetWindowText, hEdit, lpData

     ; NOTE to other newbie's, lpData will destroy after this call
     invoke FreeLibrary, hDll                              
Well There it is... i hope it helps someone :) Personally im quite happy with how it turned out, thanx again Ernie and Umbongo for your assistance. NaN
Posted on 2001-02-22 22:03:00 by NaN
{sneaks in, coppies out all the good code and paste it inside his vault... then sneaks away}
Posted on 2001-02-23 01:27:00 by Ernie
LOL :) Glad you like, I also found a good purpose for this, and helped put it to use with your sugestion to check out Jeremy Collake's compression tools. I have a solution to CyBerian's question also posted so neatly... ... Its been a good day of codin' :D NaN
Posted on 2001-02-23 01:34:00 by NaN