Skip to content

Commit

Permalink
Put Marshal.GetHINSTANCE under ifdef for Windows instead of COM (#51523)
Browse files Browse the repository at this point in the history
  • Loading branch information
elinor-fung committed Apr 20, 2021
1 parent 2bc0508 commit a668de0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private static object PtrToStructureHelper(IntPtr ptr, Type structureType)
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern bool IsPinnable(object? obj);

#if FEATURE_COMINTEROP
#if TARGET_WINDOWS
/// <summary>
/// Returns the HInstance for this module. Returns -1 if the module doesn't have
/// an HInstance. In Memory (Dynamic) Modules won't have an HInstance.
Expand All @@ -244,7 +244,7 @@ public static IntPtr GetHINSTANCE(Module m)
[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
private static extern IntPtr GetHINSTANCE(QCallModule m);

#endif // FEATURE_COMINTEROP
#endif // TARGET_WINDOWS


[MethodImpl(MethodImplOptions.InternalCall)]
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/vm/ecalllist.h
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,9 @@ FCFuncStart(gInteropMarshalFuncs)
FCFuncElement("IsPinnable", MarshalNative::IsPinnable)
FCFuncElement("GetExceptionCode", ExceptionNative::GetExceptionCode)
FCFuncElement("GetExceptionPointers", ExceptionNative::GetExceptionPointers)
#ifdef TARGET_WINDOWS
QCFuncElement("GetHINSTANCE", COMModule::GetHINSTANCE)
#endif // TARGET_WINDOWS

FCFuncElement("OffsetOfHelper", MarshalNative::OffsetOfHelper)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,6 @@ public static IntPtr GetComInterfaceForObject(object o, Type T, CustomQueryInter
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
}

public static IntPtr GetHINSTANCE(Module m)
{
if (m is null)
{
throw new ArgumentNullException(nameof(m));
}

return (IntPtr)(-1);
}

[SupportedOSPlatform("windows")]
public static IntPtr GetIDispatchForObject(object o)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,19 @@ public static void PtrToStructure<T>(IntPtr ptr, [DisallowNull] T structure)

public static void DestroyStructure<T>(IntPtr ptr) => DestroyStructure(ptr, typeof(T));

// CoreCLR has a different implementation for Windows only
#if !CORECLR || !TARGET_WINDOWS
public static IntPtr GetHINSTANCE(Module m)
{
if (m is null)
{
throw new ArgumentNullException(nameof(m));
}

return (IntPtr)(-1);
}
#endif

/// <summary>
/// Converts the HRESULT to a CLR exception.
/// </summary>
Expand Down

0 comments on commit a668de0

Please sign in to comment.