Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / CompMod / System / Runtime / InteropServices / StandardOleMarshalObject.cs / 2 / 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; } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- LogWriteRestartAreaAsyncResult.cs
- PageParser.cs
- VirtualDirectoryMapping.cs
- FormViewUpdatedEventArgs.cs
- _ListenerResponseStream.cs
- CacheEntry.cs
- AnonymousIdentificationSection.cs
- TimeZoneNotFoundException.cs
- InfiniteTimeSpanConverter.cs
- ByteAnimationBase.cs
- ApplicationId.cs
- FileFormatException.cs
- BindingGraph.cs
- MemberDescriptor.cs
- State.cs
- WebEvents.cs
- XmlDataSourceView.cs
- DPAPIProtectedConfigurationProvider.cs
- WebPartDisplayMode.cs
- FaultCode.cs
- DataGridViewCellConverter.cs
- PropertyPath.cs
- ResourcePool.cs
- ColorKeyFrameCollection.cs
- EdmConstants.cs
- XmlRootAttribute.cs
- ToolBar.cs
- DesignerInterfaces.cs
- TrackingProfileCache.cs
- TextRunTypographyProperties.cs
- TextParagraphCache.cs
- RoleGroupCollection.cs
- EncryptedReference.cs
- CapabilitiesRule.cs
- OperatorExpressions.cs
- TextBoxAutoCompleteSourceConverter.cs
- DashStyle.cs
- TextRangeAdaptor.cs
- OleDbException.cs
- InstanceDescriptor.cs
- PrincipalPermission.cs
- ExtendedTransformFactory.cs
- XmlSchemaInfo.cs
- DataKey.cs
- SrgsRuleRef.cs
- ObservableCollection.cs
- ProxyAttribute.cs
- ObjectItemLoadingSessionData.cs
- ComplexType.cs
- ZipArchive.cs
- DataGridViewAccessibleObject.cs
- AuthenticatedStream.cs
- Trace.cs
- XmlSchemaInclude.cs
- StandardToolWindows.cs
- Size3DValueSerializer.cs
- DefaultPropertyAttribute.cs
- DataGridTable.cs
- StorageAssociationTypeMapping.cs
- DSASignatureDeformatter.cs
- DPTypeDescriptorContext.cs
- MetadataCache.cs
- AnonymousIdentificationModule.cs
- ArrangedElementCollection.cs
- DockAndAnchorLayout.cs
- OleAutBinder.cs
- KnownAssemblyEntry.cs
- XhtmlBasicTextBoxAdapter.cs
- Version.cs
- FontClient.cs
- MenuItemBindingCollection.cs
- HtmlGenericControl.cs
- TypographyProperties.cs
- BitConverter.cs
- BitmapEffect.cs
- SettingsAttributeDictionary.cs
- PackageRelationshipCollection.cs
- DuplicateDetector.cs
- ByteKeyFrameCollection.cs
- SrgsToken.cs
- FileDialog_Vista_Interop.cs
- PersonalizationEntry.cs
- ListControlDesigner.cs
- ComponentResourceManager.cs
- StoreItemCollection.Loader.cs
- ModuleElement.cs
- PTManager.cs
- SrgsSubset.cs
- MultipleViewPattern.cs
- PageCatalogPart.cs
- ImageCodecInfo.cs
- NamespaceCollection.cs
- indexingfiltermarshaler.cs
- CustomCategoryAttribute.cs
- TextEncodedRawTextWriter.cs
- CodeArrayCreateExpression.cs
- XmlLanguageConverter.cs
- XmlSchemaExternal.cs
- MimeMultiPart.cs
- UnhandledExceptionEventArgs.cs