LoadLibrary on DLLs in memory

Started by
8 comments, last by LessBread 19 years, 1 month ago
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
Advertisement
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.
----Erzengel des Lichtes光の大天使Archangel of LightEverything has a use. You must know that use, and when to properly use the effects.♀≈♂?
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.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Give this a check:

Loading a DLL from memory
...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!
----Erzengel des Lichtes光の大天使Archangel of LightEverything has a use. You must know that use, and when to properly use the effects.♀≈♂?
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 Desdemona
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
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...
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.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Quote:Original post by LessBread
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.
Well, 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.
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.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man

This topic is closed to new replies.

Advertisement