The COM model used by DirectDraw specifies that new functionality can be added by providing new interfaces. This release of DirectDraw implements two new interfaces, the IDirectDraw2 Interface and the IDirectDrawSurface2 Interface. These new interfaces 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 a compile-time error.
In addition to the IDirectDraw2::GetAvailableVidMem method, the IDirectDraw2 interface contains all of the methods provided in the IDirectDraw interface. Included in this interface are the IDirectDraw2::SetDisplayMode and IDirectDraw2::EnumDisplayModes methods which allow refresh rates to be specified. If refresh rates are not required, the IDirectDraw::SetDisplayMode and IDirectDraw::EnumDisplayModes methods can be used.
The interaction between the IDirectDraw::SetCooperativeLevel and IDirectDraw::SetDisplayMode methods is slightly different than the one between the IDirectDraw2::SetCooperativeLevel and IDirectDraw2::SetDisplayMode methods. If you are using the IDirectDraw interface and an application gains exclusive mode by calling IDirectDraw::SetCooperativeLevel with the DDSCL_EXCLUSIVE flag, changes the mode using IDirectDraw::SetDisplayMode, 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.
Note Because some methods behave somewhat differently in the two interfaces, mixing methods from IDirectDraw and IDirectDraw2 may cause unpredictable results. You should only use functions from one of these interfaces at a time; do not use some functions from IDirectDraw and other functions from IDirectDraw2.
For more information on using the IDirectDrawSurface2 interface, see IDirectDrawSurface2 Interface.