title: Dll not being loaded in Firefox but loads in custom application
body: <p>I posted a recent question on SO about <a href="https://stackoverflow.com/questions/26117920/c-code-injection-crashes-injected-application">code injection</a>, this one is similar but not the same. I am injecting dll into Firefox, it injects successfully but the code in the DLL doesn't run. If i inject the same code into a custom application, it works. Why might that be. This is the code that I'm using.</p>
  
  <p><strong>Injector.exe</strong>     // the file that's injecting the code</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;windows.h&gt;
  
  #define procId 2844
  #define dllname "dllinject.dll"    // located in same directory
  
  int main()
  {
      HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, false, procId);
      LPVOID allocated = (LPVOID)VirtualAllocEx(hProc, NULL, strlen(dllname), MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
      WriteProcessMemory(hProc, (LPVOID)allocated, dllname, strlen(dllname), NULL);
      LPVOID libaddr = (LPVOID)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
      CreateRemoteThread(hProc, NULL, NULL, (LPTHREAD_START_ROUTINE)libaddr, NULL, NULL);
      CloseHandle(hProc);
      return 0;
  }
  </code></pre>
  
  <p><strong>Simpleinjected.exe</strong>    // the file being injected</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main()
  {
      printf("Hello");
      return 0;
  }
  </code></pre>
  
  <p><strong>dllinject.dll</strong></p>
  
  <pre><code>#include &lt;windows.h&gt;
  
  int message(const char *msg)
  {
      MessageBox(NULL, msg, "Message from Dll", MB_OK);
      return 0;
  }
  
  BOOL WINAPI DLLMain(HINSTANCE hInstDll, DWORD ulReason, LPVOID lpReserved)
  {
      switch(ulReason)
      {
          case DLL_PROCESS_ATTACH:
              message("process attach");
              break;
          case DLL_THREAD_ATTACH:
              message("thread attach");
              break;
          case DLL_PROCESS_DETACH:
              message("process detach");
              break;
          case DLL_THREAD_DETACH:
              message("thread detach");
              break;
      }
      return true;
  }
  </code></pre>
  
  <p>It works when injected into <code>simpleinjected.exe</code> but when injected in Firefox, nothing happens even though the dll is injected successfully.</p>