Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Shared / MS / Win32 / SafeNativeMethodsOther.cs / 1305600 / SafeNativeMethodsOther.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace MS.Win32 { using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; using System; using System.Security; using System.Security.Permissions; using System.Collections; using System.IO; using System.Text; using System.ComponentModel; using System.Diagnostics; using IComDataObject = System.Runtime.InteropServices.ComTypes.IDataObject; #if WINDOWS_BASE using MS.Internal.WindowsBase; #elif PRESENTATION_CORE using MS.Internal.PresentationCore; #elif PRESENTATIONFRAMEWORK using MS.Internal.PresentationFramework; #elif DRT using MS.Internal.Drt; #else #error Attempt to use FriendAccessAllowedAttribute from an unknown assembly. using MS.Internal.YourAssemblyName; #endif //// Critical - This entire class is critical as it has SuppressUnmanagedCodeSecurity. // TreatAsSafe - These Native methods have been reviewed as safe to call. // // The attributes are commented out here because this is a partial class and the attributes are already // applied in SafeNativeMethodsCLR.cs // //[SecurityCritical, SecurityTreatAsSafe] //[SuppressUnmanagedCodeSecurity] [FriendAccessAllowed] internal partial class SafeNativeMethods { ////////////////////////////// // from Framework [Flags] internal enum PlaySoundFlags { SND_[....] = 0x00000000, /* play synchronously (default) */ SND_ASYNC = 0x00000001, /* play asynchronously */ SND_NODEFAULT = 0x00000002, /* silence (!default) if sound not found */ SND_MEMORY = 0x00000004, /* pszSound points to a memory file */ SND_LOOP = 0x00000008, /* loop the sound until next sndPlaySound */ SND_NOSTOP = 0x00000010, /* don't stop any currently playing sound */ SND_PURGE = 0x00000040, /* purge non-static events for task */ SND_APPLICATION = 0x00000080, /* look for application specific association */ SND_NOWAIT = 0x00002000, /* don't wait if the driver is busy */ SND_ALIAS = 0x00010000, /* name is a registry alias */ SND_FILENAME = 0x00020000, /* name is file name */ SND_RESOURCE = 0x00040000, /* name is resource name or atom */ } ////// Critical: This code elevates to unmanaged code permission /// TreatAsSafe: This function is safe to call /// [SecurityCritical,SecurityTreatAsSafe] internal static bool InSendMessage() { return SafeNativeMethodsPrivate.InSendMessage(); } #if never ////// Critical: This code elevates to unmanaged code permission /// TreatAsSafe: This function is safe to call /// [SecurityCritical,SecurityTreatAsSafe] public static int GetQueueStatus(uint flags) { return SafeNativeMethodsPrivate.GetQueueStatus(flags); } ////// Critical: This code elevates to unmanaged code permission /// TreatAsSafe: This function is safe to call /// [SecurityCritical,SecurityTreatAsSafe] internal static int GetInputState() { return SafeNativeMethodsPrivate.GetInputState(); } #endif ////// Critical: This code elevates to unmanaged code permission /// TreatAsafe: This function is safe to call /// [SecurityCritical,SecurityTreatAsSafe] public static bool IsUxThemeActive() { return SafeNativeMethodsPrivate.IsThemeActive() != 0; } ////// Critical: This code elevates to unmanaged code permission /// TreatAsSafe: This function is safe to call /// [SecurityCritical,SecurityTreatAsSafe] public static bool SetCaretPos(int x, int y) { // To be consistent with our other PInvoke wrappers // we should "throw" a Win32Exception on error here. // But we don't want to introduce new "throws" w/o // time to follow up on any new problems that causes. return SafeNativeMethodsPrivate.SetCaretPos(x,y); } ////// Critical: This code elevates to unmanaged code permission /// TreatAsSafe: This function is safe to call /// [SecurityCritical,SecurityTreatAsSafe] public static bool DestroyCaret() { // To be consistent with our other PInvoke wrappers // we should "throw" a Win32Exception on error here. // But we don't want to introduce new "throws" w/o // time to follow up on any new problems that causes. return SafeNativeMethodsPrivate.DestroyCaret(); } // NOTE: CLR has this in UnsafeNativeMethodsCLR.cs. Not sure why it is unsafe - need to follow up. ////// Critical: This code elevates to unmanaged code permission /// TreatAsSafe: This function is safe to call /// [SecurityCritical,SecurityTreatAsSafe] public static int GetCaretBlinkTime() { // To be consistent with our other PInvoke wrappers // we should "throw" a Win32Exception on error here. // But we don't want to introduce new "throws" w/o // time to follow up on any new problems that causes. return SafeNativeMethodsPrivate.GetCaretBlinkTime(); } // Constants for GetStringTypeEx. public const uint CT_CTYPE1 = 1; public const uint CT_CTYPE2 = 2; public const uint CT_CTYPE3 = 4; public const UInt16 C1_SPACE = 0x0008; public const UInt16 C1_PUNCT = 0x0010; public const UInt16 C1_BLANK = 0x0040; public const UInt16 C3_NONSPACING = 0x0001; public const UInt16 C3_DIACRITIC = 0x0002; public const UInt16 C3_VOWELMARK = 0x0004; public const UInt16 C3_KATAKANA = 0x0010; public const UInt16 C3_HIRAGANA = 0x0020; public const UInt16 C3_HALFWIDTH = 0x0040; public const UInt16 C3_FULLWIDTH = 0x0080; public const UInt16 C3_IDEOGRAPH = 0x0100; public const UInt16 C3_KASHIDA = 0x0200; ////// Critical: This code elevates to unmanaged code permission /// TreatAsSafe: This function is safe to call /// [SecurityCritical, SecurityTreatAsSafe] public static bool GetStringTypeEx(uint locale, uint infoType, char[] sourceString, int count, UInt16[] charTypes) { bool win32Return = SafeNativeMethodsPrivate.GetStringTypeEx(locale, infoType, sourceString, count, charTypes); int win32Error = Marshal.GetLastWin32Error(); if (!win32Return) { throw new Win32Exception(win32Error); } return win32Return; } ////// Critical: This code elevates to unmanaged code permission /// TreatAsSafe: This function is safe to call /// [SecurityCritical,SecurityTreatAsSafe] public static int GetSysColor(int nIndex) { return SafeNativeMethodsPrivate.GetSysColor(nIndex); } ////// Critical: This code elevates to unmanaged code permission /// TreatAsSafe: Exposes no critical data and doesn't affect clipboard state /// [SecurityCritical, SecurityTreatAsSafe] public static bool IsClipboardFormatAvailable(int format) { return SafeNativeMethodsPrivate.IsClipboardFormatAvailable(format); } #if never [DllImport(ExternDll.User32, EntryPoint = "DestroyIcon", CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)] private static extern bool IntDestroyIcon(NativeMethods.IconHandle hIcon); internal static void DestroyIcon(NativeMethods.IconHandle hIcon) { if (IntDestroyIcon(hIcon) == false) { throw new Win32Exception(); } } #endif ///////////////////////////// // Used by BASE and FRAMEWORK #if FRAMEWORK_NATIVEMETHODS || BASE_NATIVEMETHODS ////// Critical: This code elevates to unmanaged code permission /// TreatAsSafe: This function is safe to call /// [SecurityCritical,SecurityTreatAsSafe] public static bool IsDebuggerPresent() { return SafeNativeMethodsPrivate.IsDebuggerPresent(); } #endif #if BASE_NATIVEMETHODS ///////////////////// // used by BASE ////// Critical: This code elevates to unmanaged code permission /// TreatAsSafe: This function is safe to call /// [SecurityCritical,SecurityTreatAsSafe] public static void QueryPerformanceCounter(out long lpPerformanceCount) { if (!SafeNativeMethodsPrivate.QueryPerformanceCounter(out lpPerformanceCount)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } } ////// Critical: This code elevates to unmanaged code permission /// TreatAsSafe: This function is safe to call /// [SecurityCritical,SecurityTreatAsSafe] public static void QueryPerformanceFrequency(out long lpFrequency) { if (!SafeNativeMethodsPrivate.QueryPerformanceFrequency(out lpFrequency)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } } ////// Critical: This code elevates to unmanaged code permission /// TreatAsSafe: This function is safe to call /// [SecurityCritical,SecurityTreatAsSafe] internal static int GetMessageTime() { return SafeNativeMethodsPrivate.GetMessageTime(); } #endif // BASE_NATIVEMETHODS ////// This method accesses an UnsafeNativeMethod under an elevation. This is /// still safe because it just returns the style or ex style which we consider safe. /// [SecurityCritical,SecurityTreatAsSafe] internal static Int32 GetWindowStyle(HandleRef hWnd, bool exStyle) { int nIndex = exStyle ? NativeMethods.GWL_EXSTYLE : NativeMethods.GWL_STYLE; return UnsafeNativeMethods.GetWindowLong(hWnd, nIndex); } [SuppressUnmanagedCodeSecurity] private static partial class SafeNativeMethodsPrivate { [DllImport(ExternDll.User32, CharSet = CharSet.Auto)] internal static extern bool InSendMessage(); // [DllImport(ExternDll.User32, ExactSpelling = true)] // public static extern int GetQueueStatus(uint flags); // [DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)] // internal static extern int GetInputState(); [DllImport(ExternDll.Uxtheme, CharSet = CharSet.Unicode)] public static extern int IsThemeActive(); [DllImport(ExternDll.User32, SetLastError=true, CharSet=CharSet.Auto)] public static extern bool SetCaretPos(int x, int y); [DllImport(ExternDll.User32, SetLastError=true, CharSet=CharSet.Auto)] public static extern bool DestroyCaret(); // NOTE: CLR has this in UnsafeNativeMethodsCLR.cs. Not sure why it is unsafe - need to follow up. [DllImport(ExternDll.User32, SetLastError=true, CharSet=CharSet.Auto)] public static extern int GetCaretBlinkTime(); [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] public static extern bool GetStringTypeEx(uint locale, uint infoType, char[] sourceString, int count, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] UInt16[] charTypes); [DllImport(ExternDll.User32, CharSet = System.Runtime.InteropServices.CharSet.Auto)] public static extern int GetSysColor(int nIndex); [DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)] public static extern bool IsClipboardFormatAvailable(int format); #if FRAMEWORK_NATIVEMETHODS || BASE_NATIVEMETHODS [DllImport("kernel32.dll", ExactSpelling = true, CharSet = CharSet.Auto)] internal static extern bool IsDebuggerPresent(); #endif #if BASE_NATIVEMETHODS [DllImport("kernel32.dll", SetLastError = true)] public static extern bool QueryPerformanceCounter(out long lpPerformanceCount); [DllImport("kernel32.dll", SetLastError = true)] public static extern bool QueryPerformanceFrequency(out long lpFrequency); [DllImport(ExternDll.User32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)] internal static extern int GetMessageTime(); #endif } } } // 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
- ParameterInfo.cs
- TextTreeInsertUndoUnit.cs
- JoinGraph.cs
- SpellerInterop.cs
- SmiEventSink.cs
- ObjectAssociationEndMapping.cs
- WebPartConnectionsConfigureVerb.cs
- LookupBindingPropertiesAttribute.cs
- AsyncSerializedWorker.cs
- ThrowHelper.cs
- WebServiceHost.cs
- LayoutExceptionEventArgs.cs
- SecureEnvironment.cs
- InitializationEventAttribute.cs
- ProfileModule.cs
- InstanceLockTracking.cs
- BinaryNode.cs
- SignatureToken.cs
- SerializationInfo.cs
- ICollection.cs
- ImpersonationContext.cs
- UmAlQuraCalendar.cs
- newinstructionaction.cs
- FrameworkTemplate.cs
- BoundField.cs
- DataColumnMappingCollection.cs
- SByteStorage.cs
- CancelEventArgs.cs
- SerialStream.cs
- XmlValidatingReader.cs
- AttributeCollection.cs
- HashJoinQueryOperatorEnumerator.cs
- BinaryOperationBinder.cs
- SemanticBasicElement.cs
- PerformanceCounterNameAttribute.cs
- AppDomain.cs
- MediaTimeline.cs
- TargetFrameworkUtil.cs
- VirtualizingStackPanel.cs
- MessageBuffer.cs
- ClientSession.cs
- CodeChecksumPragma.cs
- PropertyRecord.cs
- ScriptReferenceBase.cs
- SapiRecognizer.cs
- StackBuilderSink.cs
- DynamicQueryStringParameter.cs
- DataContractSerializer.cs
- PermissionSetEnumerator.cs
- InputGestureCollection.cs
- BuildProvidersCompiler.cs
- DataObject.cs
- DbDataRecord.cs
- OciEnlistContext.cs
- CRYPTPROTECT_PROMPTSTRUCT.cs
- Effect.cs
- PipelineDeploymentState.cs
- DataGridRow.cs
- MultiAsyncResult.cs
- cache.cs
- TimelineGroup.cs
- ReferencedCollectionType.cs
- SimpleApplicationHost.cs
- DeferredRunTextReference.cs
- SystemInfo.cs
- IApplicationTrustManager.cs
- Internal.cs
- TableLayoutColumnStyleCollection.cs
- QuaternionRotation3D.cs
- CompiledELinqQueryState.cs
- TransactionBridge.cs
- PartialToken.cs
- AuthenticationServiceManager.cs
- XamlPointCollectionSerializer.cs
- AvTraceDetails.cs
- ExpressionQuoter.cs
- httpapplicationstate.cs
- ConfigPathUtility.cs
- Helpers.cs
- MarshalByValueComponent.cs
- DataViewSetting.cs
- EmptyEnumerator.cs
- RequestResizeEvent.cs
- PerformanceCounterNameAttribute.cs
- SmtpNtlmAuthenticationModule.cs
- WebCategoryAttribute.cs
- ImageButton.cs
- ContextMenu.cs
- DataGridViewCellValidatingEventArgs.cs
- WebEvents.cs
- TextShapeableCharacters.cs
- PersonalizationProvider.cs
- UrlPropertyAttribute.cs
- Label.cs
- AnimatedTypeHelpers.cs
- MethodCallTranslator.cs
- UserControlDocumentDesigner.cs
- InfoCardRSAPKCS1SignatureFormatter.cs
- ContextDataSourceView.cs
- ProxyHwnd.cs