This repo contains a project with examples for using a embedded .NET 6 runtime in a C++ application using dotnet_runtime.
- Visual Studio 2019
- .NET 6 SDK
- Clone this repository recursively using
git clone --recursive [email protected]:KevinGliewe/embedded_dotnet_runtime_examples.git
- Run
build_run.bat
- Imports
VsDevCmd.bat
- Installs dotnet tool
runtimedl
- Downloads the propper .NET 6 runtime for your system using
runtimedl
- Builds
Lib
andHost
using MSBuild - Runs
Host
- CMake 3.16 or newer
- .NET 6 SDK
- C++ compiler
- Clone this repository recursively using
git clone --recursive [email protected]:KevinGliewe/embedded_dotnet_runtime_examples.git
- Run
sh build_run.sh
- Installs dotnet tool
runtimedl
- Downloads the propper .NET 6 runtime for your system using
runtimedl
- Builds
Lib
using .NET 6 SDK - Creates makefile using CMake
- Builds
Host
using make - Runs
Host
snippet: InitRuntimeAndLib
Entrypoints can only use blittable types
Native
snippet: Test_ManagedEntryPoint_Args_CPP
snippet: Test_ManagedEntryPoint_ComponentEntryPoint_CPP
Managed
snippet: Test_ManagedEntryPoint_Args_CS
snippet: Test_ManagedEntryPoint_ComponentEntryPoint_CS
Entrypoints can only use blittable types
Native
snippet: Test_ManagedEntryPoint_Args_CPP
snippet: Test_ManagedEntryPoint_CustomEntryPoint_CPP
Managed
snippet: Test_ManagedEntryPoint_Args_CS
snippet: Test_ManagedEntryPoint_CustomEntryPoint_CS
Native
snippet: Test_ManagedString_Ansi_CPP
Managed
snippet: Test_ManagedString_Ansi_CS
What does CString do?
- Apends a
\0
character on the end of the string. - Converts the string into ANSI encoding.
- Allocate memory for native access using
Marshal.AllocHGlobal
. - Copy the encoded string into the allocated memory.
The encoding depends on the platform. For windows systems it is UTF16 and for posix systems it is UTF32.
Native
snippet: Test_ManagedString_Wide_CPP
Managed
What does CString do?
- Determins the correct encoding for the current platform. (UTF16 or UTF32)
- Apends a
\0
character on the end of the string. - Converts the string into the propper encoding.
- Allocate memory for native access using
Marshal.AllocHGlobal
. - Copy the encoded string into the allocated memory.
snippet: Test_ManagedString_Wide_CS
Native
snippet: Test_NativeString_Ansi_CPP
Managed
snippet: Test_NativeString_Ansi_CS
Native
snippet: Test_NativeString_Wide_CPP
Managed
snippet: Test_NativeString_Wide_CS
Native
snippet: Test_NativeString_RetArgs_CPP
snippet: Test_NativeString_FunctionPointer_CPP
Managed
snippet: Test_NativeString_FunctionPointer_CS
Native
snippet: Test_ManagedFunctionPointer_Typedef_managed_callback_fn_CPP
snippet: Test_ManagedFunctionPointer_Instance_CPP
Managed
snippet: Test_ManagedFunctionPointer_FunctionPointerCallbackDelegate_CS
snippet: Test_ManagedFunctionPointer_Instance_CS
Native
snippet: Test_ManagedFunctionPointer_Typedef_managed_callback_fn_CPP
snippet: Test_ManagedFunctionPointer_Static_CPP
Managed
snippet: Test_ManagedFunctionPointer_FunctionPointerCallbackDelegate_CS
snippet: Test_ManagedFunctionPointer_Static_CS
Native
snippet: Test_NativeFunctionPointer_CallbackFunc_CPP
snippet: Test_NativeFunctionPointer_CallbackPointer_CPP
snippet: Test_NativeFunctionPointer_CallbackFunc_Checked_CPP
Managed
snippet: Test_NativeFunctionPointer_Checked_CS
Native
snippet: Test_NativeFunctionPointer_CallbackFunc_CPP
snippet: Test_NativeFunctionPointer_CallbackPointer_CPP
snippet: Test_NativeFunctionPointer_CallbackFunc_Unchecked_CPP
Managed
snippet: Test_NativeFunctionPointer_Unchecked_CS
Native
snippet: Test_ManagedUnsafe_CPP
Managed
snippet: Test_ManagedUnsafe_CS
Native
snippet: Test_NativeArray_Args_CPP
snippet: Test_NativeArray_Args_Data_CPP
snippet: Test_NativeArray_StructFixed_CPP
Managed
snippet: Test_NativeArray_StructFixed_CS
Native
snippet: Test_NativeArray_ArgumentFixed_CPP
Managed
snippet: Test_NativeArray_ArgumentFixed_CS
Native
snippet: Test_NativeArray_ArgumentFixed_FunctionPointer_CPP
Managed
snippet: Test_NativeArray_ArgumentFixed_FunctionPointer_CS
Native
snippet: Test_DllImport_Export_CPP
snippet: Test_DllImport_Call_CPP
For posix systems, use the
-export-dynamic
flag for the linker.
Managed
snippet: Test_DllImport_CS
Native
snippet: Test_NativeExport_Export_CPP
snippet: Test_NativeExport_Call_CPP
For posix systems, use the
-export-dynamic
flag for the linker.
Managed
snippet: Test_NativeExport_CS
Native
snippet: Test_NativeVTable_Class_CPP
snippet: Test_NativeVTable_Call_CPP
Managed
snippet: Test_NativeVTable_Class_CS
snippet: Test_NativeVTable_ManagedCall_CS
Native
snippet: Test_NativeVTable_Class_CPP
snippet: Test_NativeVTable_Call_CPP
Managed
snippet: Test_NativeVTable_Class_CS
snippet: Test_NativeVTable_Overwrite_CS
snippet: Test_NativeVTable_ManagedOverwrite_CS
dotnet_runtime_test is licensed under MIT license. See LICENSE for more details.