Getting an IDirectDraw4 Interface

The Component Object Model on which DirectX is built specifies that an object can provide new functionality through new interfaces, without affecting backward compatibility. To this end, the IDirectDraw4 interface supersedes the IDirectDraw2 interface. This new interface can be obtained by using the IUnknown::QueryInterface method, as the following C++ example shows:

// Create an IDirectDraw4 interface. 
LPDIRECTDRAW  lpDD; 
LPDIRECTDRAW4 lpDD4; 
 
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_IDirectDraw4, 
    (LPVOID *)&lpDD4); 
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 IDirectDraw4 interface.

After getting an IDirectDraw4 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 IDirectDraw2 and IDirectDraw4, for example) can cause unpredictable results.