2 * Copyright (c) 2007-2010 SlimDX Group
\r
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
5 * of this software and associated documentation files (the "Software"), to deal
\r
6 * in the Software without restriction, including without limitation the rights
\r
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
8 * copies of the Software, and to permit persons to whom the Software is
\r
9 * furnished to do so, subject to the following conditions:
\r
11 * The above copyright notice and this permission notice shall be included in
\r
12 * all copies or substantial portions of the Software.
\r
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
24 #undef COMOBJECT_BASE
\r
25 #undef COMOBJECT_CUSTOM
\r
27 #define COMOBJECT_BASE(nativeType) \
\r
29 static property System::Guid NativeInterface { System::Guid get() { return Utilities::ConvertNativeGuid( IID_ ## nativeType ); } } \
\r
30 property nativeType* InternalPointer { nativeType* get() new { return static_cast<nativeType*>( UnknownPointer ); } } \
\r
33 // This macro provides the basic infrastructure for SlimDX ComObject subclasses.
\r
34 #define COMOBJECT(nativeType, managedType) \
\r
36 managedType( nativeType* pointer, ComObject^ owner ) { Construct( pointer, owner ); } \
\r
37 managedType( System::IntPtr pointer ) { Construct( pointer, NativeInterface ); } \
\r
39 static managedType^ FromPointerReflectionThunk( System::IntPtr pointer ) { return FromPointer( static_cast<nativeType*>( pointer.ToPointer() ) ); } \
\r
40 static managedType^ FromPointerReflectionThunk( System::IntPtr pointer, ComObject^ owner ) { return FromPointer( static_cast<nativeType*>( pointer.ToPointer()), owner ); } \
\r
41 static managedType^ FromPointer( nativeType* pointer ) { return FromPointer( pointer, nullptr, ComObjectFlags::None ); } \
\r
42 static managedType^ FromPointer( nativeType* pointer, ComObject^ owner ) { return FromPointer( pointer, owner, ComObjectFlags::None ); } \
\r
43 static managedType^ FromPointer( nativeType* pointer, ComObject^ owner, ComObjectFlags flags ) { return ConstructFromPointer<managedType,nativeType>( pointer, owner, flags ); } \
\r
45 static managedType^ FromPointer( System::IntPtr pointer ) { return ConstructFromUserPointer<managedType>( pointer ); } \
\r
46 COMOBJECT_BASE(nativeType)
\r
48 // This macro provides the basic infrastructure for SlimDX ComObject subclasses, but allows
\r
49 // the subclass to customize the behavior of the creation process for that subclass. This macro
\r
50 // should be applied instead of the regular COMOBJECT() macro when such customization is required.
\r
51 // The subclass must provide a body for the following methods:
\r
52 // * managedType( nativeType* pointer, ComObject^ owner )
\r
53 // * managedType( System::IntPtr pointer )
\r
54 // * managedType^ FromPointer( nativeType* pointer, ComObject^ owner, ComObjectFlags flags )
\r
55 // * managedType^ FromPointer( System::IntPtr pointer )
\r
57 // Partial specialization is not supported; if the subclass needs special behavior for only
\r
58 // a subset of the above methods, it must still implement all of them, copying the standard
\r
59 // implementation from the COMOBJECT() macro for the appropriate non-specialized methods.
\r
60 #define COMOBJECT_CUSTOM(nativeType, managedType) \
\r
62 managedType( nativeType* pointer, ComObject^ owner ); \
\r
63 managedType( System::IntPtr pointer ); \
\r
65 static managedType^ FromPointer( nativeType* pointer ) { return FromPointer( pointer, nullptr, ComObjectFlags::None ); } \
\r
66 static managedType^ FromPointer( nativeType* pointer, ComObject^ owner ) { return FromPointer( pointer, owner, ComObjectFlags::None ); } \
\r
67 static managedType^ FromPointer( nativeType* pointer, ComObject^ owner, ComObjectFlags flags ); \
\r
69 static managedType^ FromPointer( System::IntPtr pointer ); \
\r
70 COMOBJECT_BASE(nativeType)
\r