Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / CompMod / System / Runtime / InteropServices / StandardOleMarshalObject.cs / 1305376 / StandardOleMarshalObject.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Runtime.InteropServices { using System.Diagnostics; using System; using Microsoft.Win32; using System.Security; using System.Security.Permissions; ////// /// /// Replaces the standard CLR free-threaded marshaler with the standard OLE STA one. This prevents the calls made into /// our hosting object by OLE from coming in on threads other than the UI thread. /// /// [ComVisible(true)] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Interoperability", "CA1403:AutoLayoutTypesShouldNotBeComVisible")] public class StandardOleMarshalObject : MarshalByRefObject, UnsafeNativeMethods.IMarshal { protected StandardOleMarshalObject() { } [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)] private IntPtr GetStdMarshaller(ref Guid riid, int dwDestContext, int mshlflags) { IntPtr pStdMarshal = IntPtr.Zero; IntPtr pUnk = Marshal.GetIUnknownForObject(this); if (pUnk != IntPtr.Zero) { try { if (NativeMethods.S_OK == UnsafeNativeMethods.CoGetStandardMarshal(ref riid, pUnk, dwDestContext, IntPtr.Zero, mshlflags, out pStdMarshal)) { Debug.Assert(pStdMarshal != null, "Failed to get marshaller for interface '" + riid.ToString() + "', CoGetStandardMarshal returned S_OK"); return pStdMarshal; } } finally { Marshal.Release(pUnk); } } throw new InvalidOperationException(SR.GetString(SR.StandardOleMarshalObjectGetMarshalerFailed, riid.ToString())); } ////// [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)] int UnsafeNativeMethods.IMarshal.GetUnmarshalClass(ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags, out Guid pCid){ pCid = typeof(UnsafeNativeMethods.IStdMarshal).GUID; return NativeMethods.S_OK; } /// /// [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)] int UnsafeNativeMethods.IMarshal.GetMarshalSizeMax(ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags, out int pSize) { // 98830 - GUID marshaling in StandardOleMarshalObject AVs on 64-bit Guid riid_copy = riid; IntPtr pStandardMarshal = GetStdMarshaller(ref riid_copy, dwDestContext, mshlflags); try { return UnsafeNativeMethods.CoGetMarshalSizeMax(out pSize, ref riid_copy, pStandardMarshal, dwDestContext, pvDestContext, mshlflags); } finally { Marshal.Release(pStandardMarshal); } } /// /// [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)] int UnsafeNativeMethods.IMarshal.MarshalInterface(object pStm, ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags) { IntPtr pStandardMarshal = GetStdMarshaller(ref riid, dwDestContext, mshlflags); try { return UnsafeNativeMethods.CoMarshalInterface(pStm, ref riid, pStandardMarshal, dwDestContext, pvDestContext, mshlflags); } finally { Marshal.Release(pStandardMarshal); if (pStm != null) { Marshal.ReleaseComObject(pStm); } } } /// /// [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)] int UnsafeNativeMethods.IMarshal.UnmarshalInterface(object pStm, ref Guid riid, out IntPtr ppv) { // this should never be called on this interface, but on the standard one handed back by the previous calls. Debug.Fail("IMarshal::UnmarshalInterface should not be called."); ppv = IntPtr.Zero; if (pStm != null) { Marshal.ReleaseComObject(pStm); } return NativeMethods.E_NOTIMPL; } /// /// [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)] int UnsafeNativeMethods.IMarshal.ReleaseMarshalData(object pStm) { // this should never be called on this interface, but on the standard one handed back by the previous calls. Debug.Fail("IMarshal::ReleaseMarshalData should not be called."); if (pStm != null) { Marshal.ReleaseComObject(pStm); } return NativeMethods.E_NOTIMPL; } /// /// [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)] int UnsafeNativeMethods.IMarshal.DisconnectObject(int dwReserved) { // this should never be called on this interface, but on the standard one handed back by the previous calls. Debug.Fail("IMarshal::DisconnectObject should not be called."); return NativeMethods.E_NOTIMPL; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Runtime.InteropServices { using System.Diagnostics; using System; using Microsoft.Win32; using System.Security; using System.Security.Permissions; ////// /// /// Replaces the standard CLR free-threaded marshaler with the standard OLE STA one. This prevents the calls made into /// our hosting object by OLE from coming in on threads other than the UI thread. /// /// [ComVisible(true)] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Interoperability", "CA1403:AutoLayoutTypesShouldNotBeComVisible")] public class StandardOleMarshalObject : MarshalByRefObject, UnsafeNativeMethods.IMarshal { protected StandardOleMarshalObject() { } [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)] private IntPtr GetStdMarshaller(ref Guid riid, int dwDestContext, int mshlflags) { IntPtr pStdMarshal = IntPtr.Zero; IntPtr pUnk = Marshal.GetIUnknownForObject(this); if (pUnk != IntPtr.Zero) { try { if (NativeMethods.S_OK == UnsafeNativeMethods.CoGetStandardMarshal(ref riid, pUnk, dwDestContext, IntPtr.Zero, mshlflags, out pStdMarshal)) { Debug.Assert(pStdMarshal != null, "Failed to get marshaller for interface '" + riid.ToString() + "', CoGetStandardMarshal returned S_OK"); return pStdMarshal; } } finally { Marshal.Release(pUnk); } } throw new InvalidOperationException(SR.GetString(SR.StandardOleMarshalObjectGetMarshalerFailed, riid.ToString())); } ////// [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)] int UnsafeNativeMethods.IMarshal.GetUnmarshalClass(ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags, out Guid pCid){ pCid = typeof(UnsafeNativeMethods.IStdMarshal).GUID; return NativeMethods.S_OK; } /// /// [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)] int UnsafeNativeMethods.IMarshal.GetMarshalSizeMax(ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags, out int pSize) { // 98830 - GUID marshaling in StandardOleMarshalObject AVs on 64-bit Guid riid_copy = riid; IntPtr pStandardMarshal = GetStdMarshaller(ref riid_copy, dwDestContext, mshlflags); try { return UnsafeNativeMethods.CoGetMarshalSizeMax(out pSize, ref riid_copy, pStandardMarshal, dwDestContext, pvDestContext, mshlflags); } finally { Marshal.Release(pStandardMarshal); } } /// /// [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)] int UnsafeNativeMethods.IMarshal.MarshalInterface(object pStm, ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags) { IntPtr pStandardMarshal = GetStdMarshaller(ref riid, dwDestContext, mshlflags); try { return UnsafeNativeMethods.CoMarshalInterface(pStm, ref riid, pStandardMarshal, dwDestContext, pvDestContext, mshlflags); } finally { Marshal.Release(pStandardMarshal); if (pStm != null) { Marshal.ReleaseComObject(pStm); } } } /// /// [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)] int UnsafeNativeMethods.IMarshal.UnmarshalInterface(object pStm, ref Guid riid, out IntPtr ppv) { // this should never be called on this interface, but on the standard one handed back by the previous calls. Debug.Fail("IMarshal::UnmarshalInterface should not be called."); ppv = IntPtr.Zero; if (pStm != null) { Marshal.ReleaseComObject(pStm); } return NativeMethods.E_NOTIMPL; } /// /// [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)] int UnsafeNativeMethods.IMarshal.ReleaseMarshalData(object pStm) { // this should never be called on this interface, but on the standard one handed back by the previous calls. Debug.Fail("IMarshal::ReleaseMarshalData should not be called."); if (pStm != null) { Marshal.ReleaseComObject(pStm); } return NativeMethods.E_NOTIMPL; } /// /// [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)] int UnsafeNativeMethods.IMarshal.DisconnectObject(int dwReserved) { // this should never be called on this interface, but on the standard one handed back by the previous calls. Debug.Fail("IMarshal::DisconnectObject should not be called."); return NativeMethods.E_NOTIMPL; } } } // 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
- SafeCoTaskMem.cs
- UpdateExpressionVisitor.cs
- CodeDOMUtility.cs
- WebPartManager.cs
- itemelement.cs
- FontFamily.cs
- Pts.cs
- AsyncOperation.cs
- CodeDomConfigurationHandler.cs
- RelationshipDetailsRow.cs
- HistoryEventArgs.cs
- VirtualDirectoryMappingCollection.cs
- DoWorkEventArgs.cs
- SynchronizedInputAdaptor.cs
- FrameworkContentElement.cs
- ConfigXmlComment.cs
- ZipFileInfoCollection.cs
- MailDefinition.cs
- CRYPTPROTECT_PROMPTSTRUCT.cs
- IsolatedStorageFilePermission.cs
- WebRequest.cs
- TextRunCacheImp.cs
- Renderer.cs
- HttpResponseWrapper.cs
- TreeNode.cs
- TemplateField.cs
- MenuAutomationPeer.cs
- FlowLayoutPanel.cs
- TdsParserSafeHandles.cs
- HtmlPanelAdapter.cs
- SmtpTransport.cs
- SymDocumentType.cs
- XmlSchemaAnnotation.cs
- ResourceProperty.cs
- XamlWrappingReader.cs
- UnauthorizedAccessException.cs
- ResourceReferenceKeyNotFoundException.cs
- PeerEndPoint.cs
- ServiceModelConfigurationSection.cs
- CodePageUtils.cs
- IndexedString.cs
- SQLString.cs
- BooleanToVisibilityConverter.cs
- UpdateManifestForBrowserApplication.cs
- SecurityTokenTypes.cs
- BamlRecordWriter.cs
- XmlSchemaInclude.cs
- LiteralControl.cs
- ConfigViewGenerator.cs
- TextDecorationUnitValidation.cs
- Stack.cs
- TabletDeviceInfo.cs
- PropertyInfoSet.cs
- CleanUpVirtualizedItemEventArgs.cs
- IPHostEntry.cs
- ExternalFile.cs
- WebDescriptionAttribute.cs
- precedingsibling.cs
- SqlDataReaderSmi.cs
- CompiledELinqQueryState.cs
- ConfigurationCollectionAttribute.cs
- ToolboxItemCollection.cs
- ButtonFlatAdapter.cs
- TransformGroup.cs
- ProcessHostMapPath.cs
- TemplateColumn.cs
- DrawingContextWalker.cs
- SimpleWorkerRequest.cs
- RadioButtonRenderer.cs
- safelink.cs
- MenuStrip.cs
- Calendar.cs
- HelpProvider.cs
- BrowserCapabilitiesCodeGenerator.cs
- DataGridToolTip.cs
- DataControlExtensions.cs
- SetterBaseCollection.cs
- TransformationRules.cs
- AttachedPropertyBrowsableAttribute.cs
- QilGeneratorEnv.cs
- SecurityState.cs
- DbParameterHelper.cs
- MemberProjectionIndex.cs
- configsystem.cs
- Int64AnimationBase.cs
- WorkflowApplicationAbortedEventArgs.cs
- XmlNodeChangedEventArgs.cs
- TableLayoutColumnStyleCollection.cs
- WpfPayload.cs
- PieceNameHelper.cs
- ParameterBuilder.cs
- KeyValuePair.cs
- TextWriter.cs
- wmiprovider.cs
- SQLDateTimeStorage.cs
- CompressionTracing.cs
- TimelineCollection.cs
- ConnectionProviderAttribute.cs
- RequestCachePolicyConverter.cs
- Pen.cs