-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Porting StandardOleMarshalObject and IMarshal #30931
Conversation
| @@ -0,0 +1,33 @@ | |||
| // Licensed to the .NET Foundation under one or more agreements. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this being added to src/Common/src? Is it going to be consumed into projects other than System.Runtime.InteropServices? Seems like it should either a) be in System.Runtime.InteropServices's directory, or b) be in src/Common/src/Interop/... somewhere... and I don't believe there's any reason it needs to remain in the Microsoft.Win32 namespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even in desktop it looks like this was the only consumer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stephentoub What are your thoughts on the System.Runtime.InteropServices.ComTypes namespace? COM tends to be a four letter word, but that namespace really represents this interface's provenance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It really doesn't matter since it is an internal-only interface. IMHO I'd just put it in the same namespace as the type that uses it.
| return NativeMethods.E_NOTIMPL; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any tests we can add as part of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added issue #30952 to track this.
| { | ||
| internal static partial class Ole32 | ||
| { | ||
| [DllImport("ole32.dll")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interop.Libraries.Ole32
|
|
||
| namespace Microsoft.Win32 | ||
| { | ||
| internal partial interface IMarshal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Internal types should not be in refererence assembly.
| { | ||
| public class StandardOleMarshalObject : MarshalByRefObject, IMarshal | ||
| { | ||
| private static readonly Guid Clsid_StdMarshal = new Guid("00000017-0000-0000-c000-000000000046"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be CLSID_StdMarshal. https://github.com/dotnet/corefx/blob/master/Documentation/coding-guidelines/interop-guidelines.md#naming
| public partial class StandardOleMarshalObject : MarshalByRefObject, Microsoft.Win32.IMarshal | ||
| { | ||
| protected StandardOleMarshalObject() { } | ||
| int Microsoft.Win32.IMarshal.GetUnmarshalClass(ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags, out Guid pCid) { throw null; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, these are effectively not public.
| int DisconnectObject(int dwReserved); | ||
| } | ||
|
|
||
| internal static class NativeMethods |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not to be too dogmatic, but there is no way these constants aren't already defined somewhere. Is it possible to use them?
| <Compile Include="System\Runtime\InteropServices\ExporterEventKind.cs" /> | ||
| <Compile Include="System\Runtime\InteropServices\RegistrationClassContext.cs" /> | ||
| <Compile Include="System\Runtime\InteropServices\RegistrationConnectionType.cs" /> | ||
| <Compile Include="System\Runtime\InteropServices\StandardOleMarshalObject.cs" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose these types aren't for uap scenario. Could you add a condition for these types?
| // we must not wrap pStandardMarshal with an RCW because that would trigger QIs for random IIDs and the marshaler | ||
| // (aka stub manager object) does not really handle these well and we would risk triggering an AppVerifier break | ||
| IntPtr vtable = *(IntPtr*)pStandardMarshal.ToPointer(); | ||
| IntPtr method = *((IntPtr*)vtable.ToPointer() + 5); // GetMarshalSizeMax is 5th slot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetMarshalSizeMax is 5th slot
typo? it should be MarshalInterface is 5th slot
| Marshal.Release(pUnknown); | ||
| } | ||
| } | ||
| throw new InvalidOperationException(string.Format(SR.StandardOleMarshalObjectGetMarshalerFailed, riid.ToString())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: This doesn't feel correct. These COM methods are marked as [PreserveSig] but in here we are going to throw exception. since it works in desktop, maybe we just keep it as it is.
| <Compile Include="System\Runtime\InteropServices\ComEventInterfaceAttribute.cs" Condition="'$(TargetGroup)' != 'uapaot'" /> | ||
| <Compile Include="System\Runtime\InteropServices\DefaultParameterValueAttribute.cs" Condition="'$(TargetGroup)' != 'uapaot'" /> | ||
| <Compile Include="System\Runtime\InteropServices\HandleCollector.cs" Condition="'$(TargetGroup)' != 'uapaot'" /> | ||
| <Compile Include="System\Runtime\InteropServices\IMarshal.cs" Condition="'$(TargetGroup)' != 'uapaot'" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to exclude this for uapaot? CoGetStandardMarshal is allowed for UWP apps in https://docs.microsoft.com/en-us/windows/desktop/api/combaseapi/nf-combaseapi-cogetstandardmarshal.
We have been keeping the netcoreapp and uap surface in sync.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't aware of this. I did this because of #30931 (comment)
I will revert this
|
Merging this one and an issue has been added to track the tests (Most Probably tests will be added in coreclr). |
* Porting IMarshal * Writing ref File and minor changes * ported from .netfx * formatting and adding aditional files * Minor fixes * Feedback addressed Commit migrated from dotnet/corefx@f70599a
Fixes https://github.com/dotnet/corefx/issues/29956