3 // Permission is hereby granted, free of charge, to any person obtaining
4 // a copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to
8 // permit persons to whom the Software is furnished to do so, subject to
9 // the following conditions:
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 * Copyright (C) 5/11/2002 Carlos Harvey Perez
25 * Permission is hereby granted, free of charge, to any person obtaining
26 * a copy of this software and associated documentation files (the
27 * "Software"), to deal in the Software without restriction, including
28 * without limitation the rights to use, copy, modify, merge, publish,
29 * distribute, sublicense, and/or sell copies of the Software, and to
30 * permit persons to whom the Software is furnished to do so, subject
31 * to the following conditions:
33 * The above copyright notice and this permission notice shall be
34 * included in all copies or substantial portions of the Software.
36 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
37 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
38 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
40 * IN NO EVENT SHALL CARLOS HARVEY PEREZ BE LIABLE FOR ANY CLAIM,
41 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
42 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
43 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
45 * Except as contained in this notice, the name of Carlos Harvey Perez
46 * shall not be used in advertising or otherwise to promote the sale,
47 * use or other dealings in this Software without prior written
48 * authorization from Carlos Harvey Perez.
53 //namespace UtilityLibrary.Win32
54 namespace System
.Windows
.Forms
{
55 #if HAVE_SHELL_SUPPORT
56 internal class ShellHandle
: IDisposable
58 #region Class Variables
59 IntPtr handle
= IntPtr
.Zero
;
63 // Can only be used as base classes
64 internal ShellHandle(IntPtr handle
)
76 internal IntPtr Handle
78 get { return handle; }
84 internal virtual void Dispose(bool disposing
)
86 // This class encapsulate a PIDL handle that
87 // it is allocated my the Shell Memory Manager
88 // it needs to be deallocated by the Shell Memory Manager
91 // To avoid threads simultaneously releasing this resource
95 if ( handle
!= IntPtr
.Zero
)
97 // If we have a valid handle
98 // Release pointer that was allocated by the COM memory allocator
99 Win32
.SHFreeMalloc(handle
);
100 handle
= IntPtr
.Zero
;
107 // Implements the IDisposable Interface
108 public void Dispose()
110 // Let the Garbage Collector know that it does
111 // not need to call finalize for this class
112 GC
.SuppressFinalize(this);
122 internal class COMInterface
: IDisposable
124 #region Class Variables
125 internal IUnknown iUnknown
= null;
129 // Can only be used as base classes
130 internal COMInterface(IUnknown iUnknown
)
132 this.iUnknown
= iUnknown
;
145 protected virtual void Dispose(bool disposing
)
147 // Release the reference to this interface
150 if ( iUnknown
!= null )
160 // Implements the IDisposable Interface
161 public void Dispose()
163 // Let the Garbage Collector know that it does
164 // not need to call finalize for this class
165 GC
.SuppressFinalize(this);
174 internal class GdiHandle
: IDisposable
176 #region Class Variables
177 IntPtr handle
= IntPtr
.Zero
;
181 // Can only be used as base classes
182 protected GdiHandle(IntPtr handle
)
184 this.handle
= handle
;
196 get { return handle; }
202 protected virtual void Dispose(bool disposing
)
204 // To avoid threads simultaneously releasing this resource
208 if ( handle
!= IntPtr
.Zero
)
210 // If we have a valid handle
211 // Destroy the handle
212 Win32
.DeleteObject(handle
);
213 handle
= IntPtr
.Zero
;
220 // Implements the IDisposable Interface
221 public void Dispose()
223 // Let the Garbage Collector know that it does
224 // not need to call finalize for this class
225 GC
.SuppressFinalize(this);