title: D3D->CreateDevice() fails inside an injected DLL
body: <p>I'm writing a DLL that hooks certain D3D-functions by changing needed pointers in the VMT of the injected process. The algorythm is like:</p>
  
  <ol>
  <li>Obtain a dummy window handle.</li>
  <li>Init a dummmy D3D-object, create a D3D-device.</li>
  <li>Grab the needed offsets (VMT - D3D base address).</li>
  <li>Destroy the D3D object and the window handle.</li>
  <li>Get the D3D*.dll base of the injected process.</li>
  <li>Construct the actual VMT pointers (offsets + base).</li>
  <li>Search for them in the process heap.</li>
  <li>If found - change the pointers to my own.</li>
  </ol>
  
  <p>It works totally fine within the application, where I init D3D, start the drawing loop and then fire the hooking procedure, but it doesn't work from a DLL - for some reason it crashes while trying to create a dummy device with last error code = 126 ("The specified module could not be found", though D3D*.dll loads correctly).</p>
  
  <p>I know that at the same moment there can be only one D3DDevice inited, but in my test app I can create more of 1 - only 1 works, but I still can grab the VMT.</p>
  
  <p>So, the question is - what is the difference between running the same code from EXE and from DLL?</p>