title: CreateRemoteThread + LoadLibraryA doesn't do anything despite succeeding
body: <p>Despite the fact that memory allocation/write, finding <code>LoadLibraryA</code> address and creating a remote thread return valid (not NULL) results, absolutely nothing happens after that (mainly, the DllMain of the loaded DLL doesn't seem to get called).</p>
  <pre class="lang-cpp prettyprint-override"><code>#define PROC_NAME L&quot;TestConsole.exe&quot;
  #define DLL_NAME &quot;TestLib.dll\0&quot;
  
  HANDLE GetProcessByName(const wchar_t* name);
  
  int main()
  {
      const char dllName[] = DLL_NAME;
      int dllNameSize = strlen(dllName) + 1;
  
      HANDLE process = GetProcessByName(PROC_NAME);
  
      LPVOID allocMem = VirtualAllocEx(process, NULL, dllNameSize, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
  
      WriteProcessMemory(process, allocMem, dllName, dllNameSize, NULL);
  
      // Just to make sure
      char buff[20];
      ReadProcessMemory(process, allocMem, buff, dllNameSize, NULL);
      printf(&quot;Data: %s\n&quot;, buff);
  
      LPVOID libraryAddress =
          (LPVOID)GetProcAddress(GetModuleHandle(L&quot;kernel32.dll&quot;), &quot;LoadLibraryA&quot;);
  
      HANDLE remoteThread = CreateRemoteThread(process, NULL, NULL, (LPTHREAD_START_ROUTINE)libraryAddress, allocMem, NULL, NULL);
  }
  
  HANDLE GetProcessByName(const wchar_t* name)
  {
      PROCESSENTRY32 entry;
      entry.dwSize = sizeof(PROCESSENTRY32);
  
      HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
  
      if (Process32First(snapshot, &amp;entry) == TRUE)
      {
          while (Process32Next(snapshot, &amp;entry) == TRUE)
          {
              if (wcscmp(entry.szExeFile, name) == 0)
              {
                  return OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ParentProcessID);
              }
          }
      }
  
      return NULL;
  }
  </code></pre>
  <p>Things I know/checked:</p>
  <ul>
  <li>The thread gets created and a valid (not null) handle is returned. Despite it nothing happens.</li>
  <li>I'm pretty sure that it's <strong>not</strong> DLL's fault. It's extremely simple, simply prints to console when it gets loaded and it works correctly when used simply with <code>CreateThread()</code>.</li>
  <li>Injector, DLL and the app to which I'm injecting are all 64 bit. If I chose any other platform (for all 3) everything works the same except for <code>CreateRemoteThread()</code>, which now fails.</li>
  </ul>