What exactly gets returned with extern(C) export string func() ?
frame
frame86 at live.com
Wed Jun 16 08:00:44 UTC 2021
On Wednesday, 16 June 2021 at 02:46:36 UTC, cc wrote:
> I can't seem to get it to work as a return type, but
> interestingly it does work as an out/pass by ref parameter.
Probably for returning the struct it needs some allocation
directive in C# but I'm not sure. Maybe C# also tries something
to do with the IntPtr. It may work if you use a struct on the DLL
side too and convert any specific things like pointers to simple
integers instead.
The out keyword however basically is just a pointer to the
struct, so reading directly from the memory offset from the DLL
works instead.
As long the GC sees the data alive - .(i)dup doesn't protect your
memory here. The data could be collected by the GC anytime the
function call goes out of scope.
More information about the Digitalmars-d-learn
mailing list