fancycode/MemoryModule — Issue #2: LoadLibrary()
Author: Psychotron
Created: 2012-01-30 00:57:28+00:00
State: open

MemoryLibrary.c:250

You make the incorrect assumption that LoadLibrary() returns INVALID_HANDLE_VALUE on failure. It actually returns NULL. INVALID_HANDLE_VALUE is 0xffffffff.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms684175%28v=vs.85%29.aspx

"If the specified module is a DLL that is not already loaded for the calling process, the system calls the DLL's DllMain function with the DLL_PROCESS_ATTACH value. If DllMain returns TRUE, LoadLibrary returns a handle to the module. If DllMain returns FALSE, the system unloads the DLL from the process address space and LoadLibrary returns NULL. It is not safe to call LoadLibrary from DllMain. For more information, see the Remarks section in DllMain."