Sign in to follow this  
Desdemona

LoadLibrary on DLLs in memory

Recommended Posts

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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

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