add_subdirectory(PInvoke/Delegate/MarshalDelegateAsField)
add_subdirectory(PInvoke/Delegate/MarshalDelegateAsParam)
add_subdirectory(PInvoke/Primitives/Int)
+add_subdirectory(PInvoke/Primitives/RuntimeHandles)
add_subdirectory(PInvoke/SizeParamIndex/PInvoke/PassingByOut)
add_subdirectory(PInvoke/SizeParamIndex/PInvoke/PassingByRef)
add_subdirectory(PInvoke/SizeParamIndex/ReversePInvoke/PassingByOut)
--- /dev/null
+cmake_minimum_required (VERSION 2.6)
+project (RuntimeHandlesNative)
+include ("${CLR_INTEROP_TEST_ROOT}/Interop.cmake")
+include_directories(${INC_PLATFORM_DIR})
+set(SOURCES RuntimeHandlesNative.cpp)
+add_library (RuntimeHandlesNative SHARED ${SOURCES})
+# add the install targets
+install (TARGETS RuntimeHandlesNative DESTINATION bin)
--- /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 <xplatform.h>
+
+extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE Marshal_In(HANDLE expected, HANDLE actual)
+{
+ return expected == actual ? TRUE : FALSE;
+}
--- /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.Runtime.InteropServices;
+using System;
+using System.Reflection;
+using TestLibrary;
+
+class TestClass
+{
+ public int field;
+
+ public void Method()
+ {
+ }
+}
+
+class RuntimeHandlesTest
+{
+ [DllImport("RuntimeHandlesNative")]
+ private static extern bool Marshal_In(RuntimeMethodHandle expected, IntPtr handle);
+ [DllImport("RuntimeHandlesNative")]
+ private static extern bool Marshal_In(RuntimeFieldHandle expected, IntPtr handle);
+ [DllImport("RuntimeHandlesNative")]
+ private static extern bool Marshal_In(RuntimeTypeHandle expected, IntPtr handle);
+
+ private static void TestRuntimeMethodHandle()
+ {
+ RuntimeMethodHandle handle = typeof(TestClass).GetMethod(nameof(TestClass.Method)).MethodHandle;
+ Assert.IsTrue(Marshal_In(handle, handle.Value));
+ }
+
+ private static void TestRuntimeFieldHandle()
+ {
+ RuntimeFieldHandle handle = typeof(TestClass).GetField(nameof(TestClass.field)).FieldHandle;
+ Assert.IsTrue(Marshal_In(handle, handle.Value));
+ }
+
+ private static void TestRuntimeTypeHandle()
+ {
+ RuntimeTypeHandle handle = typeof(TestClass).TypeHandle;
+ Assert.IsTrue(Marshal_In(handle, handle.Value));
+ }
+
+ public static int Main()
+ {
+ try
+ {
+ TestRuntimeTypeHandle();
+ TestRuntimeFieldHandle();
+ TestRuntimeMethodHandle();
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e);
+ return 101;
+ }
+ return 100;
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <AssemblyName>RuntimeHandlesTest</AssemblyName>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{F1E66554-8C8E-4141-85CF-D0CD6A0CD0B0}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\</SolutionDir>
+ <DefineConstants>$(DefineConstants);STATIC</DefineConstants>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"></PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"></PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="RuntimeHandlesTest.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="CMakeLists.txt" />
+ </ItemGroup>
+ <Import Project="../../../Interop.settings.targets" />
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+</Project>
typedef char* LPSTR;
typedef const char* LPCSTR;
typedef void* FARPROC;
+typedef void* HANDLE;
typedef void* HMODULE;
typedef int error_t;
typedef void* LPVOID;