title: What is the structure of HMODULE in x64?
body: <p>I'm trying to implement an <a href="https://stackoverflow.com/questions/8372524/ejecting-after-injecting-dll-from-running-process">injection of my 64-bit DLL</a> into a 64-bit process. My host process calls <code>CreateRemoteThread</code> with a thread subroutine pointing to <code>LoadLibrary</code>. The DLL later unloads itself "from within" by calling <code>FreeLibraryAndExitThread</code>.</p>
  
  <p>My goal is to know if the injected <code>LoadLibrary</code> call succeeded. For that unfortunately I can't use <code>GetExitCodeThread</code> from within my (host) process since returned 64-bit <code>HMODULE</code> handle is truncated to by a remote thread to <code>DWORD</code>. And I don't want to use <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms686832%28v=VS.85%29.aspx?f=255&amp;MSPPError=-2147217396" rel="nofollow noreferrer">Tool Help APIs</a> as they will introduce a race condition.</p>
  
  <p>So thus I was wondering about the lower 32-bits of the <code>HMODULE</code> returned by <code>LoadLibrary</code> in a 64-bit process -- can I reliably assume that its lower 32-bits will not be 0's for a valid handle?</p>
  
  <p>PS. I don't need the <code>HMODULE</code> handle itself, all I need to know if <code>LoadLibrary</code> succeeded or not.</p>
  
  <p><em>Edit. The call from my host process is done as such (in a very concise pseudo-code -- no error checking):</em></p>
  
  <pre><code>CreateRemoteThread(hProcess, 0, 0, 
    GetProcAddress(GetModuleHandle(L"kernel32.dll"), "LoadLibraryW"),
    pVmAddressOfMyDllsPathWrittenWith_WriteProcessMemory, 0, 0);
  </code></pre>