Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / Tools / WSATConfig / Configuration / ClusterSafeNativeMethods.cs / 1305376 / ClusterSafeNativeMethods.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace Microsoft.Tools.ServiceModel.WsatConfig
{
using System;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Security.AccessControl;
using System.Security.Permissions;
using System.Text;
using Microsoft.Win32;
abstract class SafeClusterHandle : SafeHandle
{
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
internal SafeClusterHandle()
:
base(IntPtr.Zero, true)
{
}
public override bool IsInvalid
{
get { return IsClosed || handle == IntPtr.Zero; }
}
}
class SafeHCluster : SafeClusterHandle
{
// MSDN remarks: This function always returns TRUE.
[DllImport(SafeNativeMethods.ClusApi)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
static extern bool CloseCluster([In] IntPtr hCluster);
protected override bool ReleaseHandle()
{
return CloseCluster(handle);
}
}
class SafeHResource : SafeClusterHandle
{
[DllImport(SafeNativeMethods.ClusApi)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
static extern bool CloseClusterResource([In] IntPtr hResource);
protected override bool ReleaseHandle()
{
return CloseClusterResource(handle);
}
}
class SafeHClusEnum : SafeClusterHandle
{
[DllImport(SafeNativeMethods.ClusApi)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
static extern uint ClusterCloseEnum([In] IntPtr hEnum);
protected override bool ReleaseHandle()
{
return ClusterCloseEnum(handle) == SafeNativeMethods.ERROR_SUCCESS;
}
}
class SafeHKey : SafeClusterHandle
{
[DllImport(SafeNativeMethods.ClusApi)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
static extern int ClusterRegCloseKey([In] IntPtr hEnum);
protected override bool ReleaseHandle()
{
return ClusterRegCloseKey(handle) == SafeNativeMethods.ERROR_SUCCESS;
}
}
[Flags]
enum ClusterEnum : uint
{
Node = 0x00000001,
ResType = 0x00000002,
Resource = 0x00000004,
Group = 0x00000008,
Network = 0x00000010,
NetInterface = 0x00000020,
InternalNetwork = 0x80000000
}
enum ClusterResourceControlCode : uint
{
GetResourceType = 0x0100002d,
//GetId = 0x01000039
}
static partial class SafeNativeMethods
{
internal const string ClusApi = "clusapi.dll";
internal const uint ERROR_SUCCESS = 0;
internal const uint ERROR_FILE_NOT_FOUND = 2;
internal const uint ERROR_INSUFFICIENT_BUFFER = 122;
internal const uint ERROR_MORE_DATA = 234;
internal const uint ERROR_NO_MORE_ITEMS = 259;
internal const uint REG_OPTION_NON_VOLATILE = 0;
[DllImport(ClusApi, SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern SafeHCluster OpenCluster(
[MarshalAs(UnmanagedType.LPWStr)] [In] string lpszClusterName);
[DllImport(ClusApi, SetLastError = false, CharSet = CharSet.Unicode)]
internal static extern int GetClusterInformation(
[In] SafeHCluster hCluster,
[Out] StringBuilder lpszClusterName,
[In, Out] ref uint lpcchClusterName,
[In, Out] IntPtr lpClusterInfo
);
[DllImport(ClusApi, SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern SafeHClusEnum ClusterOpenEnum(
[In] SafeHCluster hCluster,
[In] ClusterEnum dwType);
[DllImport(ClusApi, CharSet = CharSet.Unicode)]
internal static extern uint ClusterEnum(
[In] SafeHClusEnum hEnum,
[In] uint dwIndex,
[Out] out uint lpdwType,
[Out] StringBuilder lpszName,
[In, Out] ref uint lpcchName);
[DllImport(ClusApi, CharSet = CharSet.Unicode)]
internal static extern uint ClusterResourceControl(
[In] SafeHResource hResource,
[In] IntPtr hHostNode, //HNODE hHostNode, never used
[In] ClusterResourceControlCode dwControlCode,
[In] IntPtr lpInBuffer, // LPVOID lpInBuffer, never used
[In] uint cbInBufferSize,
[In, Out, MarshalAs(UnmanagedType.LPArray)] byte[] buffer,
[In] uint cbOutBufferSize,
[In, Out] ref uint lpcbBytesReturned);
[DllImport(ClusApi, SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern SafeHResource OpenClusterResource(
[In] SafeHCluster hCluster,
[In, MarshalAs(UnmanagedType.LPWStr)] string lpszResourceName);
[DllImport(ClusApi, SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern bool GetClusterResourceNetworkName(
[In] SafeHResource hResource,
[Out] StringBuilder lpBuffer,
[In, Out] ref uint nSize);
[DllImport(ClusApi, SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern SafeHKey GetClusterResourceKey(
[In] SafeHResource hResource,
[In] RegistryRights samDesired);
[DllImport(ClusApi, SetLastError = false, CharSet = CharSet.Unicode)]
internal static extern int ClusterRegCreateKey(
[In] SafeHKey hKey,
[In, MarshalAs(UnmanagedType.LPWStr)] string lpszSubKey,
[In] uint dwOption,
[In] RegistryRights samDesired,
[In] IntPtr lpSecurityAttributes,
[Out] out SafeHKey phkResult,
[Out] out int lpdwDisposition);
[DllImport(ClusApi, CharSet = CharSet.Unicode)]
internal static extern int ClusterRegQueryValue(
[In] SafeHKey hKey,
[In, MarshalAs(UnmanagedType.LPWStr)] string lpszValueName,
[Out] out RegistryValueKind lpdwValueType,
[Out, MarshalAs(UnmanagedType.LPArray)] byte[] lpbData,
[In, Out] ref uint lpcbData);
[DllImport(ClusApi, CharSet = CharSet.Unicode)]
internal static extern int ClusterRegSetValue(
[In] SafeHKey hKey,
[In, MarshalAs(UnmanagedType.LPWStr)] string lpszValueName,
[In] RegistryValueKind lpdwValueType,
[In, MarshalAs(UnmanagedType.LPArray)] byte[] lpbData,
[In] uint lpcbData);
[DllImport(ClusApi, CharSet = CharSet.Unicode)]
internal static extern int ClusterRegGetKeySecurity(
[In] SafeHKey hKey,
[In] SecurityInfos securityInformation,
[In, Out] byte[] securityDescriptor,
[In, Out] ref uint lpcbSecurityDescriptor);
[DllImport(ClusApi, CharSet = CharSet.Unicode)]
internal static extern int ClusterRegSetKeySecurity(
[In] SafeHKey hKey,
[In] SecurityInfos securityInformation,
[In] byte[] securityDescriptor);
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace Microsoft.Tools.ServiceModel.WsatConfig
{
using System;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Security.AccessControl;
using System.Security.Permissions;
using System.Text;
using Microsoft.Win32;
abstract class SafeClusterHandle : SafeHandle
{
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
internal SafeClusterHandle()
:
base(IntPtr.Zero, true)
{
}
public override bool IsInvalid
{
get { return IsClosed || handle == IntPtr.Zero; }
}
}
class SafeHCluster : SafeClusterHandle
{
// MSDN remarks: This function always returns TRUE.
[DllImport(SafeNativeMethods.ClusApi)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
static extern bool CloseCluster([In] IntPtr hCluster);
protected override bool ReleaseHandle()
{
return CloseCluster(handle);
}
}
class SafeHResource : SafeClusterHandle
{
[DllImport(SafeNativeMethods.ClusApi)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
static extern bool CloseClusterResource([In] IntPtr hResource);
protected override bool ReleaseHandle()
{
return CloseClusterResource(handle);
}
}
class SafeHClusEnum : SafeClusterHandle
{
[DllImport(SafeNativeMethods.ClusApi)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
static extern uint ClusterCloseEnum([In] IntPtr hEnum);
protected override bool ReleaseHandle()
{
return ClusterCloseEnum(handle) == SafeNativeMethods.ERROR_SUCCESS;
}
}
class SafeHKey : SafeClusterHandle
{
[DllImport(SafeNativeMethods.ClusApi)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
static extern int ClusterRegCloseKey([In] IntPtr hEnum);
protected override bool ReleaseHandle()
{
return ClusterRegCloseKey(handle) == SafeNativeMethods.ERROR_SUCCESS;
}
}
[Flags]
enum ClusterEnum : uint
{
Node = 0x00000001,
ResType = 0x00000002,
Resource = 0x00000004,
Group = 0x00000008,
Network = 0x00000010,
NetInterface = 0x00000020,
InternalNetwork = 0x80000000
}
enum ClusterResourceControlCode : uint
{
GetResourceType = 0x0100002d,
//GetId = 0x01000039
}
static partial class SafeNativeMethods
{
internal const string ClusApi = "clusapi.dll";
internal const uint ERROR_SUCCESS = 0;
internal const uint ERROR_FILE_NOT_FOUND = 2;
internal const uint ERROR_INSUFFICIENT_BUFFER = 122;
internal const uint ERROR_MORE_DATA = 234;
internal const uint ERROR_NO_MORE_ITEMS = 259;
internal const uint REG_OPTION_NON_VOLATILE = 0;
[DllImport(ClusApi, SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern SafeHCluster OpenCluster(
[MarshalAs(UnmanagedType.LPWStr)] [In] string lpszClusterName);
[DllImport(ClusApi, SetLastError = false, CharSet = CharSet.Unicode)]
internal static extern int GetClusterInformation(
[In] SafeHCluster hCluster,
[Out] StringBuilder lpszClusterName,
[In, Out] ref uint lpcchClusterName,
[In, Out] IntPtr lpClusterInfo
);
[DllImport(ClusApi, SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern SafeHClusEnum ClusterOpenEnum(
[In] SafeHCluster hCluster,
[In] ClusterEnum dwType);
[DllImport(ClusApi, CharSet = CharSet.Unicode)]
internal static extern uint ClusterEnum(
[In] SafeHClusEnum hEnum,
[In] uint dwIndex,
[Out] out uint lpdwType,
[Out] StringBuilder lpszName,
[In, Out] ref uint lpcchName);
[DllImport(ClusApi, CharSet = CharSet.Unicode)]
internal static extern uint ClusterResourceControl(
[In] SafeHResource hResource,
[In] IntPtr hHostNode, //HNODE hHostNode, never used
[In] ClusterResourceControlCode dwControlCode,
[In] IntPtr lpInBuffer, // LPVOID lpInBuffer, never used
[In] uint cbInBufferSize,
[In, Out, MarshalAs(UnmanagedType.LPArray)] byte[] buffer,
[In] uint cbOutBufferSize,
[In, Out] ref uint lpcbBytesReturned);
[DllImport(ClusApi, SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern SafeHResource OpenClusterResource(
[In] SafeHCluster hCluster,
[In, MarshalAs(UnmanagedType.LPWStr)] string lpszResourceName);
[DllImport(ClusApi, SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern bool GetClusterResourceNetworkName(
[In] SafeHResource hResource,
[Out] StringBuilder lpBuffer,
[In, Out] ref uint nSize);
[DllImport(ClusApi, SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern SafeHKey GetClusterResourceKey(
[In] SafeHResource hResource,
[In] RegistryRights samDesired);
[DllImport(ClusApi, SetLastError = false, CharSet = CharSet.Unicode)]
internal static extern int ClusterRegCreateKey(
[In] SafeHKey hKey,
[In, MarshalAs(UnmanagedType.LPWStr)] string lpszSubKey,
[In] uint dwOption,
[In] RegistryRights samDesired,
[In] IntPtr lpSecurityAttributes,
[Out] out SafeHKey phkResult,
[Out] out int lpdwDisposition);
[DllImport(ClusApi, CharSet = CharSet.Unicode)]
internal static extern int ClusterRegQueryValue(
[In] SafeHKey hKey,
[In, MarshalAs(UnmanagedType.LPWStr)] string lpszValueName,
[Out] out RegistryValueKind lpdwValueType,
[Out, MarshalAs(UnmanagedType.LPArray)] byte[] lpbData,
[In, Out] ref uint lpcbData);
[DllImport(ClusApi, CharSet = CharSet.Unicode)]
internal static extern int ClusterRegSetValue(
[In] SafeHKey hKey,
[In, MarshalAs(UnmanagedType.LPWStr)] string lpszValueName,
[In] RegistryValueKind lpdwValueType,
[In, MarshalAs(UnmanagedType.LPArray)] byte[] lpbData,
[In] uint lpcbData);
[DllImport(ClusApi, CharSet = CharSet.Unicode)]
internal static extern int ClusterRegGetKeySecurity(
[In] SafeHKey hKey,
[In] SecurityInfos securityInformation,
[In, Out] byte[] securityDescriptor,
[In, Out] ref uint lpcbSecurityDescriptor);
[DllImport(ClusApi, CharSet = CharSet.Unicode)]
internal static extern int ClusterRegSetKeySecurity(
[In] SafeHKey hKey,
[In] SecurityInfos securityInformation,
[In] byte[] securityDescriptor);
}
}
// 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
- DataTemplate.cs
- FacetValueContainer.cs
- RequestTimeoutManager.cs
- TreeNodeBindingCollection.cs
- LeaseManager.cs
- EmbeddedMailObjectsCollection.cs
- TextBoxAutoCompleteSourceConverter.cs
- SortAction.cs
- EditCommandColumn.cs
- WebEventCodes.cs
- LayoutManager.cs
- StatusBar.cs
- CookieHandler.cs
- HtmlInputText.cs
- SafeLibraryHandle.cs
- CachingHintValidation.cs
- OptimalBreakSession.cs
- ColumnClickEvent.cs
- _BaseOverlappedAsyncResult.cs
- HwndSourceParameters.cs
- OutOfMemoryException.cs
- TypeViewSchema.cs
- TimeSpanConverter.cs
- ResourceIDHelper.cs
- __Filters.cs
- DefaultAssemblyResolver.cs
- DataGridItemCollection.cs
- ColumnBinding.cs
- EnterpriseServicesHelper.cs
- XsdDataContractExporter.cs
- ContentControl.cs
- DependencyPropertyHelper.cs
- DataReceivedEventArgs.cs
- ListComponentEditorPage.cs
- DataError.cs
- Point3DAnimationUsingKeyFrames.cs
- PeerNameResolver.cs
- ObjectHandle.cs
- PassportPrincipal.cs
- SortDescription.cs
- DbParameterHelper.cs
- CodeConstructor.cs
- FrameDimension.cs
- SynchronizedDispatch.cs
- CacheOutputQuery.cs
- MarshalDirectiveException.cs
- DocumentOrderQuery.cs
- ProfileModule.cs
- PartialTrustHelpers.cs
- ConfigXmlReader.cs
- RichTextBox.cs
- XmlQualifiedNameTest.cs
- RemotingServices.cs
- ContextMenuService.cs
- SqlCommandSet.cs
- XmlCodeExporter.cs
- TrustManagerMoreInformation.cs
- SymmetricKeyWrap.cs
- AppDomain.cs
- XPathSingletonIterator.cs
- hwndwrapper.cs
- basemetadatamappingvisitor.cs
- ConstantCheck.cs
- SimpleHandlerBuildProvider.cs
- InputGestureCollection.cs
- XslNumber.cs
- EventSinkHelperWriter.cs
- CannotUnloadAppDomainException.cs
- __FastResourceComparer.cs
- DataRecordInternal.cs
- SapiGrammar.cs
- SchemaEntity.cs
- SqlProvider.cs
- ColorConverter.cs
- SignatureDescription.cs
- SettingsPropertyIsReadOnlyException.cs
- Convert.cs
- XslAstAnalyzer.cs
- Math.cs
- ColorConvertedBitmap.cs
- WsdlWriter.cs
- LiteralText.cs
- WindowClosedEventArgs.cs
- ScrollBarRenderer.cs
- RequestCachingSection.cs
- AmbiguousMatchException.cs
- EmbossBitmapEffect.cs
- CorrelationService.cs
- ComplexType.cs
- ContainsRowNumberChecker.cs
- ValueTable.cs
- AppDomainManager.cs
- InfoCardConstants.cs
- CodeGen.cs
- PersonalizationProvider.cs
- TableItemPattern.cs
- NonVisualControlAttribute.cs
- CoreSwitches.cs
- ActionItem.cs
- NotCondition.cs