ddraw: Get rid of ICOM_VFIELD_MULTI_NAME and ICOM_VFIELD_OFFSET.
[wine] / dlls / ddraw / ddcomimpl.h
1 /* A few helpful macros for implementing COM objects.
2  *
3  * Copyright 2000 TransGaming Technologies Inc.
4  *
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19
20 #ifndef _DDCOMIMPL_H_
21 #define _DDCOMIMPL_H_
22
23 #include <stddef.h>
24
25 /* Given an interface pointer, returns the implementation pointer. */
26 #define ICOM_OBJECT(impltype, ifacename, ifaceptr)              \
27         (impltype*)((ifaceptr) == NULL ? NULL                   \
28                   : (char*)(ifaceptr) - offsetof(impltype, ifacename##_vtbl))
29
30 #define ICOM_THIS_FROM(impltype, ifacename, ifaceptr) \
31         impltype* This = ICOM_OBJECT(impltype, ifacename, ifaceptr)
32
33 #define COM_INTERFACE_CAST(impltype, ifnamefrom, ifnameto, ifaceptr) \
34     ((ifaceptr) ? (ifnameto *)&(((impltype *)((char *)(ifaceptr) \
35     - offsetof(impltype, ifnamefrom##_vtbl)))->ifnameto##_vtbl) : NULL)
36 #endif /* _DDCOMIMPL_H_ */