title: C# code to inject 64bit dll to process
body: <p>I have a code to inject 32bit library(C++) to foreign 32bit process:</p>
  
  <pre><code>[DllImport("kernel32")]
          public static extern IntPtr CreateRemoteThread(
            IntPtr hProcess,
            IntPtr lpThreadAttributes,
            uint dwStackSize,
            UIntPtr lpStartAddress, // raw Pointer into remote process  
            IntPtr lpParameter,
            uint dwCreationFlags,
            out IntPtr lpThreadId
          );
  
          ...
  
          public static bool InjectDLL(Process p, string dll)
          {
              IntPtr bytesout;
              Int32 LenWrite = dll.Length + 1;
              IntPtr AllocMem = (IntPtr)VirtualAllocEx(p.Handle, (IntPtr)null, (uint)LenWrite, 0x1000, 0x40);
              WriteProcessMemory(p.Handle, AllocMem, dll, (UIntPtr)LenWrite, out bytesout);
              UIntPtr Injector = (UIntPtr)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
              IntPtr hThread = (IntPtr)CreateRemoteThread(p.Handle, (IntPtr)null, 0, Injector, AllocMem, 0, out bytesout);
              return true;
          }
  </code></pre>
  
  <p>But how to fix that code to inject 64 bit libraries to 64bit processes? Code above doesn't work to 64bit processes and dlls.</p>
  
  <p>Thanks!</p>