title: CreateRemoteThread() succeeds yet doesn't do anything
body: <p>I'm trying to inject dll (found in <code>dll_path[]</code> and it's <strong>correct</strong> path) into target process using <code>CreateRemoteThread()</code>. Unfortunately completely nothing happens (expected result is <code>MessageBox()</code> call from <code>DLL_PROCESS_ATTACH</code> resulting in window pop up). 
  It works <strong>properly</strong> when used with remote injector.</p>
  
  <p>You can treat every <code>what()</code> call as <code>GetLastError()</code> and <code>assert(0)</code>. It is guaranteed that variable <code>PID</code> will contain correct process id (I tested it many times). Also <strong>none</strong> of the function calls you see in code below fails. Funny thing is that it worked well until I rewrote it from C to more C++-like code which you can see below. I compiled code below and dll code without any warnings. I wonder where do I made mistake. Here's my code:</p>
  
  <pre><code>int main() {
  
      const WCHAR dll_path[] = L"C:\\myDLL.dll";
  
      const std::wstring process_name = L"target.exe";
  
      const DWORD PID = get_PID(process_name);
  
      if (!PID)
          what();
  
      HANDLE process = OpenProcess(PROCESS_ALL_ACCESS, false, PID);
      if (!process)
          what();
  
      FARPROC lib = GetProcAddress(GetModuleHandle(L"kernel32.dll"), "LoadLibraryA");
      if (!lib)
          what();
  
      LPVOID base = (LPVOID)VirtualAllocEx(process, 0, wcslen(dll_path), MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
      if (!base)
          what();
  
      BOOL good = WriteProcessMemory(process, base, dll_path, wcslen(dll_path), 0);
      if (!good)
          what();
  
      HANDLE thread = CreateRemoteThread(process, 0, 0, reinterpret_cast&lt;LPTHREAD_START_ROUTINE&gt;(lib), base, 0, 0);
      if (!thread)
          what();    
  
      if (thread) {
          std::cout &lt;&lt; "Remote thread successfully created." &lt;&lt; std::endl;
          std::cout &lt;&lt; "process ID = " &lt;&lt; PID &lt;&lt; std::endl;
      }
  
  #if 1
      CloseHandle(thread);
      CloseHandle(process);
  #endif
  
      return 0;
  }
  </code></pre>