1 /* A few helpful macros for implementing COM objects.
3 * Copyright 2000 TransGaming Technologies Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 /* Generates the name for a vtable pointer for a given interface. */
23 /* The canonical name for a single interface is "lpVtbl". */
24 #define ICOM_VFIELD_MULTI_NAME2(iface) ITF_##iface
25 #define ICOM_VFIELD_MULTI_NAME(iface) ICOM_VFIELD_MULTI_NAME2(iface)
27 /* Declares a vtable pointer field in an implementation. */
28 #define ICOM_VFIELD_MULTI(iface) \
29 iface ICOM_VFIELD_MULTI_NAME(iface)
31 /* Returns the offset of a vtable pointer within an implementation object. */
32 #define ICOM_VFIELD_OFFSET(impltype, iface) \
33 offsetof(impltype, ICOM_VFIELD_MULTI_NAME(iface))
35 /* Given an interface pointer, returns the implementation pointer. */
36 #define ICOM_OBJECT(impltype, ifacename, ifaceptr) \
37 (impltype*)((ifaceptr) == NULL ? NULL \
38 : (char*)(ifaceptr) - ICOM_VFIELD_OFFSET(impltype,ifacename))
40 #define ICOM_THIS_FROM(impltype, ifacename, ifaceptr) \
41 impltype* This = ICOM_OBJECT(impltype, ifacename, ifaceptr)
43 /* Given an object and interface name, returns a pointer to that interface. */
44 #define ICOM_INTERFACE(implobj, iface) \
45 (&((implobj)->ICOM_VFIELD_MULTI_NAME(iface)))
47 #define ICOM_INIT_INTERFACE(implobj, ifacename, vtblname) \
49 (implobj)->ICOM_VFIELD_MULTI_NAME(ifacename).lpVtbl = &(vtblname); \
52 #define COM_INTERFACE_CAST(impltype, ifnamefrom, ifnameto, ifaceptr) \
53 ICOM_INTERFACE(ICOM_OBJECT(impltype, ifnamefrom, ifaceptr), ifnameto)