Using macros to call DirectX com
Many Microsoft DirectX interfaces define a macro for each method, which makes it easier to use these methods in your application. You will find these macros in the header file of the interface declaration. These macros are designed to be Macros in C and Macros in C ++. If you want to use Macros in C ++, you must define _ cplusplus. Otherwise, you will use Macros in C. The syntax of macros is the same in the two languages, but they are defined separately in the header file for proper extension of call conventions.
For example, the following code snippet shows the C macro and C ++ macro defined for the idirect3d8: getadapteridentifier method from the d3d. h header file.
# If! Defined (_ cplusplus) | defined (cinterface)
...
# Define idirect3d8_getadapteridentifier (P, A, B, C) (p)-> lpvtbl-> getadapteridentifier (P, A, B, C)
...
# Else
...
# Define idirect3d8_getadapteridentifier (P, A, B, C) (p)-> getadapteridentifier (A, B, C)
...
# Endif
To use these macros, you must first obtain the pointers of related interfaces. The first parameter of the macro must be set as this pointer. The remaining parameters correspond to the parameters in the method. The return value of a macro is an hresult type, which is the return value of the method corresponding to the macro. The following code snippet uses a macro to call idirect3d8: getadapter (dentifier method, pd3d is a pointer to the idirect3d8 interface.
HR = idirect3d8_getadapteridentifier (pd3d,
Adapter,
Dwflags,
Pidentifier );
Note: Due to the limited translation level, errors are inevitable. If you find that the translation is incorrect, ask your friends on the road to correct it. Thank you.
Can be reproduced at will.
Translator: closeall
Translated by 2005.09.05