title: Can't create d3d device
body: <p>I am trying to initialize directX, but for some reason it can't create d3d device.
  It compiles properly, but shows last messagebox ("Can't create D3D device")</p>
  
  <p>While debugging:<br>
  -       d3dObject   0x00000000  IDirect3D9 *<br>
  -       IUnknown    {...}   IUnknown<br>
          __vfptr CXX0030: Error: expression cannot be evaluated  </p>
  
  <pre><code>#include &lt;d3d9.h&gt;
  #include &lt;d3dx9.h&gt;
  #include &lt;windows.h&gt;
  
  HWND hMainWindow;
  
  IDirect3D9 *d3dObject = 0;
  IDirect3DDevice9 *d3dDevice = 0;
  
  bool InitDirectX()
  {
      d3dObject = Direct3DCreate9(D3D_SDK_VERSION);
      if( !d3dObject )
      {
          MessageBox(0, "Can't create Direct3D Object", "Error", MB_ICONSTOP);
          PostQuitMessage(0);
      }
  
      D3DDISPLAYMODE mode;
      d3dObject-&gt;GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &amp;mode);
      d3dObject-&gt;CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, mode.Format, mode.Format, true);
      d3dObject-&gt;CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DFMT_X8R8G8B8, false);
  
      D3DCAPS9 caps;
      d3dObject-&gt;GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &amp;caps);
  
      DWORD devBehaviorFlags = 0;
      if( caps.DevCaps &amp; D3DDEVCAPS_HWTRANSFORMANDLIGHT )
            devBehaviorFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
      else
            devBehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
  
      // If pure device and HW T&amp;L supported
      if( caps.DevCaps &amp; D3DDEVCAPS_PUREDEVICE &amp;&amp;
            devBehaviorFlags &amp; D3DCREATE_HARDWARE_VERTEXPROCESSING)
                  devBehaviorFlags |= D3DCREATE_PUREDEVICE;
  
      D3DPRESENT_PARAMETERS d3dpp;
      d3dpp.BackBufferWidth            = 800;
      d3dpp.BackBufferHeight           = 600;
      d3dpp.BackBufferFormat           = D3DFMT_X8R8G8B8;
      d3dpp.BackBufferCount            = 1;
      d3dpp.MultiSampleType            = D3DMULTISAMPLE_NONE;
      d3dpp.MultiSampleQuality         = 0;
      d3dpp.SwapEffect                 = D3DSWAPEFFECT_DISCARD;
      d3dpp.hDeviceWindow              = hMainWindow;
      d3dpp.Windowed                   = true;
      d3dpp.EnableAutoDepthStencil     = true;
      d3dpp.AutoDepthStencilFormat     = D3DFMT_D24S8;
      d3dpp.Flags                      = 0;
      d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
      d3dpp.PresentationInterval       = D3DPRESENT_INTERVAL_IMMEDIATE;
  
  
      if(!d3dObject-&gt;CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hMainWindow, devBehaviorFlags, &amp;d3dpp, &amp;d3dDevice))
      {
          ::MessageBox(0, "Can't create D3D device", "Error", MB_ICONSTOP);
          return false;
      }
  
      return true;
  }
  </code></pre>