title: Creating a D3D device without HWND input parameter to MSFT CreateDevice() function
body: <p>Kindly Pardon me if my doubt is silly or foolish. I am totally new to DirectX programming. Just have C++ knowledge (Very basic COM knowledge).  </p>
  
  <p>Below code sample is from MSDN <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb219676%28v=vs.85%29.aspx" rel="nofollow">Creating D3D device</a> which explains how to create a D3D device from scratch. </p>
  
  <p><strong>MyDoubt is</strong> :</p>
  
  <blockquote>
    <p>Here the function "<strong>pD3D->CreateDeviceEx()</strong>" takes in a parameter
    HWND hwnd. What if I am trying to create a D3D device from a
    commadline C++ win32 app where I need to use some of the functions in D3D device's interfaces. How do I get the HWND field. In this case
    how do I create D3D device. PLease explain in detail.</p>
  </blockquote>
  
  <pre><code>HRESULT InitD3D9Ex( /* IN */ HWND hWnd, /* OUT */ IDirect3DDevice9Ex ** ppD3DDevice )
  {
      HRESULT hr = E_FAIL;
      IDirect3D9Ex * pD3D = NULL;
      IDirect3DDevice9Ex * pDevice = NULL;
  
      if(ppD3DDevice == NULL)
      {
          return hr;
      }
  
      // Create the D3D object, which is needed to create the D3DDevice.
      if(FAILED(hr = Direct3DCreate9Ex( D3D_SDK_VERSION, &amp;pD3D )))
      {
          *ppD3DDevice = NULL;
          return hr;
      }
  
  
      // Set up the structure used to create the D3DDevice. 
      D3DPRESENT_PARAMETERS d3dpp; 
      ZeroMemory( &amp;d3dpp, sizeof(d3dpp) );
      d3dpp.Windowed = TRUE;
      d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
      d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
  
      // Create the Direct3D device. 
      if( FAILED( hr = pD3D-&gt;CreateDeviceEx( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                        D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                        &amp;d3dpp, NULL, &amp;pDevice ) ) )
  
      {
          *ppD3DDevice = NULL;
          return hr;
      }
  
      // Device state would normally be set here
  
      *ppD3DDevice = pDevice;
  
      return hr;
  }
  </code></pre>