Question

I Wanted to convert a c# code to j# and somehow managed to get over dllimport and marshalas.

Problem is, when a function has a reference to an object - ref isn't recognized

public static native int Mathod(ref Type type, int flags);

Anyone has any experience with j# and know how to send references to a method (or define a type in a method as a reference)

Was it helpful?

Solution

I'm pretty sure that you can't do this directly.

Everything is passed by value in real Java, and presumably in J# too.

In recent versions of Java you can workaround the restriction by using AtomicReference, but I very much doubt that J# is up-to-date enough to support this.

You could try changing the method signature to accept a single-element Type[] array, and then mutate that array element. This would allow you to achieve a similar outcome to ref. The downside is that you'd need to change the call-site and the method itself to wrap and unwrap the variable in the array. (Although you could create your own custom type to encapsulate the wrapping and unwrapping if it simplifies things.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top