shepmaster / rust-ffi-omnibus

A collection of examples of using code written in Rust from other languages
http://jakegoulding.com/rust-ffi-omnibus/
Other
493 stars 41 forks source link

C# Arrays example only allows for data to flow in one direction. #87

Open OptimisticPeach opened 5 years ago

OptimisticPeach commented 5 years ago

I tried to use the example as shown here to pass it to rust as a *mut MyStruct and I'm not too sure if it's because of the nature of the Struct or simply due to extern semantics in C#, but I was able to edit the values in rust, but they were not copied back into C#. On the other hand, the following did work but requires me to use unsafe code in C#:

var Output = new MyStruct[100];
unsafe 
{
    fixed(MyStruct* ptr = Output)
    {
        my_rust_function((IntPtr)ptr);
    }
}