Ordinary structure nesting is very simple, C # directly defined in the corresponding structure can be, here is the introduction of nested structure in the form of pointers to express
"1" nested struct-body pointers
C + + code:
typedef struct _TESTSTRU10PRE{INT ival;} teststru10pre;typedef struct _teststru10{teststru10pre *ppre;long lval;_teststru10 () {ppre = NULL;}} TESTSTRU10;
Exportdll_api void Struct_neststruct (TestStru10 *pstru) {if (NULL = = Pstru) {return;} Pstru->lval = 10;if (NULL! = pstru->ppre) {pstru->ppre->ival = 9;} wprintf (L "struct_neststruct \ n");}
C # code:Defined asIntPtrNeed to be parsed:
public struct teststru10pre{public int ival;}; public struct teststru10{public IntPtr ppre; public int lval;}; [DllImport ("ExportDll.dll", CharSet = charset.unicode)]public static extern void Struct_neststruct (ref TESTSTRU10 Pstru );
Test:
Cexportdll.teststru10pre str10pre = new Cexportdll.teststru10pre (); IntPtr intptrstru10pre = Marshal.alloccotaskmem ( Marshal.SizeOf (Str10pre)); Marshal.structuretoptr (Str10pre, Intptrstru10pre, false); Cexportdll.teststru10 stru10 = new Cexportdll.teststru10 (); stru10.ppre = Intptrstru10pre; Cexportdll.struct_neststruct (ref STRU10); Cexportdll.teststru10pre Str10pre2 = (cexportdll.teststru10pre) marshal.ptrtostructure (Stru10.pPre, typeof ( Cexportdll.teststru10pre)); Marshal.destroystructure (Intptrstru10pre, typeof (Cexportdll.teststru10pre));
C # calls C + + platform invoke p/invoke struct-struct nested "eight"