Skip to content

Commit

Permalink
Add basic implementation of the ComWrappers (#653)
Browse files Browse the repository at this point in the history
* Add basic implementation of the ComWrappers

* Implement IUnknown interface for CCW

* Introduce InternalComInterfaceDispatch

* Pass type to which convert COM instance.

* Create separate tests for ComWrappers feature

* Read GUID directly from metadata instead of relying on Reflection

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 21, 2021
1 parent 87c90da commit 4ab2b2b
Show file tree
Hide file tree
Showing 13 changed files with 758 additions and 40 deletions.
4 changes: 4 additions & 0 deletions src/coreclr/nativeaot/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
<PropertyGroup>
<DefineConstants Condition="'$(FeatureCominterop)' == 'true'">FEATURE_COMINTEROP;$(DefineConstants)</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<FeatureComWrappers>false</FeatureComWrappers>
<FeatureComWrappers Condition="'$(TargetsWindows)' == 'true'">true</FeatureComWrappers>
</PropertyGroup>

<!-- Platform specific properties -->
<PropertyGroup Condition="'$(Platform)' == 'x64'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,20 @@ public static T GetCurrentCalleeDelegate<T>() where T : class // constraint can'
return PInvokeMarshal.GetCurrentCalleeDelegate<T>();
}

public static IntPtr ConvertManagedComInterfaceToNative(object pUnk)
public static IntPtr ConvertManagedComInterfaceToNative(object pUnk, Guid interfaceGuid)
{
if (pUnk == null)
{
return IntPtr.Zero;
}

#if TARGET_WINDOWS
#pragma warning disable CA1416
return ComWrappers.ComInterfaceForObject(pUnk, interfaceGuid);
#pragma warning restore CA1416
#else
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
#endif
}

public static object ConvertNativeComInterfaceToManaged(IntPtr pUnk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3151,7 +3151,13 @@
<data name="Argv_IncludeDoubleQuote" xml:space="preserve">
<value>The argv[0] argument cannot include a double quote.</value>
</data>
<data name="InvalidOperation_ResetGlobalComWrappersInstance" xml:space="preserve">
<value>Attempt to update previously set global instance.</value>
</data>
<data name="ResourceManager_ReflectionNotAllowed" xml:space="preserve">
<value>Use of ResourceManager for custom types is disabled. Set the MSBuild Property CustomResourceTypesSupport to true in order to enable it.</value>
</data>
<data name="InvalidOperation_ComInteropRequireComWrapperInstance" xml:space="preserve">
<value>COM Interop requires ComWrapper instance registered for marshalling.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
<Compile Include="System\Runtime\TypeLoaderExports.cs" />
<Compile Include="System\Runtime\InitializeFinalizerThread.cs" />
<Compile Include="System\Runtime\InteropServices\ComEventsHelper.CoreRT.cs" Condition="'$(FeatureCominterop)' == 'true'" />
<Compile Include="System\Runtime\InteropServices\ComWrappers.CoreRT.cs" Condition="'$(FeatureComWrappers)' == 'true'" />
<Compile Include="System\Runtime\InteropServices\GCHandle.CoreRT.cs" />
<Compile Include="System\Runtime\InteropServices\InteropExtensions.cs" />
<Compile Include="System\Runtime\InteropServices\NativeFunctionPointerWrapper.cs" />
Expand Down
Loading

0 comments on commit 4ab2b2b

Please sign in to comment.