Skip to content

Commit

Permalink
Retarget to dotnet6.0. Alter nativehost.cpp to call new `TestCultur…
Browse files Browse the repository at this point in the history
…eInfoCompareInfo` method.

Also add CultureInfo/CompareInfo test code to delegate method for secondary test.
  • Loading branch information
lewiji committed Mar 26, 2022
1 parent 56f4647 commit d232201
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 17 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
/HostWithHostFxr/bin/Debug
/HostWithHostFxr/src/.vs/HostWithHostFxr
/HostWithHostFxr/src/DotNetLib/obj
/HostWithHostFxr/src/NativeHost/bin/Debug/net5.0
/HostWithHostFxr/src/NativeHost/bin/Debug/
/HostWithHostFxr/src/NativeHost/Debug
/HostWithHostFxr/src/NativeHost/obj
**/.idea/
/HostWithHostFxr/src/HostWithHostFxr.sln.DotSettings.user
3 changes: 2 additions & 1 deletion HostWithHostFxr/src/DotNetLib/DotNetLib.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
<LangVersion>10</LangVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down
36 changes: 34 additions & 2 deletions HostWithHostFxr/src/DotNetLib/Lib.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Runtime.InteropServices;
using System.Globalization;

namespace DotNetLib
{
Expand Down Expand Up @@ -27,11 +28,42 @@ public static int Hello(IntPtr arg, int argLength)
return 0;
}

public static int TestCultureInfoCompareInfo(IntPtr arg, int argLength)
{
String[] sign = new String[] { "<", "=", ">" };

// The code below demonstrates how strings compare
// differently for different cultures.
String s1 = "Coté", s2 = "coté", s3 = "côte";

// Set sort order of strings for French in France.
CompareInfo ci = new CultureInfo("fr-FR").CompareInfo;
Console.WriteLine("The LCID for {0} is {1}.", ci.Name, ci.LCID);

// Display the result using fr-FR Compare of Coté = coté.
Console.WriteLine("fr-FR Compare: {0} {2} {1}",
s1, s2, sign[ci.Compare(s1, s2, CompareOptions.IgnoreCase) + 1]);

// Display the result using fr-FR Compare of coté > côte.
Console.WriteLine("fr-FR Compare: {0} {2} {1}",
s2, s3, sign[ci.Compare(s2, s3, CompareOptions.None) + 1]);

// Set sort order of strings for Japanese as spoken in Japan.
ci = new CultureInfo("ja-JP").CompareInfo;
Console.WriteLine("The LCID for {0} is {1}.", ci.Name, ci.LCID);

// Display the result using ja-JP Compare of coté < côte.
Console.WriteLine("ja-JP Compare: {0} {2} {1}",
s2, s3, sign[ci.Compare(s2, s3) + 1]);

return 0;
}

public delegate void CustomEntryPointDelegate(LibArgs libArgs);
public static void CustomEntryPoint(LibArgs libArgs)
{
Console.WriteLine($"Hello, world! from {nameof(CustomEntryPoint)} in {nameof(Lib)}");
PrintLibArgs(libArgs);
Console.WriteLine("-------");
TestCultureInfoCompareInfo(libArgs.Message, libArgs.Number);
}

#if NET5_0
Expand Down
6 changes: 3 additions & 3 deletions HostWithHostFxr/src/NativeHost/NativeHost.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -92,7 +92,7 @@

<Exec Command="g++ $(SourceFiles) $(IncPaths) $(PreprocessorDefines) -std=c++11 -o &quot;$(NativeOutputFilePath)&quot; $(CompilerArgs) $(LinkArgs)"
WorkingDirectory="$(NativeObjDir)"
ConsoleToMsBuild="true" />
/>

<Copy SourceFiles="$(NetHostDir)/$(NetHostName)"
DestinationFolder="$(NativeBinDir)"
Expand All @@ -114,7 +114,7 @@

<Exec Command="&quot;$(MSVCCompilerPath)&quot; $(SourceFiles) $(IncPaths) $(PreprocessorDefines) $(CompilerArgs) /link $(LibPaths) /out:&quot;$(NativeOutputFilePath)&quot;"
WorkingDirectory="$(NativeObjDir)"
ConsoleToMsBuild="true" />
/>

<Copy SourceFiles="$(NetHostDir)/$(NetHostName)"
DestinationFolder="$(NativeBinDir)"
Expand Down
3 changes: 0 additions & 3 deletions HostWithHostFxr/src/NativeHost/NativeHost.vs.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<RootNamespace>NativeHost</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
Expand All @@ -52,7 +51,6 @@
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
Expand Down Expand Up @@ -160,7 +158,6 @@
<ItemGroup>
<ClCompile Include="nativehost.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"NativeHost": {
"commandName": "Executable",
"executablePath": "$(SolutionDir)\\..\\bin\\$(Configuration)\\nativehost.exe",
"executablePath": "$(MSBuildProjectDirectory)/../../bin/Debug/nativehost",
"nativeDebugging": true
}
}
Expand Down
12 changes: 6 additions & 6 deletions HostWithHostFxr/src/NativeHost/nativehost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ int main(int argc, char *argv[])
//
const string_t dotnetlib_path = root_path + STR("DotNetLib.dll");
const char_t *dotnet_type = STR("DotNetLib.Lib, DotNetLib");
const char_t *dotnet_type_method = STR("Hello");
const char_t *dotnet_type_method = STR("TestCultureInfoCompareInfo");
// <SnippetLoadAndGet>
// Function pointer to managed delegate
component_entry_point_fn hello = nullptr;
Expand All @@ -115,19 +115,19 @@ int main(int argc, char *argv[])
const char_t *message;
int number;
};
for (int i = 0; i < 3; ++i)
{
// <SnippetCallManaged>
lib_args args
{
STR("from host!"),
i
};

0
};
hello(&args, sizeof(args));
// </SnippetCallManaged>

}

// </SnippetCallManaged>

#ifdef NET5_0
// Function pointer to managed delegate with non-default signature
typedef void (CORECLR_DELEGATE_CALLTYPE *custom_entry_point_fn)(lib_args args);
Expand Down

0 comments on commit d232201

Please sign in to comment.