Creating Clipper Objects Using CoCreateInstance

DirectDrawClipper objects have full class-factory support for COM compliance. In addition to the standard DirectDrawCreateClipper function and IDirectDraw::CreateClipper method, you can also create a DirectDrawClipper object either by using CoGetClassObject to obtain a class factory and then calling CoCreateInstance, or by calling CoCreateInstance directly. The following example shows how to create a DirectDrawClipper object using CoCreateInstance and the IDirectDrawClipper::Initialize method.

ddrval = CoCreateInstance(&CLSID_DirectDrawClipper,

NULL,

CLSCTX_ALL,

&IID_IDirectDrawClipper,

&lpClipper);

if (!FAILED(ddrval))

ddrval = IDirectDrawClipper_Initialize(lpClipper,

lpDD, 0UL);

CLSID_DirectDrawClipper is the class identifier of the DirectDrawClipper object class, IID_IDirectDrawClipper is the currently supported interface (which is the one you want), and lpClipper is the clipper object returned.

Clippers created by the class factory mechanism must be initialized with the IDirectDrawClipper::Initialize method before you can use the object. 0UL is the dwFlags parameter, which in this case has a value of 0 since no flags are currently supported. In the example shown here, lpDD is the DirectDraw object that owns the DirectDrawClipper object. However, you could supply a NULL instead, which would create an independent clipper (equivalent to creating a DirectDrawClipper object using the DirectDrawCreateClipper function).

Before closing the application, shut down COM using CoUninitialize, as shown below.

CoUnitialize();