Direct3D Driver Interface

DirectDraw presents a single, unified object to you as an application programmer. This object encapsulates both the DirectDraw and Direct3D states. The DirectDraw driver COM interfaces (IID_IDirectDraw or IID_IDirectDraw2) and the Direct3D driver COM interface (IID_IDirect3D) all allow you to communicate with the same underlying object. Therefore, no Direct3D object is created. Rather, a Direct3D interface to the DirectDraw object is obtained. This is achieved using the standard COM QueryInterface method.

The following example demonstrates how to create the DirectDraw object and obtain a Direct3D interface for communicating with that object.

LPDIRECTDRAW lpDD;

LPDIRECT3D lpD3D;

ddres = DirectDrawCreate(NULL, &lpDD, NULL);

if (FAILED(ddres))

...

ddres = lpDD->QueryInterface(IID_IDirect3D,

&lpD3D);

if (FAILED(ddres))

...

The code shown in the previous example creates a single object and obtains two interfaces to that object. Therefore, the object's reference count after the IDirectDraw::QueryInterface method call is two. The important implication of this is that the lifetime of the Direct3D driver state is the same as that of the DirectDraw object. Releasing the Direct3D interface does not destroy the Direct3D driver state. That state is not destroyed until all references, whether DirectDraw or Direct3D, to that object have been released. Hence, if you release a Direct3D interface while holding a reference to a DirectDraw driver interface, and re-query the Direct3D interface, the Direct3D state will be preserved.