?/TD>
Microsoft DirectX 9.0

Using Macros to Call DirectX COM Methods


Many of the Microsoft?DirectX® Component Object Model (COM) interfaces have macros defined for each method that simplify using the methods in your application. You can find definitions of these macros in the same header file as the interface declaration. The macros are designed to be used by both C and C++ applications. To use the C++ macros, you must define _cplusplus. Otherwise, the C macros will be used. The macro syntax is the same for both languages, but the header files include separate sets of macro definitions that expand to the appropriate calling convention.

For example, the following code fragment from the d3d.h header file shows the definitions of the C and C++ macros for the IDirect3D9::GetAdapterIdentifier method.

...
#define IDirect3D9_GetAdapterIdentifier(p,a,b,c) (p)->lpVtbl->GetAdapterIdentifier(p,a,b,c)
...
#else
...
#define IDirect3D9_GetAdapterIdentifier(p,a,b,c) (p)->GetAdapterIdentifier(a,b,c)
...
#endif

To use one of these macros, you must first obtain a pointer to the associated interface. The first parameter of the macro must be set to that pointer. The remaining parameters map to the method's parameters. The macro's return value is the HRESULT value that is returned by the method. The following code fragment uses a macro to call the IDirect3D9::GetAdapterIdentifier method. pD3D is a pointer to an IDirect3D9 interface.

hr = IDirect3D9_GetAdapterIdentifier(pD3D,
                                     Adapter,
                                     dwFlags,
                                     pIdentifier);									 
									 


© 2002 Microsoft Corporation. All rights reserved.