* Add tests for VBByRefStr marshalling.
* Compile native for VBByRefStr on all platforms.
* Fix encoding.
* PR Feedback.
* Fix PInvokeDefs file.
* Fix visibility
add_subdirectory(StringMarshalling/UTF8)
add_subdirectory(StringMarshalling/BSTR)
add_subdirectory(StringMarshalling/AnsiBSTR)
+add_subdirectory(StringMarshalling/VBByRefStr)
add_subdirectory(MarshalAPI/FunctionPointer)
add_subdirectory(MarshalAPI/IUnknown)
add_subdirectory(SizeConst)
--- /dev/null
+cmake_minimum_required (VERSION 2.6)
+project (VBByRefStrNative)
+include_directories(${INC_PLATFORM_DIR})
+set(SOURCES VBByRefStrNative.cpp )
+
+# add the executable
+add_library (VBByRefStrNative SHARED ${SOURCES})
+target_link_libraries(VBByRefStrNative ${LINK_LIBRARIES_ADDITIONAL})
+
+# add the install targets
+install (TARGETS VBByRefStrNative 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;
+
+class VBByRefStrNative
+{
+
+ [DllImport(nameof(VBByRefStrNative), CharSet = CharSet.Ansi)]
+ public static extern bool Marshal_Ansi(string expected, [MarshalAs(UnmanagedType.VBByRefStr)] ref string actual, string newValue);
+ [DllImport(nameof(VBByRefStrNative), CharSet = CharSet.Unicode)]
+ public static extern bool Marshal_Unicode(string expected, [MarshalAs(UnmanagedType.VBByRefStr)] ref string actual, string newValue);
+
+ [DllImport(nameof(VBByRefStrNative), EntryPoint = "Marshal_Invalid")]
+ public static extern bool Marshal_StringBuilder([MarshalAs(UnmanagedType.VBByRefStr)]ref StringBuilder builder);
+
+ [DllImport(nameof(VBByRefStrNative), EntryPoint = "Marshal_Invalid")]
+ public static extern bool Marshal_ByVal([MarshalAs(UnmanagedType.VBByRefStr)]string str);
+}
--- /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>
+#include "platformdefines.h"
+
+extern "C" DLL_EXPORT BOOL Marshal_Ansi(LPCSTR expected, LPSTR actual, LPCSTR newValue)
+{
+ bool result = strcmp(expected, actual) == 0;
+
+ strcpy_s(actual, strlen(actual), newValue);
+
+ return result;
+}
+
+extern "C" DLL_EXPORT BOOL Marshal_Unicode(LPCWSTR expected, LPWSTR actual, LPCWSTR newValue)
+{
+ bool result = wcscmp(expected, actual) == 0;
+
+ wcscpy_s(actual, wcslen(actual), newValue);
+
+ return result;
+}
+
+
+extern "C" DLL_EXPORT BOOL Marshal_Invalid(LPCSTR value)
+{
+ 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.Runtime.InteropServices;
+using System;
+using System.Reflection;
+using System.Text;
+using TestLibrary;
+
+#pragma warning disable CS0612, CS0618
+
+class Test
+{
+
+ public static int Main(string[] args)
+ {
+ try
+ {
+ string expected = "abcdefgh";
+ string actual;
+ string newValue = "zyxwvut\0";
+
+ actual = expected;
+ Assert.IsTrue(VBByRefStrNative.Marshal_Ansi(expected, ref actual, newValue));
+ Assert.AreEqual(newValue, actual);
+
+ actual = expected;
+ Assert.IsTrue(VBByRefStrNative.Marshal_Unicode(expected, ref actual, newValue));
+ Assert.AreEqual(newValue, actual);
+
+ StringBuilder builder = new StringBuilder();
+
+ Assert.Throws<MarshalDirectiveException>(() => VBByRefStrNative.Marshal_StringBuilder(ref builder));
+ Assert.Throws<MarshalDirectiveException>(() => VBByRefStrNative.Marshal_ByVal(string.Empty));
+ }
+ 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>VBByRefStrTest</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>
+ <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+ <DefineConstants>$(DefineConstants);STATIC</DefineConstants>
+ <!-- Test unsupported outside of windows -->
+ <TestUnsupportedOutsideWindows>true</TestUnsupportedOutsideWindows>
+ <DisableProjectBuild Condition="'$(TargetsUnix)' == 'true'">true</DisableProjectBuild>
+ </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>