-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
274 additions
and
93 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/tests/Interop/PInvoke/Variant/VariantTest.BuiltInCom.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
using TestLibrary; | ||
using static VariantNative; | ||
|
||
#pragma warning disable CS0612, CS0618 | ||
partial class Test | ||
{ | ||
public static int Main() | ||
{ | ||
bool builtInComDisabled=false; | ||
var comConfig = AppContext.GetData("System.Runtime.InteropServices.BuiltInComInterop.IsSupported"); | ||
if(comConfig != null && !bool.Parse(comConfig.ToString())) | ||
{ | ||
builtInComDisabled=true; | ||
} | ||
|
||
Console.WriteLine($"Built-in COM Disabled?: {builtInComDisabled}"); | ||
try | ||
{ | ||
TestByValue(builtInComDisabled); | ||
TestByRef(builtInComDisabled); | ||
TestOut(); | ||
TestFieldByValue(builtInComDisabled); | ||
TestFieldByRef(builtInComDisabled); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine($"Test failed: {e}"); | ||
return 101; | ||
} | ||
return 100; | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
src/tests/Interop/PInvoke/Variant/VariantTest.ComWrappers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
using TestLibrary; | ||
using static VariantNative; | ||
using ComTypes = System.Runtime.InteropServices.ComTypes; | ||
|
||
#pragma warning disable CS0612, CS0618 | ||
partial class Test | ||
{ | ||
public static int Main() | ||
{ | ||
bool testComMarshal=true; | ||
ComWrappers.RegisterForMarshalling(new ComWrappersImpl()); | ||
try | ||
{ | ||
TestByValue(testComMarshal); | ||
TestByRef(testComMarshal); | ||
TestOut(); | ||
TestFieldByValue(testComMarshal); | ||
TestFieldByRef(testComMarshal); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine($"Test failed: {e}"); | ||
return 101; | ||
} | ||
return 100; | ||
} | ||
} | ||
|
||
internal unsafe class ComWrappersImpl : ComWrappers | ||
{ | ||
private static readonly ComInterfaceEntry* wrapperEntry; | ||
|
||
static ComWrappersImpl() | ||
{ | ||
var vtblRaw = (IntPtr*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(IDispatchVtbl), sizeof(IntPtr) * 7); | ||
GetIUnknownImpl(out vtblRaw[0], out vtblRaw[1], out vtblRaw[2]); | ||
|
||
vtblRaw[3] = (IntPtr)(delegate* unmanaged<IntPtr, IntPtr, int>)&IDispatchVtbl.GetTypeInfoCountInternal; | ||
vtblRaw[4] = (IntPtr)(delegate* unmanaged<IntPtr, int, int, IntPtr, int>)&IDispatchVtbl.GetTypeInfoInternal; | ||
vtblRaw[5] = (IntPtr)(delegate* unmanaged<IntPtr, IntPtr, IntPtr, int, int, IntPtr, int>)&IDispatchVtbl.GetIDsOfNamesInternal; | ||
vtblRaw[6] = (IntPtr)(delegate* unmanaged<IntPtr, int, IntPtr, int, ComTypes.INVOKEKIND, IntPtr, IntPtr, IntPtr, IntPtr, int>)&IDispatchVtbl.InvokeInternal; | ||
|
||
wrapperEntry = (ComInterfaceEntry*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(IDispatchVtbl), sizeof(ComInterfaceEntry)); | ||
wrapperEntry->IID = new Guid("00020400-0000-0000-C000-000000000046"); | ||
wrapperEntry->Vtable = (IntPtr)vtblRaw; | ||
} | ||
|
||
protected override unsafe ComInterfaceEntry* ComputeVtables(object obj, CreateComInterfaceFlags flags, out int count) | ||
{ | ||
// Always return the same table mappings. | ||
count = 1; | ||
return wrapperEntry; | ||
} | ||
|
||
protected override object CreateObject(IntPtr externalComObject, CreateObjectFlags flags) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected override void ReleaseObjects(IEnumerable objects) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
public struct IDispatchVtbl | ||
{ | ||
[UnmanagedCallersOnly] | ||
public static int GetTypeInfoCountInternal(IntPtr thisPtr, IntPtr i) | ||
{ | ||
return 0; // S_OK; | ||
} | ||
|
||
[UnmanagedCallersOnly] | ||
public static int GetTypeInfoInternal(IntPtr thisPtr, int itinfo, int lcid, IntPtr i) | ||
{ | ||
return 0; // S_OK; | ||
} | ||
|
||
[UnmanagedCallersOnly] | ||
public static int GetIDsOfNamesInternal( | ||
IntPtr thisPtr, | ||
IntPtr iid, | ||
IntPtr names, | ||
int namesCount, | ||
int lcid, | ||
IntPtr dispIds) | ||
{ | ||
return 0; // S_OK; | ||
} | ||
|
||
[UnmanagedCallersOnly] | ||
public static int InvokeInternal( | ||
IntPtr thisPtr, | ||
int dispIdMember, | ||
IntPtr riid, | ||
int lcid, | ||
ComTypes.INVOKEKIND wFlags, | ||
IntPtr pDispParams, | ||
IntPtr VarResult, | ||
IntPtr pExcepInfo, | ||
IntPtr puArgErr) | ||
{ | ||
return 0; // S_OK; | ||
} | ||
} |
Oops, something went wrong.