Retrieving an IDirect3D3 Interface

When a Direct3D application starts up, it must obtain a pointer to an IDirect3D3 interface to access Direct3D functionality. Use the following steps to obtain a pointer to the IDirect3D3 interface:

To obtain a pointer to the IDirect3D3 interface

  1. Call DirectDrawCreate to create a DirectDraw device.
  2. Call the IUnknown::QueryInterface method to get a pointer to an IDirect3D3 interface.

The following diagram illustrates these steps:

The following code fragment demonstrates how to query for an IDirect3D3 interface:

LPDIRECTDRAW    lpDD;               // IDirectDraw Interface
LPDIRECT3D3     lpD3D;              // IDirect3D3 Interface
 
// Get an IDirectDraw interface.
// Use the current display driver.
hResult = DirectDrawCreate (NULL, &lpDD, NULL); 
if (FAILED (hResult))
{
    // Code to handle an error goes here.
}
 
// Get D3D interface
hResult = 
    lpDD->QueryInterface (IID_IDirect3D3, (void **)&lpD3D);
if (FAILED (hResult))
{
    // Code to handle the error goes here.
}