Platform SDK: DirectX

Accessing COM Objects by Using C

[Visual Basic]

This topic pertains only to applications written in C. For an introduction to programming for DirectX in Visual Basic, see Visual Basic Programming Topics.

[C++]

Any COM interface method can be called from a C program. There are two things to remember when calling an interface method from C:

The following example creates a surface associated with a DirectDraw object by calling the IDirectDraw7::CreateSurface method in C:

ret = lpDD->lpVtbl->CreateSurface (lpDD, &ddsd, &lpDDS, 
      NULL); 

The lpDD parameter references the DirectDraw object associated with the new surface. The method call fills a surface-description structure (&ddsd) and returns a pointer to the new surface (&lpDDS).

To call the IDirectDraw7::CreateSurface method, first dereference the DirectDraw object's vtable, and then dereference the method from the vtable. The first parameter supplied in the method is a reference to the DirectDraw object that has been created and that invokes the method.

To illustrate the difference between calling a COM object method in C and C++, the same method is shown in C++ (C++ implicitly dereferences the lpVtbl parameter and passes the this pointer):

ret = lpDD->CreateSurface(&ddsd, &lpDDS, NULL)