blob: 7011770b4b84c0a7da3aba79a42045bca5d39ac7 [file] [log] [blame]
Alexandre Julliardd6c0f9f2001-01-04 22:44:55 +00001/* A few helpful macros for implementing COM objects.
2 *
3 * Copyright 2000 TransGaming Technologies Inc.
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00004 *
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.
9 *
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.
14 *
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
Alexandre Julliardd6c0f9f2001-01-04 22:44:55 +000018 */
19
Lionel Ulmer43c3dc42002-11-21 21:04:16 +000020#ifndef _DDCOMIMPL_H_
21#define _DDCOMIMPL_H_
22
Alexandre Julliardd6c0f9f2001-01-04 22:44:55 +000023#include <stddef.h>
24
25/* Generates the name for a vtable pointer for a given interface. */
26/* The canonical name for a single interface is "lpVtbl". */
27#define ICOM_VFIELD_MULTI_NAME2(iface) ITF_##iface
28#define ICOM_VFIELD_MULTI_NAME(iface) ICOM_VFIELD_MULTI_NAME2(iface)
29
30/* Declares a vtable pointer field in an implementation. */
31#define ICOM_VFIELD_MULTI(iface) \
32 iface ICOM_VFIELD_MULTI_NAME(iface)
33
34/* Returns the offset of a vtable pointer within an implementation object. */
35#define ICOM_VFIELD_OFFSET(impltype, iface) \
36 offsetof(impltype, ICOM_VFIELD_MULTI_NAME(iface))
37
38/* Given an interface pointer, returns the implementation pointer. */
39#define ICOM_OBJECT(impltype, ifacename, ifaceptr) \
40 (impltype*)((ifaceptr) == NULL ? NULL \
41 : (char*)(ifaceptr) - ICOM_VFIELD_OFFSET(impltype,ifacename))
42
43#define ICOM_THIS_FROM(impltype, ifacename, ifaceptr) \
44 impltype* This = ICOM_OBJECT(impltype, ifacename, ifaceptr)
45
46/* Given an object and interface name, returns a pointer to that interface. */
47#define ICOM_INTERFACE(implobj, iface) \
48 (&((implobj)->ICOM_VFIELD_MULTI_NAME(iface)))
49
50#define ICOM_INIT_INTERFACE(implobj, ifacename, vtblname) \
51 do { \
52 (implobj)->ICOM_VFIELD_MULTI_NAME(ifacename).lpVtbl = &(vtblname); \
53 } while (0)
54
55#define COM_INTERFACE_CAST(impltype, ifnamefrom, ifnameto, ifaceptr) \
56 ICOM_INTERFACE(ICOM_OBJECT(impltype, ifnamefrom, ifaceptr), ifnameto)
Lionel Ulmer43c3dc42002-11-21 21:04:16 +000057
58#endif /* _DDCOMIMPL_H_ */