Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / Data / System / Data / OleDb / SafeHandles.cs / 1 / SafeHandles.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //----------------------------------------------------------------------------- namespace System.Data.OleDb { using System; using System.Data.Common; using System.Data.ProviderBase; using System.Diagnostics; using System.Globalization; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Security; using System.Security.Permissions; using System.Threading; using System.Runtime.ConstrainedExecution; internal sealed class DualCoTaskMem : SafeHandle { private IntPtr handle2; // this must be protected so derived classes can use out params. private DualCoTaskMem() : base(IntPtr.Zero, true) { this.handle2 = IntPtr.Zero; } // IDBInfo.GetLiteralInfo internal DualCoTaskMem(UnsafeNativeMethods.IDBInfo dbInfo, int[] literals, out int literalCount, out IntPtr literalInfo, out OleDbHResult hr) : this() { int count = (null != literals) ? literals.Length : 0; Bid.Trace("\n"); hr = dbInfo.GetLiteralInfo(count, literals, out literalCount, out base.handle, out this.handle2); literalInfo = base.handle; Bid.Trace(" %08X{HRESULT}\n", hr); } // IColumnsInfo.GetColumnInfo internal DualCoTaskMem(UnsafeNativeMethods.IColumnsInfo columnsInfo, out IntPtr columnCount, out IntPtr columnInfos, out OleDbHResult hr) : this() { Bid.Trace(" \n"); hr = columnsInfo.GetColumnInfo(out columnCount, out base.handle, out this.handle2); columnInfos = base.handle; Bid.Trace(" %08X{HRESULT}\n", hr); } // IDBSchemaRowset.GetSchemas internal DualCoTaskMem(UnsafeNativeMethods.IDBSchemaRowset dbSchemaRowset, out int schemaCount, out IntPtr schemaGuids, out IntPtr schemaRestrictions, out OleDbHResult hr) : this() { Bid.Trace(" \n"); hr = dbSchemaRowset.GetSchemas(out schemaCount, out base.handle, out this.handle2); schemaGuids = base.handle; schemaRestrictions = this.handle2; Bid.Trace(" %08X{HRESULT}\n", hr); } internal DualCoTaskMem(UnsafeNativeMethods.IColumnsRowset icolumnsRowset, out IntPtr cOptColumns, out OleDbHResult hr) : base(IntPtr.Zero, true) { Bid.Trace(" \n"); hr = icolumnsRowset.GetAvailableColumns(out cOptColumns, out base.handle); Bid.Trace(" %08X{HRESULT}\n", hr); } public override bool IsInvalid { get { return (((IntPtr.Zero == base.handle)) && (IntPtr.Zero == this.handle2)); } } protected override bool ReleaseHandle() { // NOTE: The SafeHandle class guarantees this will be called exactly once. IntPtr ptr = base.handle; base.handle = IntPtr.Zero; if (IntPtr.Zero != ptr) { SafeNativeMethods.CoTaskMemFree(ptr); } ptr = this.handle2; this.handle2 = IntPtr.Zero; if (IntPtr.Zero != ptr) { SafeNativeMethods.CoTaskMemFree(ptr); } return true; } } internal sealed class RowHandleBuffer : DbBuffer { internal RowHandleBuffer(IntPtr rowHandleFetchCount) : base((int)rowHandleFetchCount*ADP.PtrSize) { } internal IntPtr GetRowHandle(int index) { IntPtr value = ReadIntPtr( index * ADP.PtrSize); Debug.Assert(ODB.DB_NULL_HROW != value, "bad rowHandle"); return value; } } internal sealed class StringMemHandle : DbBuffer { internal StringMemHandle(string value) : base((null != value) ? checked(2+2*value.Length) : 0) { if (null != value) { // null-termination exists because of the extra 2+ which is zero'd during on allocation WriteCharArray(0, value.ToCharArray(), 0, value.Length); } } } internal sealed class ChapterHandle : WrappedIUnknown { internal static readonly ChapterHandle DB_NULL_HCHAPTER = new ChapterHandle(IntPtr.Zero); private IntPtr _chapterHandle; internal static ChapterHandle CreateChapterHandle(object chapteredRowset, RowBinding binding, int valueOffset) { if ((null == chapteredRowset) || (IntPtr.Zero == binding.ReadIntPtr(valueOffset))) { return ChapterHandle.DB_NULL_HCHAPTER; } return new ChapterHandle(chapteredRowset, binding, valueOffset); } // from ADODBRecordSetConstruction we do not want to release the initial chapter handle internal static ChapterHandle CreateChapterHandle(IntPtr chapter) { if (IntPtr.Zero == chapter) { return ChapterHandle.DB_NULL_HCHAPTER; } return new ChapterHandle(chapter); } // from ADODBRecordSetConstruction we do not want to release the initial chapter handle private ChapterHandle(IntPtr chapter) : base((object)null) { _chapterHandle = chapter; } private ChapterHandle(object chapteredRowset, RowBinding binding, int valueOffset) : base(chapteredRowset) { RuntimeHelpers.PrepareConstrainedRegions(); try {} finally { _chapterHandle = binding.InterlockedExchangePointer(valueOffset); } } internal IntPtr HChapter { get { return _chapterHandle; } } protected override bool ReleaseHandle() { // NOTE: The SafeHandle class guarantees this will be called exactly once and is non-interrutible. IntPtr chapter = _chapterHandle; _chapterHandle = IntPtr.Zero; if ((IntPtr.Zero != base.handle) && (IntPtr.Zero != chapter)) { Bid.Trace(" Chapter=%Id\n", chapter); OleDbHResult hr = (OleDbHResult)NativeOledbWrapper.IChapteredRowsetReleaseChapter(base.handle, chapter); Bid.Trace(" %08X{HRESULT}\n", hr); } return base.ReleaseHandle(); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //----------------------------------------------------------------------------- namespace System.Data.OleDb { using System; using System.Data.Common; using System.Data.ProviderBase; using System.Diagnostics; using System.Globalization; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Security; using System.Security.Permissions; using System.Threading; using System.Runtime.ConstrainedExecution; internal sealed class DualCoTaskMem : SafeHandle { private IntPtr handle2; // this must be protected so derived classes can use out params. private DualCoTaskMem() : base(IntPtr.Zero, true) { this.handle2 = IntPtr.Zero; } // IDBInfo.GetLiteralInfo internal DualCoTaskMem(UnsafeNativeMethods.IDBInfo dbInfo, int[] literals, out int literalCount, out IntPtr literalInfo, out OleDbHResult hr) : this() { int count = (null != literals) ? literals.Length : 0; Bid.Trace("\n"); hr = dbInfo.GetLiteralInfo(count, literals, out literalCount, out base.handle, out this.handle2); literalInfo = base.handle; Bid.Trace(" %08X{HRESULT}\n", hr); } // IColumnsInfo.GetColumnInfo internal DualCoTaskMem(UnsafeNativeMethods.IColumnsInfo columnsInfo, out IntPtr columnCount, out IntPtr columnInfos, out OleDbHResult hr) : this() { Bid.Trace(" \n"); hr = columnsInfo.GetColumnInfo(out columnCount, out base.handle, out this.handle2); columnInfos = base.handle; Bid.Trace(" %08X{HRESULT}\n", hr); } // IDBSchemaRowset.GetSchemas internal DualCoTaskMem(UnsafeNativeMethods.IDBSchemaRowset dbSchemaRowset, out int schemaCount, out IntPtr schemaGuids, out IntPtr schemaRestrictions, out OleDbHResult hr) : this() { Bid.Trace(" \n"); hr = dbSchemaRowset.GetSchemas(out schemaCount, out base.handle, out this.handle2); schemaGuids = base.handle; schemaRestrictions = this.handle2; Bid.Trace(" %08X{HRESULT}\n", hr); } internal DualCoTaskMem(UnsafeNativeMethods.IColumnsRowset icolumnsRowset, out IntPtr cOptColumns, out OleDbHResult hr) : base(IntPtr.Zero, true) { Bid.Trace(" \n"); hr = icolumnsRowset.GetAvailableColumns(out cOptColumns, out base.handle); Bid.Trace(" %08X{HRESULT}\n", hr); } public override bool IsInvalid { get { return (((IntPtr.Zero == base.handle)) && (IntPtr.Zero == this.handle2)); } } protected override bool ReleaseHandle() { // NOTE: The SafeHandle class guarantees this will be called exactly once. IntPtr ptr = base.handle; base.handle = IntPtr.Zero; if (IntPtr.Zero != ptr) { SafeNativeMethods.CoTaskMemFree(ptr); } ptr = this.handle2; this.handle2 = IntPtr.Zero; if (IntPtr.Zero != ptr) { SafeNativeMethods.CoTaskMemFree(ptr); } return true; } } internal sealed class RowHandleBuffer : DbBuffer { internal RowHandleBuffer(IntPtr rowHandleFetchCount) : base((int)rowHandleFetchCount*ADP.PtrSize) { } internal IntPtr GetRowHandle(int index) { IntPtr value = ReadIntPtr( index * ADP.PtrSize); Debug.Assert(ODB.DB_NULL_HROW != value, "bad rowHandle"); return value; } } internal sealed class StringMemHandle : DbBuffer { internal StringMemHandle(string value) : base((null != value) ? checked(2+2*value.Length) : 0) { if (null != value) { // null-termination exists because of the extra 2+ which is zero'd during on allocation WriteCharArray(0, value.ToCharArray(), 0, value.Length); } } } internal sealed class ChapterHandle : WrappedIUnknown { internal static readonly ChapterHandle DB_NULL_HCHAPTER = new ChapterHandle(IntPtr.Zero); private IntPtr _chapterHandle; internal static ChapterHandle CreateChapterHandle(object chapteredRowset, RowBinding binding, int valueOffset) { if ((null == chapteredRowset) || (IntPtr.Zero == binding.ReadIntPtr(valueOffset))) { return ChapterHandle.DB_NULL_HCHAPTER; } return new ChapterHandle(chapteredRowset, binding, valueOffset); } // from ADODBRecordSetConstruction we do not want to release the initial chapter handle internal static ChapterHandle CreateChapterHandle(IntPtr chapter) { if (IntPtr.Zero == chapter) { return ChapterHandle.DB_NULL_HCHAPTER; } return new ChapterHandle(chapter); } // from ADODBRecordSetConstruction we do not want to release the initial chapter handle private ChapterHandle(IntPtr chapter) : base((object)null) { _chapterHandle = chapter; } private ChapterHandle(object chapteredRowset, RowBinding binding, int valueOffset) : base(chapteredRowset) { RuntimeHelpers.PrepareConstrainedRegions(); try {} finally { _chapterHandle = binding.InterlockedExchangePointer(valueOffset); } } internal IntPtr HChapter { get { return _chapterHandle; } } protected override bool ReleaseHandle() { // NOTE: The SafeHandle class guarantees this will be called exactly once and is non-interrutible. IntPtr chapter = _chapterHandle; _chapterHandle = IntPtr.Zero; if ((IntPtr.Zero != base.handle) && (IntPtr.Zero != chapter)) { Bid.Trace(" Chapter=%Id\n", chapter); OleDbHResult hr = (OleDbHResult)NativeOledbWrapper.IChapteredRowsetReleaseChapter(base.handle, chapter); Bid.Trace(" %08X{HRESULT}\n", hr); } return base.ReleaseHandle(); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DelegateBodyWriter.cs
- WebConfigurationManager.cs
- InputLanguageCollection.cs
- LocatorPartList.cs
- FontStyles.cs
- CharUnicodeInfo.cs
- SequenceFullException.cs
- EventRoute.cs
- Math.cs
- UInt16Storage.cs
- SerializerProvider.cs
- NumberFunctions.cs
- OleDbSchemaGuid.cs
- ArcSegment.cs
- GPPOINT.cs
- XpsFilter.cs
- TableDetailsRow.cs
- CriticalExceptions.cs
- DataConnectionHelper.cs
- WebContentFormatHelper.cs
- VerificationAttribute.cs
- XPathMultyIterator.cs
- BaseTransportHeaders.cs
- SelectiveScrollingGrid.cs
- Label.cs
- RegionInfo.cs
- BackStopAuthenticationModule.cs
- SqlInternalConnectionTds.cs
- EndpointPerformanceCounters.cs
- DragDeltaEventArgs.cs
- StateWorkerRequest.cs
- ParallelTimeline.cs
- X509UI.cs
- SetStateEventArgs.cs
- TraceInternal.cs
- LogicalExpr.cs
- InputLanguageCollection.cs
- ResourceSet.cs
- EmbeddedMailObject.cs
- HtmlTextViewAdapter.cs
- TextDecorationCollectionConverter.cs
- RawUIStateInputReport.cs
- WithStatement.cs
- ModelItemExtensions.cs
- TypeDependencyAttribute.cs
- StatementContext.cs
- RightsManagementInformation.cs
- ServiceBusyException.cs
- ComponentResourceKeyConverter.cs
- ThemeInfoAttribute.cs
- recordstate.cs
- PartManifestEntry.cs
- TransactionOptions.cs
- SatelliteContractVersionAttribute.cs
- UnsafeNativeMethods.cs
- RawStylusInputReport.cs
- FastEncoderWindow.cs
- OleDbCommand.cs
- Geometry3D.cs
- LoginDesigner.cs
- CompressionTransform.cs
- UserControl.cs
- CqlWriter.cs
- RawStylusInput.cs
- GetPageNumberCompletedEventArgs.cs
- DynamicRenderer.cs
- BindableTemplateBuilder.cs
- Point4DValueSerializer.cs
- TextPattern.cs
- TimeSpanValidatorAttribute.cs
- EventProvider.cs
- ConfigurationElement.cs
- PerSessionInstanceContextProvider.cs
- CacheForPrimitiveTypes.cs
- SqlUtil.cs
- StorageEntitySetMapping.cs
- DBBindings.cs
- SerializationFieldInfo.cs
- MemberRelationshipService.cs
- GorillaCodec.cs
- MultipartIdentifier.cs
- SqlIdentifier.cs
- ToolStripOverflow.cs
- DataSvcMapFile.cs
- HttpHandlerActionCollection.cs
- FlowLayoutSettings.cs
- WizardPanel.cs
- RightsManagementResourceHelper.cs
- AVElementHelper.cs
- ImageListImage.cs
- MruCache.cs
- Span.cs
- ProcessHostServerConfig.cs
- FormViewInsertEventArgs.cs
- UdpDiscoveryEndpoint.cs
- HTMLTagNameToTypeMapper.cs
- RegexInterpreter.cs
- DocumentReferenceCollection.cs
- TableCell.cs
- ComplexBindingPropertiesAttribute.cs