Hello Joachim. Your code is invaluable!
I am actually using it inside my application
and it works excellent with an exception.
I will try to go straight to the point and
be concise. One particular DLL library crashes
my application when I’m trying to load it from memory.
I have made an archive with a text document describing
the problem and the DLL. I am hoping you can investigate the problem.

P.S.: I am sorry if posting twice bothers you, but this happes with a number of the DLLs I’m trying to
load and I’m hoping there’s a small trick I can’t get here and that solving it won’t take much of you’re time (I only know what I know from the MSDN documentation and from my C# experience, but I can see you’re a professional developer when it comes to windows os “insides”).

Hey. No problem, I understood as soon as I’ve seen them back.
I investigated the problem a bit more – about the _CRT_INIT function. Using OllyDebugger here’s what I found out: the _CRT_INIT function fails to return OK because at some point it calls the GetModuleFileNameW function. Calling this function it returns zero -> that’s the key! Using Olly Debugger I hooked immediately after this function, modified the EAX register (which holds its return value) from zero to one. And it worked like a charm! The problem is that now we’ve got 2 options:
we either hook the GetModuleFileNameW function so that, when it’s called with our module’s handle it returns a value different from zero, or we try to figure out how does LoadLibrary assign a file name to a specific handle – I’d choose option two, since it’s more “legal”. Here’s where I’m hoping you can help me or give me a hint: how does LoadLibrary “assign” a file name to the handle of the loaded module, making it “visible” to the GetModuleFileNameW function – the two functions work together, obviuosly. If we could find this out, I think the MemoryModule would be a one step closer to be complete!

The reason for the error is that the module that gets loaded by MemoryModule never gets inserted into the _LIST_ENTRY link list. This link list is used to store a PEB for each dll and .exe that gets loaded into memory. When you call GetModuleFileNameW, it ultimately has to refer to the double linked list to find the PEB that contains such information. No PEB, no file name to return.