Getting an IDirectDraw2 Interface

The Component Object Model on which DirectX is built specifies that an object can provide new functionality can be added through new interfaces, without affecting backward compatibility. To this end, the IDirectDraw2 interface supersedes the IDirectDraw interface. This new interface can be obtained by using the IDirectDraw::QueryInterface method, as shown in the following C++ 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; 
 

The preceding example creates a DirectDraw object, then calls the IUnknown::QueryInterface method of the IDirectDraw interface it received to create an IDirectDraw2 interface.

After getting an IDirectDraw2 interface, you can begin calling its methods to take advantage of new features, performance improvements, and behavioral differences. 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.