Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split Variant marshalling tests #53035

Merged
merged 9 commits into from
May 30, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/tests/Interop/PInvoke/Variant/VariantTest.BuiltInCom.cs
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 src/tests/Interop/PInvoke/Variant/VariantTest.ComWrappers.cs
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");
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved Hide resolved
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;
}
}
Loading