SET(CLR_INTEROP_TEST_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
include_directories(common)
+add_subdirectory(PInvoke/ArrayWithOffset)
add_subdirectory(PInvoke/DllImportPath)
add_subdirectory(PInvoke/BestFitMapping/Char)
add_subdirectory(PInvoke/BestFitMapping/LPStr)
--- /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_InOut(int expected[], int actual[], int numElements, int newValue[])
+{
+ bool correctPassedIn = memcmp(expected, actual, numElements * sizeof(int)) == 0;
+
+ memcpy(actual, newValue, numElements * sizeof(int));
+
+ return correctPassedIn ? TRUE : FALSE;
+}
+
+extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE Marshal_Invalid(void* invalid)
+{
+ return 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;
+using System.Text;
+using System.Runtime.InteropServices;
+using TestLibrary;
+
+unsafe class ArrayWithOffsetTest
+{
+ public static int Main()
+ {
+ try
+ {
+ Span<int> expected = new int[] {1, 2, 3, 4, 5, 6};
+ Span<int> newValue = new int[] {7, 8, 9, 10, 11, 12};
+
+ for (int i = 0; i < expected.Length; i++)
+ {
+ int[] array = new int[] {1, 2, 3, 4, 5, 6};
+ ArrayWithOffset offset = new ArrayWithOffset(array, i * 4); // The offset parameter in ArrayWithOffset is a byte-offset, not an element offset.
+
+ fixed (int* expectedSubArray = expected.Slice(i))
+ fixed (int* newValueSubArray = newValue.Slice(i))
+ {
+ Assert.IsTrue(ArrayWithOffsetNative.Marshal_InOut(expectedSubArray, offset, expected.Length - i, newValueSubArray), $"Native call failed with element offset {i}.");
+ }
+
+ for (int j = 0; j < i; j++)
+ {
+ Assert.AreEqual(expected[j], array[j]);
+ }
+
+ for (int j = i; j < array.Length; j++)
+ {
+ Assert.AreEqual(newValue[j], array[j]);
+ }
+ }
+
+ ArrayWithOffset arrayWithOffset = new ArrayWithOffset(new int[]{ 1 }, 0);
+
+ Assert.Throws<MarshalDirectiveException>(() => ArrayWithOffsetNative.Marshal_Invalid(arrayWithOffset));
+ Assert.Throws<MarshalDirectiveException>(() => ArrayWithOffsetNative.Marshal_Invalid(ref arrayWithOffset));
+ }
+ 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" />
+ <Import Project="../../Interop.settings.targets" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <AssemblyName>ArrayWithOffsetTest</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>
+ <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+ <LangVersion>latest</LangVersion>
+ </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="*.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="CMakeLists.txt" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+</Project>
--- /dev/null
+cmake_minimum_required (VERSION 2.6)
+project (ArrayWithOffsetNative)
+include ("${CLR_INTEROP_TEST_ROOT}/Interop.cmake")
+include_directories(${INC_PLATFORM_DIR})
+set(SOURCES
+ ArrayWithOffsetNative.cpp
+)
+if(WIN32)
+ list(APPEND LINK_LIBRARIES_ADDITIONAL
+ OleAut32.lib
+ )
+endif(WIN32)
+# add the executable
+add_library (ArrayWithOffsetNative SHARED ${SOURCES})
+target_link_libraries(ArrayWithOffsetNative ${LINK_LIBRARIES_ADDITIONAL})
+# add the install targets
+install (TARGETS ArrayWithOffsetNative 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.
+
+using System;
+using System.Text;
+using System.Runtime.InteropServices;
+
+unsafe class ArrayWithOffsetNative
+{
+ [DllImport(nameof(ArrayWithOffsetNative))]
+ public static extern bool Marshal_InOut(int* expected, [In, Out] ArrayWithOffset actual, int numElements, int* newValue);
+
+ [DllImport(nameof(ArrayWithOffsetNative))]
+ public static extern bool Marshal_Invalid(ArrayWithOffset invalidArray);
+
+ [DllImport(nameof(ArrayWithOffsetNative))]
+ public static extern bool Marshal_Invalid(ref ArrayWithOffset array);
+}