1 /* A few helpful macros for implementing COM objects.
3 * Copyright 2000 TransGaming Technologies Inc.
8 /* Generates the name for a vtable pointer for a given interface. */
9 /* The canonical name for a single interface is "lpVtbl". */
10 #define ICOM_VFIELD_MULTI_NAME2(iface) ITF_##iface
11 #define ICOM_VFIELD_MULTI_NAME(iface) ICOM_VFIELD_MULTI_NAME2(iface)
13 /* Declares a vtable pointer field in an implementation. */
14 #define ICOM_VFIELD_MULTI(iface) \
15 iface ICOM_VFIELD_MULTI_NAME(iface)
17 /* Returns the offset of a vtable pointer within an implementation object. */
18 #define ICOM_VFIELD_OFFSET(impltype, iface) \
19 offsetof(impltype, ICOM_VFIELD_MULTI_NAME(iface))
21 /* Given an interface pointer, returns the implementation pointer. */
22 #define ICOM_OBJECT(impltype, ifacename, ifaceptr) \
23 (impltype*)((ifaceptr) == NULL ? NULL \
24 : (char*)(ifaceptr) - ICOM_VFIELD_OFFSET(impltype,ifacename))
26 #define ICOM_THIS_FROM(impltype, ifacename, ifaceptr) \
27 impltype* This = ICOM_OBJECT(impltype, ifacename, ifaceptr)
29 /* Given an object and interface name, returns a pointer to that interface. */
30 #define ICOM_INTERFACE(implobj, iface) \
31 (&((implobj)->ICOM_VFIELD_MULTI_NAME(iface)))
33 #define ICOM_INIT_INTERFACE(implobj, ifacename, vtblname) \
35 (implobj)->ICOM_VFIELD_MULTI_NAME(ifacename).lpVtbl = &(vtblname); \
38 #define COM_INTERFACE_CAST(impltype, ifnamefrom, ifnameto, ifaceptr) \
39 ICOM_INTERFACE(ICOM_OBJECT(impltype, ifnamefrom, ifaceptr), ifnameto)