The purpose of this repo is to demonstrate the various marshaling behaviors of C# for C++. This demonstrates the following:
- passing simple data types by value, address, and reference
- returning simple data types
- passing arrays of simple data types as const and non-const
- passing C# strings as C-strings
- returning C-strings of different lengths
- passing structs by value, address, and reference
- structs with simple data type members
- structs with struct members
- structs with pointer members
- structs with array members
- returning structs
- passing and executing delegates (function pointers) in the same thread
- with simple data type parameters
- with string parameters
- with struct parameters
- passing and executing a delegate array in the same thread
- passing, storing, and executing delegates for later
- passing struct with delegate members, storing, and executing delegates
- passing and executing delegates in a separate thread
This repo contains 2 projects:
Tested on Visual Studio Community 2017 Version 15.8.5 and Unity Version 2018.3.7f1
- Build the C++ DLL using Visual Studio
- Copy the
NativeLib.dllfrom the output folder and paste it into theAssets\Plugins\x86_64folder - Open Unity3D (or restart it if it was opened while the dll was being copied)
- Open
Assets\Scenes\SampleScene - Navigate to the
TesterGame Object - Enable the Tester script you wish to execute
- Play the scene and check the logs for result
InterOp Marshaling Official MS Documentation
Marshaling with C# Old reference but has good explanation on BOOL vs BOOLEAN
I need help in testing this for macOS. I don't have an Apple machine.