DirectDraw presents programmers with a single, unified object. This object encapsulates both the DirectDraw and Direct3D states. Both the DirectDraw driver COM interfaces and the Direct3D driver COM interface allow you to communicate with the same underlying object. When an application uses Direct3D, no Direct3D object is created—rather, the application uses the standard COM QueryInterface method to obtain a Direct3D interface to a DirectDraw object.
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 is 2 after the IDirectDraw2::QueryInterface method call. 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 to that object—whether they are DirectDraw or Direct3D references—have been released. Therefore, if you release a Direct3D interface while holding a reference to a DirectDraw driver interface, and then query the Direct3D interface again, the Direct3D state will be preserved.