3 ms·
C# <-> Rust is pretty straightforward. Just follow the C FFI side on Rust and C# has standard marshal mechanisms for calling C code. extern/dllimport[1] Covers
by vvanders 10y ago
C# <-> Rust is pretty straightforward. Just follow the C FFI side on Rust and C# has standard marshal mechanisms for calling C code.
extern/dllimport[1] Covers most of it. There's automatic conversion for CString/string and delegates as function pointers. If you need to go deeper than that there's the marshal namespace[2]. Going through C++/CX sounds really painful.
[1] -
https://msdn.microsoft.com/en-us/library/e59b22c5.aspx https://msdn.microsoft.com/en-us/library/e59b22c5.aspx
[2] - https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal(v=vs.110).aspx https://msdn.microsoft.com/en-us/library/system.runtime.inte...
- pjmlp 10y ago> C++/CX sounds really painful. Not for someone that knows C++ since C++ARM. :) I am pretty comfortable with C# and native interop, my issue was trying to map Rust strings with .NET UTF-16 ones, including passing ownership from Rust to .NET side.
- vvanders 10y agoIf I remember right you can specify encoding as an attribute on the extern decl.