What's New in IDirectDraw2?

The COM model that DirectX uses specifies that new functionality can be added by providing new interfaces. The IDirectDraw2 interface supersedes the IDirectDraw interface. This new interface can be obtained by using the IDirectDraw::QueryInterface method, as shown in the following example:

// Create an IDirectDraw2 interface.

LPDIRECTDRAW lpDD;

LPDIRECTDRAW2 lpDD2;

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

if(ddrval != DD_OK)

return;

ddrval = lpDD->SetCooperativeLevel(hwnd,

DDSCL_NORMAL);

if(ddrval != DD_OK)

return;

ddrval = lpDD->QueryInterface(IID_IDirectDraw2,

(LPVOID *)&lpDD2);

if(ddrval != DD_OK)

return;

ddscaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;

ddrval = lpDD2->GetAvailableVidMem(&ddscaps, &total,

&free);

if(ddrval != DD_OK)

return;

This example shows C++ syntax for creating an IDirectDraw interface, which then uses the IDirectDraw::QueryInterface method to create an IDirectDraw2 interface. This interface contains the IDirectDraw2::GetAvailableVidMem method. An attempt to use this method from an IDirectDraw interface will result in an error during compiling.

The IDirectDraw2::GetAvailableVidMem method is the only method that was added to the IDirectDraw interface when the IDirectDraw2 interface was created. Two methods—IDirectDraw2::SetDisplayMode and IDirectDraw2::EnumDisplayModes—were modified or extended when they were included in IDirectDraw2, however.

The interaction between the IDirectDraw::SetCooperativeLevel and IDirectDraw::SetDisplayMode methods is slightly different from the interaction between the IDirectDraw2::SetCooperativeLevel and IDirectDraw2::SetDisplayMode methods. If you use the IDirectDraw interface and an application gains exclusive (full-screen) mode by calling IDirectDraw::SetCooperativeLevel with the DDSCL_EXCLUSIVE flag, changes the mode by using IDirectDraw::SetDisplayMode, and then releases exclusive mode by calling IDirectDraw::SetCooperativeLevel with the DDSCL_NORMAL flag, the original display mode will not be restored. The new display mode will remain until the application calls the IDirectDraw::RestoreDisplayMode method or the DirectDraw object is deleted. However, if you are using the IDirectDraw2 interface and an application follows the same steps, the original display mode will be restored when exclusive mode is lost.

Because some methods might change with the release of a new interface, mixing methods from an interface and its replacement (between IDirectDraw and IDirectDraw2, for example) can cause unpredictable results. You should use methods from only one version of an interface at a time.