LoadLibrary on DLLs in memory
My current project uses ZIP files for packaging game data and whatnot, and I am toying the the idea of extracting a DLL from one of my ZIPs directly into memory. LoadLibrary expects a filename. Is there any way to use LoadLibrary with the DLL in memory, or must it be a file on disk?
Any information would be appriciated,
Thanks
Joe
Nope, you have to extract it to a disk, either where you app is located currently, someplace you set with SetDLLDirectory, or the working directory (in that order).
Sorry, loading from memory would be nice, but not available.
Sorry, loading from memory would be nice, but not available.
I suspect that it can be done with a lot of work. The easiest approach is to write the file to disk and use LoadLibrary in the manner it was designed.
For more info on what goes on in side LoadLibrary, check out: What Goes On Inside Windows 2000: Solving the Mysteries of the Loader.
For more info on what goes on in side LoadLibrary, check out: What Goes On Inside Windows 2000: Solving the Mysteries of the Loader.
...It's doable, but you have to do it yourself, basically. So in response to "Is there any way to use LoadLibrary with the DLL in memory, or must it be a file on disk?", the answer is no, LoadLibrary and other API functions won't do it. But you can emulate LoadLibrary. And emulating it is just... wow. Looks like a lot of fun!
Quote:Original post by Morbo
Give this a check:
Loading a DLL from memory
Nice link. Seems like a roundabout way of doing things, but it is something to play with.
Thanks
Quote:Original post by DesdemonaUnfortunately, thats the only way to load a DLL from memory. I'm surprised Windows doesn't have a LoadLibraryFromMemory() function or something - I suppose it must be because Windows won't know when the memory becomed invalid or something...Quote:Original post by Morbo
Give this a check:
Loading a DLL from memory
Nice link. Seems like a roundabout way of doing things, but it is something to play with.
Thanks
Quote:Original post by Evil Steve
Unfortunately, thats the only way to load a DLL from memory. I'm surprised Windows doesn't have a LoadLibraryFromMemory() function or something - I suppose it must be because Windows won't know when the memory becomed invalid or something...
That's a good point to bring up. It suggests that a call to VirtualLock may be indicated. I didn't see any such call in Bauch's code.
Quote:Original post by LessBreadWell, if you're loading the library yourself, it shouldn't be too bad, since you'll know when to free it - so you're in charge of the memory. But if you were to use the fictional LoadLibraryFromMemory(), Windows would need to be in charge of it. Or it could just duplicate the data you send it I suppose.Quote:Original post by Evil Steve
Unfortunately, thats the only way to load a DLL from memory. I'm surprised Windows doesn't have a LoadLibraryFromMemory() function or something - I suppose it must be because Windows won't know when the memory becomed invalid or something...
That's a good point to bring up. It suggests that a call to VirtualLock may be indicated. I didn't see any such call in Bauch's code.
Thinking about it a little more, I don't think that paged out user code would be a problem. If the code was paged out, a page fault would ultimately lead to the restoration of the memory, so VirtualLock wouldn't be needed.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement