this question is about the "new" D: Compiler DMD32 D v2.068.2
for TL; DR, if you do not need details, skip the question below
working with visual studio (I am using v2010) by creating a new project D Dynamic Library
when the project creation process is completed, there are 2 files in the solution explorer:
dllmain.d .def file .def it is, I was able to understand that by adding some new functions to dllmain.d and prefilling with:
extern (Windows) export
will export the function, and it will be called from c# , have not tried it using C or C++ .
note, do not touch any existing code if you do not know what you are doing.
so the code below works as expected
extern (Windows) export uint D_mathPower(uint p) { return p * p; }
calling it from C # with the following signature:
[DllImport(@"pathTo...\DynamicLib1.dll", CallingConvention = CallingConvention.StdCall), SuppressUnmanagedCodeSecurity] public static extern uint D_mathPower(uint p);
I could easily use it as follows:
uint powD = D_mathPower(5);
my question
How can I return an array of structures (preferably the most economical way)?
struct dpack{ char* Name; uint Id; }
I tried using both char[] and char* , but without success.
this is my code so far
extern (Windows) export dpack[] D_getPacks(uint size) { dpack[] rtDpArr = new dpack[size]; char[] str = "someText".dup; for(uint i=0; i<size; i++) { str[$ - 1] = cast(char)('0' + i % (126 - '0')); rtDpArr[i].Id = i; rtDpArr[i].Name= str.dup; } return rtDpArr; } void getPacksPtr(uint size, dpack** DpArr) {