Load a C-Dll in C# with struct array as parameter -


i try import functions c-dll. function has struct array parameter. struct filled in function.

struct test {     int test1;     int test2; };  void fillstruct( struct test sttest[], int size) {     if(size == 2){         sttest[0].test1 = 5;         sttest[0].test2 = 5;          sttest[1].test1 = 2;         sttest[1].test2 = 2;     } } 

the method fillstruct should used in c#.

i think have create struct in c#. must marshal struct if use memcpy in fillstruct?

struct test {     public int test1;     public int test2; }  [dllimport("mydll", callingconvention = cdecl)] public static extern void fillstruct( test[] sttest, int size);  [...] var test = new test[n]; fillstruct(test, test.length); 

i don't see problem here. not matter memory in c code: long don't cause buffer overflows, can read, write copy want. c# arrays type , length of array, followed data. when use p/invoke simple structs, pointer first element in original array passed c code.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -