Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Base / MS / Internal / interop / NativeStructs.cs / 1471291 / NativeStructs.cs
/**************************************************************************\ Copyright Microsoft Corporation. All Rights Reserved. \**************************************************************************/ // // A consolidated file of native structures exposed for interop. // These may be structs or classes, depending on the calling requirements // // The naming should generally match the native counterparts. // The structures may be slightly thicker wrappers to make them // easier to consume correctly from .Net code (e.g. hiding resource management) // namespace MS.Internal.Interop { using System; using System.IO; using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; using System.Security; // Some COM interfaces and Win32 structures are already declared in the framework. // Interesting ones to remember in System.Runtime.InteropServices.ComTypes are: using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME; using IPersistFile = System.Runtime.InteropServices.ComTypes.IPersistFile; using IStream = System.Runtime.InteropServices.ComTypes.IStream; ////// This class is not safe to use in partial trust. /// Critical: This class is a wrapper for a native structure that manages its own resources. /// [SecurityCritical] [StructLayout(LayoutKind.Explicit)] internal class PROPVARIANT : IDisposable { private static class NativeMethods { ////// Critical: Suppresses unmanaged code security. /// [SecurityCritical, SuppressUnmanagedCodeSecurity] [DllImport(MS.Win32.ExternDll.Ole32)] internal static extern int PropVariantClear(PROPVARIANT pvar); } [FieldOffset(0)] private ushort vt; [FieldOffset(8)] private IntPtr pointerVal; [FieldOffset(8)] private byte byteVal; [FieldOffset(8)] private long longVal; [FieldOffset(8)] private short boolVal; ////// /// Critical: This class is tagged Critical /// TreatAsSafe - This class is only available in full trust. /// public VarEnum VarType { [SecurityCritical, SecurityTreatAsSafe] get { return (VarEnum)vt; } } // Right now only using this for strings. If for some reason we get something else return null. ////// Critical: This class is tagged Critical /// TreatAsSafe - This class is only available in full trust. /// [SecurityCritical, SecurityTreatAsSafe] public string GetValue() { if (vt == (ushort)VarEnum.VT_LPWSTR) { return Marshal.PtrToStringUni(pointerVal); } return null; } ////// Critical: This class is tagged Critical /// TreatAsSafe - This class is only available in full trust. /// [SecurityCritical, SecurityTreatAsSafe] public void SetValue(bool f) { Clear(); vt = (ushort)VarEnum.VT_BOOL; boolVal = (short)(f ? -1 : 0); } ////// Critical: This class is tagged Critical /// TreatAsSafe - This class is only available in full trust. /// [SecurityCritical, SecurityTreatAsSafe] public void SetValue(string val) { Clear(); vt = (ushort)VarEnum.VT_LPWSTR; pointerVal = Marshal.StringToCoTaskMemUni(val); } ////// Critical - Calls critical PropVariantClear /// TreatAsSafe - This class is only available in full trust. /// [SecurityCritical, SecurityTreatAsSafe] public void Clear() { NativeMethods.PropVariantClear(this); } #region IDisposable Pattern ////// Critical: This class is tagged Critical /// TreatAsSafe - This class is only available in full trust. /// [SecurityCritical, SecurityTreatAsSafe] public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } ////// Critical: This class is tagged Critical /// TreatAsSafe - This class is only available in full trust. /// [SecurityCritical, SecurityTreatAsSafe] ~PROPVARIANT() { Dispose(false); } ////// Critical: This class is tagged Critical /// TreatAsSafe - This class is only available in full trust. /// [SecurityCritical, SecurityTreatAsSafe] private void Dispose(bool disposing) { Clear(); } #endregion } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] [BestFitMapping(false)] internal class WIN32_FIND_DATAW { public FileAttributes dwFileAttributes; public FILETIME ftCreationTime; public FILETIME ftLastAccessTime; public FILETIME ftLastWriteTime; public int nFileSizeHigh; public int nFileSizeLow; public int dwReserved0; public int dwReserved1; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] public string cFileName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)] public string cAlternateFileName; } // New to Win7. [StructLayout(LayoutKind.Sequential)] internal struct CHANGEFILTERSTRUCT { public uint cbSize; public MSGFLTINFO ExtStatus; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. /**************************************************************************\ Copyright Microsoft Corporation. All Rights Reserved. \**************************************************************************/ // // A consolidated file of native structures exposed for interop. // These may be structs or classes, depending on the calling requirements // // The naming should generally match the native counterparts. // The structures may be slightly thicker wrappers to make them // easier to consume correctly from .Net code (e.g. hiding resource management) // namespace MS.Internal.Interop { using System; using System.IO; using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; using System.Security; // Some COM interfaces and Win32 structures are already declared in the framework. // Interesting ones to remember in System.Runtime.InteropServices.ComTypes are: using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME; using IPersistFile = System.Runtime.InteropServices.ComTypes.IPersistFile; using IStream = System.Runtime.InteropServices.ComTypes.IStream; ////// This class is not safe to use in partial trust. /// Critical: This class is a wrapper for a native structure that manages its own resources. /// [SecurityCritical] [StructLayout(LayoutKind.Explicit)] internal class PROPVARIANT : IDisposable { private static class NativeMethods { ////// Critical: Suppresses unmanaged code security. /// [SecurityCritical, SuppressUnmanagedCodeSecurity] [DllImport(MS.Win32.ExternDll.Ole32)] internal static extern int PropVariantClear(PROPVARIANT pvar); } [FieldOffset(0)] private ushort vt; [FieldOffset(8)] private IntPtr pointerVal; [FieldOffset(8)] private byte byteVal; [FieldOffset(8)] private long longVal; [FieldOffset(8)] private short boolVal; ////// /// Critical: This class is tagged Critical /// TreatAsSafe - This class is only available in full trust. /// public VarEnum VarType { [SecurityCritical, SecurityTreatAsSafe] get { return (VarEnum)vt; } } // Right now only using this for strings. If for some reason we get something else return null. ////// Critical: This class is tagged Critical /// TreatAsSafe - This class is only available in full trust. /// [SecurityCritical, SecurityTreatAsSafe] public string GetValue() { if (vt == (ushort)VarEnum.VT_LPWSTR) { return Marshal.PtrToStringUni(pointerVal); } return null; } ////// Critical: This class is tagged Critical /// TreatAsSafe - This class is only available in full trust. /// [SecurityCritical, SecurityTreatAsSafe] public void SetValue(bool f) { Clear(); vt = (ushort)VarEnum.VT_BOOL; boolVal = (short)(f ? -1 : 0); } ////// Critical: This class is tagged Critical /// TreatAsSafe - This class is only available in full trust. /// [SecurityCritical, SecurityTreatAsSafe] public void SetValue(string val) { Clear(); vt = (ushort)VarEnum.VT_LPWSTR; pointerVal = Marshal.StringToCoTaskMemUni(val); } ////// Critical - Calls critical PropVariantClear /// TreatAsSafe - This class is only available in full trust. /// [SecurityCritical, SecurityTreatAsSafe] public void Clear() { NativeMethods.PropVariantClear(this); } #region IDisposable Pattern ////// Critical: This class is tagged Critical /// TreatAsSafe - This class is only available in full trust. /// [SecurityCritical, SecurityTreatAsSafe] public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } ////// Critical: This class is tagged Critical /// TreatAsSafe - This class is only available in full trust. /// [SecurityCritical, SecurityTreatAsSafe] ~PROPVARIANT() { Dispose(false); } ////// Critical: This class is tagged Critical /// TreatAsSafe - This class is only available in full trust. /// [SecurityCritical, SecurityTreatAsSafe] private void Dispose(bool disposing) { Clear(); } #endregion } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] [BestFitMapping(false)] internal class WIN32_FIND_DATAW { public FileAttributes dwFileAttributes; public FILETIME ftCreationTime; public FILETIME ftLastAccessTime; public FILETIME ftLastWriteTime; public int nFileSizeHigh; public int nFileSizeLow; public int dwReserved0; public int dwReserved1; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] public string cFileName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)] public string cAlternateFileName; } // New to Win7. [StructLayout(LayoutKind.Sequential)] internal struct CHANGEFILTERSTRUCT { public uint cbSize; public MSGFLTINFO ExtStatus; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- UIPermission.cs
- WebPartTransformerAttribute.cs
- AppDomainAttributes.cs
- Matrix.cs
- SymmetricAlgorithm.cs
- BinaryObjectInfo.cs
- VectorCollectionConverter.cs
- ApplicationFileCodeDomTreeGenerator.cs
- NonSerializedAttribute.cs
- UIHelper.cs
- BinaryObjectWriter.cs
- XsdBuildProvider.cs
- MultilineStringConverter.cs
- StylusCaptureWithinProperty.cs
- RepeatInfo.cs
- BufferedStream.cs
- DesignerRegion.cs
- EncoderReplacementFallback.cs
- TimeSpanParse.cs
- RSAPKCS1KeyExchangeFormatter.cs
- BamlLocalizabilityResolver.cs
- XmlDataSourceNodeDescriptor.cs
- HotCommands.cs
- BitConverter.cs
- AlignmentYValidation.cs
- ApplyTemplatesAction.cs
- Range.cs
- ObjectDataSourceStatusEventArgs.cs
- ByteAnimationUsingKeyFrames.cs
- SqlDependencyUtils.cs
- PointCollection.cs
- UriTemplateVariablePathSegment.cs
- LongTypeConverter.cs
- MobileControlPersister.cs
- TextRenderer.cs
- MarshalByRefObject.cs
- BindingRestrictions.cs
- ClientBuildManagerCallback.cs
- MultipleViewPattern.cs
- DesignerHelpers.cs
- xsdvalidator.cs
- SizeChangedInfo.cs
- AppSecurityManager.cs
- PassportIdentity.cs
- XPathDocumentNavigator.cs
- Number.cs
- FormatControl.cs
- CompiledIdentityConstraint.cs
- BrushConverter.cs
- CapabilitiesAssignment.cs
- FirstQueryOperator.cs
- WebBrowserBase.cs
- ButtonChrome.cs
- Point4D.cs
- ResXBuildProvider.cs
- XmlChildNodes.cs
- PolyQuadraticBezierSegmentFigureLogic.cs
- ToolbarAUtomationPeer.cs
- SqlMetaData.cs
- StatusBarDrawItemEvent.cs
- ChooseAction.cs
- TcpTransportSecurityElement.cs
- SQLInt16Storage.cs
- TimelineGroup.cs
- BooleanFunctions.cs
- ParameterModifier.cs
- Native.cs
- DocumentApplication.cs
- WorkflowTransactionOptions.cs
- BinaryObjectInfo.cs
- BaseCAMarshaler.cs
- XMLSchema.cs
- CommandSet.cs
- UserControlBuildProvider.cs
- ImageMapEventArgs.cs
- TemplateComponentConnector.cs
- SchemaCompiler.cs
- FrameAutomationPeer.cs
- SafeCryptContextHandle.cs
- DescendantQuery.cs
- RegexCompiler.cs
- XmlSchemaRedefine.cs
- SortDescriptionCollection.cs
- FamilyTypefaceCollection.cs
- CompiledQueryCacheKey.cs
- __FastResourceComparer.cs
- DesignerTransaction.cs
- SQLBytesStorage.cs
- MinMaxParagraphWidth.cs
- EventHandlerList.cs
- ConfigurationFileMap.cs
- OracleFactory.cs
- Literal.cs
- TextServicesCompartmentEventSink.cs
- Set.cs
- _AutoWebProxyScriptWrapper.cs
- SelectionEditor.cs
- HyperlinkAutomationPeer.cs
- RelationshipWrapper.cs
- PlainXmlDeserializer.cs