<PackageReference Include="System.Diagnostics.EventLog">
<Version>$(MicrosoftPrivateCoreFxNETCoreAppPackageVersion)</Version>
</PackageReference>
+ <PackageReference Include="System.Drawing.Common">
+ <Version>$(MicrosoftPrivateCoreFxNETCoreAppPackageVersion)</Version>
+ </PackageReference>
</ItemGroup>
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace NetClient
+{
+ using System;
+ using System.Drawing;
+ using System.Runtime.InteropServices;
+ using TestLibrary;
+
+ class ColorTests
+ {
+ private readonly Server.Contract.Servers.ColorTesting server;
+ public ColorTests()
+ {
+ this.server = (Server.Contract.Servers.ColorTesting)new Server.Contract.Servers.ColorTestingClass();
+ }
+
+ public void Run()
+ {
+ this.VerifyColorMarshalling();
+ this.VerifyGetRed();
+ }
+
+ private void VerifyColorMarshalling()
+ {
+ Assert.IsTrue(server.AreColorsEqual(Color.Green, ColorTranslator.ToOle(Color.Green)));
+ }
+
+ private void VerifyGetRed()
+ {
+ Assert.AreEqual(Color.Red, server.GetRed());
+ }
+ }
+}
<Compile Include="ErrorTests.cs" />
<Compile Include="NumericTests.cs" />
<Compile Include="StringTests.cs" />
+ <Compile Include="ColorTests.cs" />
<Compile Include="../../ServerContracts/NativeServers.cs" />
<Compile Include="../../ServerContracts/Server.Contracts.cs" />
<Compile Include="../../ServerContracts/ServerGuids.cs" />
<ItemGroup>
<ProjectReference Include="../../NativeServer/CMakeLists.txt" />
<ProjectReference Include="../../../../Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
+ <PackageReference Include="System.Drawing.Common">
+ <Version>$(MicrosoftPrivateCoreFxNETCoreAppPackageVersion)</Version>
+ </PackageReference>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
new ArrayTests().Run();
new StringTests().Run();
new ErrorTests().Run();
+ new ColorTests().Run();
}
catch (Exception e)
{
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Drawing;
+using System.Runtime.InteropServices;
+
+[ComVisible(true)]
+[Guid(Server.Contract.Guids.ColorTesting)]
+public class ColorTesting : Server.Contract.IColorTesting
+{
+ public bool AreColorsEqual(Color managed, int native) => ColorTranslator.ToOle(managed) == native;
+
+ public Color GetRed() => Color.Red;
+}
<Compile Include="ArrayTesting.cs" />
<Compile Include="StringTesting.cs" />
<Compile Include="ErrorMarshalTesting.cs" />
+ <Compile Include="ColorTesting.cs" />
<Compile Include="../ServerContracts/Server.Contracts.cs" />
<Compile Include="../ServerContracts/ServerGuids.cs" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
-</Project>
\ No newline at end of file
+</Project>
ArrayTests.cpp
StringTests.cpp
ErrorTests.cpp
+ ColorTests.cpp
App.manifest)
# add the executable
Run_ArrayTests();
Run_StringTests();
Run_ErrorTests();
+ Run_ColorTests();
}
catch (HRESULT hr)
{
void Run_ArrayTests();
void Run_StringTests();
void Run_ErrorTests();
+void Run_ColorTests();
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#include "ClientTests.h"
+
+#define RED RGB(0xFF, 0x00, 0x00)
+#define GREEN RGB(0x00, 0xFF, 0x00)
+
+namespace
+{
+ void VerifyColorMarshalling(IColorTesting* color)
+ {
+ HRESULT hr;
+ BOOL match;
+
+ THROW_IF_FAILED(color->AreColorsEqual(GREEN, GREEN, &match));
+
+ THROW_FAIL_IF_FALSE(match);
+ }
+
+ void VerifyGetRed(IColorTesting* color)
+ {
+ HRESULT hr;
+ OLE_COLOR red;
+
+ THROW_IF_FAILED(color->GetRed(&red));
+
+ THROW_FAIL_IF_FALSE(red == RED);
+ }
+}
+
+void Run_ColorTests()
+{
+ HRESULT hr;
+
+ CoreShimComActivation csact{ W("NETServer.dll"), W("ColorTesting") };
+
+ ComSmartPtr<IColorTesting> color;
+ THROW_IF_FAILED(::CoCreateInstance(CLSID_ColorTesting, nullptr, CLSCTX_INPROC, IID_IColorTesting, (void**)&color));
+
+ VerifyColorMarshalling(color);
+ VerifyGetRed(color);
+}
<comClass
clsid="{71CF5C45-106C-4B32-B418-43A463C6041F}"
threadingModel="Both" />
+ <!-- ColorTesting -->
+ <comClass
+ clsid="{C222F472-DA5A-4FC6-9321-92F4F7053A65}"
+ threadingModel="Both" />
</file>
</assembly>
<comClass
clsid="{4CEFE36D-F377-4B6E-8C34-819A8BB9CB04}"
threadingModel="Both" />
+
+ <!-- ColorTesting -->
+ <comClass
+ clsid="{C222F472-DA5A-4FC6-9321-92F4F7053A65}"
+ threadingModel="Both" />
</file>
</assembly>
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#pragma once
+
+#include "Servers.h"
+
+#define RED RGB(0xFF, 0x00, 0x00)
+
+class ColorTesting : public UnknownImpl, public IColorTesting
+{
+public: // IColorTesting
+ DEF_FUNC(AreColorsEqual)(
+ _In_ OLE_COLOR managed,
+ _In_ OLE_COLOR native,
+ _Out_ BOOL* areEqual
+ )
+ {
+ *areEqual = (managed == native ? TRUE : FALSE);
+ return S_OK;
+ }
+
+ DEF_FUNC(GetRed)(
+ _Out_ OLE_COLOR* color
+ )
+ {
+ *color = RED;
+ return S_OK;
+ }
+
+public: // IUnknown
+ STDMETHOD(QueryInterface)(
+ /* [in] */ REFIID riid,
+ /* [iid_is][out] */ _COM_Outptr_ void __RPC_FAR *__RPC_FAR *ppvObject)
+ {
+ return DoQueryInterface<ColorTesting, IColorTesting>(this, riid, ppvObject);
+ }
+
+ DEFINE_REF_COUNTING();
+};
RETURN_IF_FAILED(RegisterClsid(__uuidof(ErrorMarshalTesting), L"Both"));
RETURN_IF_FAILED(RegisterClsid(__uuidof(DispatchTesting), L"Both"));
RETURN_IF_FAILED(RegisterClsid(__uuidof(AggregationTesting), L"Both"));
+ RETURN_IF_FAILED(RegisterClsid(__uuidof(ColorTesting), L"Both"));
return S_OK;
}
RETURN_IF_FAILED(RemoveClsid(__uuidof(ErrorMarshalTesting)));
RETURN_IF_FAILED(RemoveClsid(__uuidof(DispatchTesting)));
RETURN_IF_FAILED(RemoveClsid(__uuidof(AggregationTesting)));
+ RETURN_IF_FAILED(RemoveClsid(__uuidof(ColorTesting)));
return S_OK;
}
if (rclsid == __uuidof(AggregationTesting))
return ClassFactoryAggregate<AggregationTesting>::Create(riid, ppv);
+ if (rclsid == __uuidof(ColorTesting))
+ return ClassFactoryBasic<ColorTesting>::Create(riid, ppv);
+
return CLASS_E_CLASSNOTAVAILABLE;
}
class DECLSPEC_UUID("71CF5C45-106C-4B32-B418-43A463C6041F") ErrorMarshalTesting;
class DECLSPEC_UUID("0F8ACD0C-ECE0-4F2A-BD1B-6BFCA93A0726") DispatchTesting;
class DECLSPEC_UUID("4CEFE36D-F377-4B6E-8C34-819A8BB9CB04") AggregationTesting;
+class DECLSPEC_UUID("C222F472-DA5A-4FC6-9321-92F4F7053A65") ColorTesting;
#define CLSID_NumericTesting __uuidof(NumericTesting)
#define CLSID_ArrayTesting __uuidof(ArrayTesting)
#define CLSID_ErrorMarshalTesting __uuidof(ErrorMarshalTesting)
#define CLSID_DispatchTesting __uuidof(DispatchTesting)
#define CLSID_AggregationTesting __uuidof(AggregationTesting)
+#define CLSID_ColorTesting __uuidof(ColorTesting)
#define IID_INumericTesting __uuidof(INumericTesting)
#define IID_IArrayTesting __uuidof(IArrayTesting)
#define IID_IErrorMarshalTesting __uuidof(IErrorMarshalTesting)
#define IID_IDispatchTesting __uuidof(IDispatchTesting)
#define IID_IAggregationTesting __uuidof(IAggregationTesting)
+#define IID_IColorTesting __uuidof(IColorTesting)
// Class used for COM activation when using CoreShim
struct CoreShimComActivation
#include "ErrorMarshalTesting.h"
#include "DispatchTesting.h"
#include "AggregationTesting.h"
+ #include "ColorTesting.h"
#endif
internal class AggregationTestingClass
{
}
+
+ /// <summary>
+ /// Managed definition of CoClass
+ /// </summary>
+ [ComImport]
+ [CoClass(typeof(ColorTestingClass))]
+ [Guid("E6D72BA7-0936-4396-8A69-3B76DA1108DA")]
+ internal interface ColorTesting : Server.Contract.IColorTesting
+ {
+ }
+
+ /// <summary>
+ /// Managed activation for CoClass
+ /// </summary>
+ [ComImport]
+ [Guid(Server.Contract.Guids.ColorTesting)]
+ internal class ColorTestingClass
+ {
+ }
}
#pragma warning restore IDE1006 // Naming Styles
namespace Server.Contract
{
using System;
+ using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
[return: MarshalAs(UnmanagedType.VariantBool)]
bool AreAggregated([MarshalAs(UnmanagedType.IUnknown)] object aggregateMaybe1, [MarshalAs(UnmanagedType.IUnknown)] object aggregateMaybe2);
};
+
+ [ComVisible(true)]
+ [Guid("E6D72BA7-0936-4396-8A69-3B76DA1108DA")]
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ public interface IColorTesting
+ {
+ bool AreColorsEqual(Color managed, int native);
+ Color GetRed();
+ }
}
#pragma warning restore 618 // Must test deprecated features
/* interface */ IDispatchTesting;
struct __declspec(uuid("98cc27f0-d521-4f79-8b63-e980e3a92974"))
/* interface */ IAggregationTesting;
+struct __declspec(uuid("E6D72BA7-0936-4396-8A69-3B76DA1108DA"))
+/* interface */ IColorTesting;
//
// Smart pointer typedef declarations
_COM_SMARTPTR_TYPEDEF(IErrorMarshalTesting, __uuidof(IErrorMarshalTesting));
_COM_SMARTPTR_TYPEDEF(IDispatchTesting, __uuidof(IDispatchTesting));
_COM_SMARTPTR_TYPEDEF(IAggregationTesting, __uuidof(IAggregationTesting));
+_COM_SMARTPTR_TYPEDEF(IColorTesting, __uuidof(IColorTesting));
//
// Type library items
_Out_ VARIANT_BOOL *areAggregated) = 0;
};
+struct __declspec(uuid("E6D72BA7-0936-4396-8A69-3B76DA1108DA"))
+IColorTesting : public IUnknown
+{
+ virtual HRESULT STDMETHODCALLTYPE AreColorsEqual(
+ _In_ OLE_COLOR managed,
+ _In_ OLE_COLOR native,
+ _Out_ _Ret_ BOOL* areEqual) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE GetRed(
+ _Out_ _Ret_ OLE_COLOR* color) = 0;
+};
+
#pragma pack(pop)
public const string ErrorMarshalTesting = "71CF5C45-106C-4B32-B418-43A463C6041F";
public const string DispatchTesting = "0F8ACD0C-ECE0-4F2A-BD1B-6BFCA93A0726";
public const string AggregationTesting = "4CEFE36D-F377-4B6E-8C34-819A8BB9CB04";
+ public const string ColorTesting = "C222F472-DA5A-4FC6-9321-92F4F7053A65";
}
-}
\ No newline at end of file
+}