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 #include "ObjectTable.h"
\r
25 #include "Configuration.h"
\r
27 #include "Utilities.h"
\r
28 #include "InternalHelpers.h"
\r
31 using System::IntPtr;
\r
32 using System::Diagnostics::StackTrace;
\r
35 #include "ComObjectMacros.h"
\r
40 enum class ComObjectFlags
\r
47 public interface struct IComObject : System::IDisposable
\r
50 property System::IntPtr ComPointer
\r
52 virtual System::IntPtr get() = 0;
\r
57 /// The base class for all SlimDX types which represent COM interfaces.
\r
59 /// <unmanaged>IUnknown</unmanaged>
\r
60 public ref class ComObject abstract : IComObject
\r
63 IUnknown* m_Unknown;
\r
65 ComObjectFlags m_Flags;
\r
66 System::Diagnostics::StackTrace^ m_Source;
\r
72 void Construct( IUnknown* pointer );
\r
73 void Construct( IUnknown* pointer, ComObject^ owner );
\r
74 void Construct( System::IntPtr pointer, System::Guid guid );
\r
77 template< typename M, typename N >
\r
78 static M^ ConstructFromPointer( N* pointer, ComObject^ owner, ComObjectFlags flags )
\r
80 // Since this method is called internally by SlimDX to essentially translate the results of native
\r
81 // API calls to their managed counterparts via the object table, we expect that a null pointer
\r
82 // might be passed, and that's okay. This differs from ConstructFromUserPointer.
\r
86 M^ tableEntry = safe_cast<M^>( SlimDX::ObjectTable::Find( static_cast<System::IntPtr>( pointer ) ) );
\r
87 if( tableEntry != nullptr )
\r
89 if( static_cast<int>( flags & ComObjectFlags::IsAncillary ) == 0 )
\r
94 M^ result = gcnew M( pointer, owner );
\r
95 result->SetFlags( flags );
\r
99 template< typename M >
\r
100 static M^ ConstructFromUserPointer( System::IntPtr pointer )
\r
102 // This method gets called as a result of the user invoking the IntPtr overload of FromPointer
\r
103 // to create a SlimDX object from an externally-tracked native object. In this scenario, a
\r
104 // null pointer is a failure, so we throw.
\r
105 if( pointer == System::IntPtr::Zero )
\r
106 throw gcnew System::ArgumentNullException( "pointer" );
\r
108 M^ tableEntry = safe_cast<M^>( SlimDX::ObjectTable::Find( static_cast<System::IntPtr>( pointer ) ) );
\r
109 if( tableEntry != nullptr )
\r
114 M^ result = gcnew M( pointer );
\r
115 result->SetFlags( ComObjectFlags::IsExternal );
\r
120 property IUnknown* UnknownPointer
\r
125 property IUnknown* InternalPointer
\r
130 property ComObject^ Owner
\r
133 void set( ComObject^ value );
\r
136 void SetFlags( ComObjectFlags flags );
\r
137 void SetSource( System::Diagnostics::StackTrace^ stack );
\r
138 void SetCreationTime( int time );
\r
142 /// Gets a value that indicates whether the object has been disposed.
\r
144 property bool Disposed
\r
150 /// Gets an <see cref="IntPtr">IntPtr</see> to the underlying native COM interface.
\r
152 property System::IntPtr ComPointer
\r
154 virtual System::IntPtr get();
\r
158 /// Gets a <see cref="StackTrace"/> to the location where the object was created.
\r
160 property System::Diagnostics::StackTrace^ CreationSource
\r
162 System::Diagnostics::StackTrace^ get();
\r
166 /// Gets the timestamp, in milliseconds, of the object'ss creation.
\r
168 property int CreationTime
\r
174 /// Gets or sets a value indicating whether or not the object is in the default allocation pool.
\r
176 property bool IsDefaultPool;
\r
179 /// Extra tag data stored along with the object. This member is intended for use by users of SlimDX
\r
180 /// and has no internal meaning to the library.
\r
182 property Object^ Tag;
\r
185 /// Releases all resources used by the <see cref="SlimDX::ComObject"/>.
\r
187 virtual ~ComObject();
\r