ddraw: Get rid of ICOM_INTERFACE.
[wine.git] / dlls / ddraw / ddcomimpl.h
blob4db261bf74332c8958be91f202f6eace3a8e9827
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #ifndef _DDCOMIMPL_H_
21 #define _DDCOMIMPL_H_
23 #include <stddef.h>
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_NAME(iface) iface##_vtbl
29 /* Returns the offset of a vtable pointer within an implementation object. */
30 #define ICOM_VFIELD_OFFSET(impltype, iface) \
31 offsetof(impltype, ICOM_VFIELD_MULTI_NAME(iface))
33 /* Given an interface pointer, returns the implementation pointer. */
34 #define ICOM_OBJECT(impltype, ifacename, ifaceptr) \
35 (impltype*)((ifaceptr) == NULL ? NULL \
36 : (char*)(ifaceptr) - ICOM_VFIELD_OFFSET(impltype,ifacename))
38 #define ICOM_THIS_FROM(impltype, ifacename, ifaceptr) \
39 impltype* This = ICOM_OBJECT(impltype, ifacename, ifaceptr)
41 #define COM_INTERFACE_CAST(impltype, ifnamefrom, ifnameto, ifaceptr) \
42 ((ifaceptr) ? (ifnameto *)&(((impltype *)((char *)(ifaceptr) \
43 - ICOM_VFIELD_OFFSET(impltype, ifnamefrom)))->ICOM_VFIELD_MULTI_NAME(ifnameto)) : NULL)
44 #endif /* _DDCOMIMPL_H_ */