Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / clr / src / BCL / Microsoft / Win32 / FusionWrap.cs / 1 / FusionWrap.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== //-------------------------------------------------------------- // FusionInterfaces.cs // // This implements wrappers to Fusion interfaces //------------------------------------------------------------- namespace Microsoft.Win32 { using System; using System.IO; using System.Collections; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Globalization; using StringBuilder = System.Text.StringBuilder; #if !FEATURE_COMINTEROP using Microsoft.Win32.SafeHandles; #endif // !FEATURE_COMINTEROP #if FEATURE_COMINTEROP //------------------------------------------------------------- // Interfaces defined by fusion //------------------------------------------------------------- [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("21b8916c-f28e-11d2-a473-00c04f8ef448")] interface IAssemblyEnum { [PreserveSig()] int GetNextAssembly(out IApplicationContext ppAppCtx, out IAssemblyName ppName, uint dwFlags); [PreserveSig()] int Reset(); [PreserveSig()] int Clone(out IAssemblyEnum ppEnum); } [ComImport,InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("7c23ff90-33af-11d3-95da-00a024a85b51")] interface IApplicationContext { void SetContextNameObject(IAssemblyName pName); void GetContextNameObject(out IAssemblyName ppName); void Set([MarshalAs(UnmanagedType.LPWStr)] String szName, int pvValue, uint cbValue, uint dwFlags); void Get([MarshalAs(UnmanagedType.LPWStr)] String szName, out int pvValue, ref uint pcbValue, uint dwFlags); void GetDynamicDirectory(out int wzDynamicDir, ref uint pdwSize); } [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("CD193BC0-B4BC-11d2-9833-00C04FC31D2E")] interface IAssemblyName { [PreserveSig()] int SetProperty(uint PropertyId, IntPtr pvProperty, uint cbProperty); [PreserveSig()] int GetProperty(uint PropertyId, IntPtr pvProperty, ref uint pcbProperty); [PreserveSig()] int Finalize(); [PreserveSig()] int GetDisplayName(IntPtr szDisplayName, ref uint pccDisplayName, uint dwDisplayFlags); [PreserveSig()] int BindToObject(Object /*REFIID*/ refIID, Object /*IAssemblyBindSink*/ pAsmBindSink, IApplicationContext pApplicationContext, [MarshalAs(UnmanagedType.LPWStr)] String szCodeBase, Int64 llFlags, int pvReserved, uint cbReserved, out int ppv); [PreserveSig()] int GetName(out uint lpcwBuffer, out int pwzName); [PreserveSig()] int GetVersion(out uint pdwVersionHi, out uint pdwVersionLow); [PreserveSig()] int IsEqual(IAssemblyName pName, uint dwCmpFlags); [PreserveSig()] int Clone(out IAssemblyName pName); } #endif // FEATURE_COMINTEROP internal static class ASM_CACHE { public const uint ZAP = 0x1; public const uint GAC = 0x2; public const uint DOWNLOAD = 0x4; } internal static class CANOF { public const uint PARSE_DISPLAY_NAME = 0x1; public const uint SET_DEFAULT_VALUES = 0x2; } internal static class ASM_NAME { public const uint PUBLIC_KEY = 0; public const uint PUBLIC_KEY_TOKEN = PUBLIC_KEY + 1; public const uint HASH_VALUE = PUBLIC_KEY_TOKEN + 1; public const uint NAME = HASH_VALUE + 1; public const uint MAJOR_VERSION = NAME + 1; public const uint MINOR_VERSION = MAJOR_VERSION + 1; public const uint BUILD_NUMBER = MINOR_VERSION + 1; public const uint REVISION_NUMBER = BUILD_NUMBER + 1; public const uint CULTURE = REVISION_NUMBER + 1; public const uint PROCESSOR_ID_ARRAY = CULTURE + 1; public const uint OSINFO_ARRAY = PROCESSOR_ID_ARRAY + 1; public const uint HASH_ALGID = OSINFO_ARRAY + 1; public const uint ALIAS = HASH_ALGID + 1; public const uint CODEBASE_URL = ALIAS + 1; public const uint CODEBASE_LASTMOD = CODEBASE_URL + 1; public const uint NULL_PUBLIC_KEY = CODEBASE_LASTMOD + 1; public const uint NULL_PUBLIC_KEY_TOKEN = NULL_PUBLIC_KEY + 1; public const uint CUSTOM = NULL_PUBLIC_KEY_TOKEN + 1; public const uint NULL_CUSTOM = CUSTOM + 1; public const uint MVID = NULL_CUSTOM + 1; public const uint _32_BIT_ONLY = MVID + 1; public const uint MAX_PARAMS = _32_BIT_ONLY + 1; } internal static class Fusion { public static void ReadCache(ArrayList alAssems, String name, uint nFlag) { #if FEATURE_COMINTEROP IAssemblyEnum aEnum = null; IAssemblyName aName = null; IAssemblyName aNameEnum = null; IApplicationContext AppCtx = null; #else // FEATURE_COMINTEROP SafeFusionHandle aEnum = null; SafeFusionHandle aNameEnum = null; SafeFusionHandle AppCtx = SafeFusionHandle.InvalidHandle; #endif // FEATURE_COMINTEROP int hr; if (name != null) { hr = Win32Native.CreateAssemblyNameObject(out aNameEnum, name, CANOF.PARSE_DISPLAY_NAME, IntPtr.Zero); if (hr != 0) Marshal.ThrowExceptionForHR(hr); } #if !FEATURE_COMINTEROP using (aNameEnum) { #endif // !FEATURE_COMINTEROP hr = Win32Native.CreateAssemblyEnum(out aEnum, AppCtx, aNameEnum, nFlag, IntPtr.Zero); if (hr != 0) Marshal.ThrowExceptionForHR(hr); #if FEATURE_COMINTEROP for (;;) { hr = aEnum.GetNextAssembly(out AppCtx, out aName, 0); if (hr != 0) { if (hr < 0) Marshal.ThrowExceptionForHR(hr); break; } #else // FEATURE_COMINTEROP using (aEnum) { for (;;) using (SafeFusionHandle aAppCtx = new SafeFusionHandle(), aName = new SafeFusionHandle()) { if (!GetNextAssembly(aEnum, aAppCtx, aName, 0)) break; #endif // FEATURE_COMINTEROP String sDisplayName = GetDisplayName(aName, 0); if (sDisplayName == null) continue; alAssems.Add(sDisplayName); } #if !FEATURE_COMINTEROP } // using (aEnum) } // using (aNameEnum) #endif // !FEATURE_COMINTEROP } #if FEATURE_COMINTEROP static unsafe String GetDisplayName(IAssemblyName aName, uint dwDisplayFlags) { uint iLen=0; String sDisplayName = null; aName.GetDisplayName((IntPtr)0, ref iLen, dwDisplayFlags); if (iLen > 0) { IntPtr pDisplayName=(IntPtr)0; // Do some yucky memory allocating here // We need to assume that a wide character is 2 bytes. byte[] data = new byte[((int)iLen+1)*2]; fixed (byte *dataptr = data) { pDisplayName = new IntPtr((void *) dataptr); aName.GetDisplayName(pDisplayName, ref iLen, dwDisplayFlags); sDisplayName = Marshal.PtrToStringUni(pDisplayName); } } return sDisplayName; } #else // FEATURE_COMINTEROP [MethodImplAttribute(MethodImplOptions.InternalCall)] static extern bool GetNextAssembly(SafeFusionHandle pEnum, SafeFusionHandle pAppCtx, SafeFusionHandle pName, uint dwFlags); [MethodImplAttribute(MethodImplOptions.InternalCall)] static extern String GetDisplayName(SafeFusionHandle pName, uint dwDisplayFlags); #endif // FEATURE_COMINTEROP } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== //-------------------------------------------------------------- // FusionInterfaces.cs // // This implements wrappers to Fusion interfaces //------------------------------------------------------------- namespace Microsoft.Win32 { using System; using System.IO; using System.Collections; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Globalization; using StringBuilder = System.Text.StringBuilder; #if !FEATURE_COMINTEROP using Microsoft.Win32.SafeHandles; #endif // !FEATURE_COMINTEROP #if FEATURE_COMINTEROP //------------------------------------------------------------- // Interfaces defined by fusion //------------------------------------------------------------- [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("21b8916c-f28e-11d2-a473-00c04f8ef448")] interface IAssemblyEnum { [PreserveSig()] int GetNextAssembly(out IApplicationContext ppAppCtx, out IAssemblyName ppName, uint dwFlags); [PreserveSig()] int Reset(); [PreserveSig()] int Clone(out IAssemblyEnum ppEnum); } [ComImport,InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("7c23ff90-33af-11d3-95da-00a024a85b51")] interface IApplicationContext { void SetContextNameObject(IAssemblyName pName); void GetContextNameObject(out IAssemblyName ppName); void Set([MarshalAs(UnmanagedType.LPWStr)] String szName, int pvValue, uint cbValue, uint dwFlags); void Get([MarshalAs(UnmanagedType.LPWStr)] String szName, out int pvValue, ref uint pcbValue, uint dwFlags); void GetDynamicDirectory(out int wzDynamicDir, ref uint pdwSize); } [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("CD193BC0-B4BC-11d2-9833-00C04FC31D2E")] interface IAssemblyName { [PreserveSig()] int SetProperty(uint PropertyId, IntPtr pvProperty, uint cbProperty); [PreserveSig()] int GetProperty(uint PropertyId, IntPtr pvProperty, ref uint pcbProperty); [PreserveSig()] int Finalize(); [PreserveSig()] int GetDisplayName(IntPtr szDisplayName, ref uint pccDisplayName, uint dwDisplayFlags); [PreserveSig()] int BindToObject(Object /*REFIID*/ refIID, Object /*IAssemblyBindSink*/ pAsmBindSink, IApplicationContext pApplicationContext, [MarshalAs(UnmanagedType.LPWStr)] String szCodeBase, Int64 llFlags, int pvReserved, uint cbReserved, out int ppv); [PreserveSig()] int GetName(out uint lpcwBuffer, out int pwzName); [PreserveSig()] int GetVersion(out uint pdwVersionHi, out uint pdwVersionLow); [PreserveSig()] int IsEqual(IAssemblyName pName, uint dwCmpFlags); [PreserveSig()] int Clone(out IAssemblyName pName); } #endif // FEATURE_COMINTEROP internal static class ASM_CACHE { public const uint ZAP = 0x1; public const uint GAC = 0x2; public const uint DOWNLOAD = 0x4; } internal static class CANOF { public const uint PARSE_DISPLAY_NAME = 0x1; public const uint SET_DEFAULT_VALUES = 0x2; } internal static class ASM_NAME { public const uint PUBLIC_KEY = 0; public const uint PUBLIC_KEY_TOKEN = PUBLIC_KEY + 1; public const uint HASH_VALUE = PUBLIC_KEY_TOKEN + 1; public const uint NAME = HASH_VALUE + 1; public const uint MAJOR_VERSION = NAME + 1; public const uint MINOR_VERSION = MAJOR_VERSION + 1; public const uint BUILD_NUMBER = MINOR_VERSION + 1; public const uint REVISION_NUMBER = BUILD_NUMBER + 1; public const uint CULTURE = REVISION_NUMBER + 1; public const uint PROCESSOR_ID_ARRAY = CULTURE + 1; public const uint OSINFO_ARRAY = PROCESSOR_ID_ARRAY + 1; public const uint HASH_ALGID = OSINFO_ARRAY + 1; public const uint ALIAS = HASH_ALGID + 1; public const uint CODEBASE_URL = ALIAS + 1; public const uint CODEBASE_LASTMOD = CODEBASE_URL + 1; public const uint NULL_PUBLIC_KEY = CODEBASE_LASTMOD + 1; public const uint NULL_PUBLIC_KEY_TOKEN = NULL_PUBLIC_KEY + 1; public const uint CUSTOM = NULL_PUBLIC_KEY_TOKEN + 1; public const uint NULL_CUSTOM = CUSTOM + 1; public const uint MVID = NULL_CUSTOM + 1; public const uint _32_BIT_ONLY = MVID + 1; public const uint MAX_PARAMS = _32_BIT_ONLY + 1; } internal static class Fusion { public static void ReadCache(ArrayList alAssems, String name, uint nFlag) { #if FEATURE_COMINTEROP IAssemblyEnum aEnum = null; IAssemblyName aName = null; IAssemblyName aNameEnum = null; IApplicationContext AppCtx = null; #else // FEATURE_COMINTEROP SafeFusionHandle aEnum = null; SafeFusionHandle aNameEnum = null; SafeFusionHandle AppCtx = SafeFusionHandle.InvalidHandle; #endif // FEATURE_COMINTEROP int hr; if (name != null) { hr = Win32Native.CreateAssemblyNameObject(out aNameEnum, name, CANOF.PARSE_DISPLAY_NAME, IntPtr.Zero); if (hr != 0) Marshal.ThrowExceptionForHR(hr); } #if !FEATURE_COMINTEROP using (aNameEnum) { #endif // !FEATURE_COMINTEROP hr = Win32Native.CreateAssemblyEnum(out aEnum, AppCtx, aNameEnum, nFlag, IntPtr.Zero); if (hr != 0) Marshal.ThrowExceptionForHR(hr); #if FEATURE_COMINTEROP for (;;) { hr = aEnum.GetNextAssembly(out AppCtx, out aName, 0); if (hr != 0) { if (hr < 0) Marshal.ThrowExceptionForHR(hr); break; } #else // FEATURE_COMINTEROP using (aEnum) { for (;;) using (SafeFusionHandle aAppCtx = new SafeFusionHandle(), aName = new SafeFusionHandle()) { if (!GetNextAssembly(aEnum, aAppCtx, aName, 0)) break; #endif // FEATURE_COMINTEROP String sDisplayName = GetDisplayName(aName, 0); if (sDisplayName == null) continue; alAssems.Add(sDisplayName); } #if !FEATURE_COMINTEROP } // using (aEnum) } // using (aNameEnum) #endif // !FEATURE_COMINTEROP } #if FEATURE_COMINTEROP static unsafe String GetDisplayName(IAssemblyName aName, uint dwDisplayFlags) { uint iLen=0; String sDisplayName = null; aName.GetDisplayName((IntPtr)0, ref iLen, dwDisplayFlags); if (iLen > 0) { IntPtr pDisplayName=(IntPtr)0; // Do some yucky memory allocating here // We need to assume that a wide character is 2 bytes. byte[] data = new byte[((int)iLen+1)*2]; fixed (byte *dataptr = data) { pDisplayName = new IntPtr((void *) dataptr); aName.GetDisplayName(pDisplayName, ref iLen, dwDisplayFlags); sDisplayName = Marshal.PtrToStringUni(pDisplayName); } } return sDisplayName; } #else // FEATURE_COMINTEROP [MethodImplAttribute(MethodImplOptions.InternalCall)] static extern bool GetNextAssembly(SafeFusionHandle pEnum, SafeFusionHandle pAppCtx, SafeFusionHandle pName, uint dwFlags); [MethodImplAttribute(MethodImplOptions.InternalCall)] static extern String GetDisplayName(SafeFusionHandle pName, uint dwDisplayFlags); #endif // FEATURE_COMINTEROP } } // 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
- RevocationPoint.cs
- COM2TypeInfoProcessor.cs
- CanonicalXml.cs
- DoubleSumAggregationOperator.cs
- IncomingWebResponseContext.cs
- XAMLParseException.cs
- BinaryQueryOperator.cs
- DateTimeFormatInfo.cs
- XmlQualifiedNameTest.cs
- RelationshipSet.cs
- TrackingMemoryStream.cs
- SpeakProgressEventArgs.cs
- DeobfuscatingStream.cs
- FormViewInsertedEventArgs.cs
- CompositeControl.cs
- ParallelTimeline.cs
- ActivityValidator.cs
- EncodingDataItem.cs
- ImageListUtils.cs
- ConfigurationProviderException.cs
- URLIdentityPermission.cs
- FrameworkContentElement.cs
- ManagementExtension.cs
- GAC.cs
- ViewLoader.cs
- MessageEncodingBindingElement.cs
- MetadataPropertyvalue.cs
- InternalBase.cs
- CryptoKeySecurity.cs
- QueryResponse.cs
- TracedNativeMethods.cs
- IgnoreFileBuildProvider.cs
- LinkDescriptor.cs
- ListenerTraceUtility.cs
- MDIWindowDialog.cs
- xamlnodes.cs
- MappingException.cs
- EventMappingSettingsCollection.cs
- ListBindingHelper.cs
- RuntimeArgumentHandle.cs
- InstanceDataCollection.cs
- AppDomainInfo.cs
- FieldDescriptor.cs
- Line.cs
- ComPlusTraceRecord.cs
- ConfigurationStrings.cs
- IPEndPoint.cs
- ObjectDataSourceView.cs
- CompensatableTransactionScopeActivity.cs
- KnownTypesHelper.cs
- CallContext.cs
- _LoggingObject.cs
- WebPartCatalogAddVerb.cs
- HttpContext.cs
- TextDpi.cs
- ReceiveDesigner.xaml.cs
- DbConnectionClosed.cs
- FormViewModeEventArgs.cs
- MouseEventArgs.cs
- UniformGrid.cs
- MultiSelector.cs
- IMembershipProvider.cs
- DetailsViewUpdatedEventArgs.cs
- DataGridViewRowHeightInfoPushedEventArgs.cs
- AmbiguousMatchException.cs
- StoreItemCollection.Loader.cs
- FocusWithinProperty.cs
- OperandQuery.cs
- DateTimeFormatInfoScanner.cs
- ScriptingAuthenticationServiceSection.cs
- X509ChainPolicy.cs
- PostBackOptions.cs
- RegexCharClass.cs
- SqlProcedureAttribute.cs
- MissingMethodException.cs
- OneOfElement.cs
- UnsafeNativeMethods.cs
- MappingException.cs
- StateDesigner.LayoutSelectionGlyph.cs
- AnnotationHelper.cs
- FormatterServicesNoSerializableCheck.cs
- RemotingException.cs
- SequenceNumber.cs
- SHA1.cs
- CancellationTokenRegistration.cs
- IPEndPoint.cs
- ValueUtilsSmi.cs
- XmlBoundElement.cs
- Point4DConverter.cs
- Schema.cs
- ControlPaint.cs
- EventData.cs
- BuildProvider.cs
- NotSupportedException.cs
- UInt64Converter.cs
- XmlRawWriter.cs
- Error.cs
- MDIControlStrip.cs
- StateDesigner.CommentLayoutGlyph.cs
- Condition.cs