You can create a DirectDraw object by using the CoCreateInstance function and the IDirectDraw2::Initialize method rather than the DirectDrawCreate function. The following steps describe how to create the DirectDraw object:
if (FAILED(CoInitialize(NULL)))
return FALSE;
ddrval = CoCreateInstance(&CLSID_DirectDraw,
NULL, CLSCTX_ALL, &IID_IDirectDraw2, &lpdd);
if(!FAILED(ddrval))
ddrval = IDirectDraw2_Initialize(lpdd, NULL);
In this call to CoCreateInstance, the first parameter, CLSID_DirectDraw, is the class identifier of the DirectDraw driver object class, the IID_IDirectDraw2 parameter identifies the particular DirectDraw interface to be created, and the lpdd parameter points to the DirectDraw object that is retrieved. If the call is successful, this function returns an uninitialized object.
Before you close the application, shut down COM by using the CoUninitialize function.
CoUnitialize();