c# - Marshal.PtrToStructure() that struct contains a double pointer menebre (mapped to IntPtr) -


i dymanically loading win32 dll , calling function. function contains passing-by-ref parameter , parameter struct contains double pointer member. marshaled double pointer member intptr, marshaled struct parameter intptr also. part of code seems have no problem.

after function call (methodinfo.invoke()), use marshal.ptrtostructure() returned struct data intptr , exception "cannot evaluate expression because code of current method optimized.". made sure "optimize code" unchecked project.

the following simplified code:

typedef struct {     int x;     int** xx; }struct_doubptr int passoutdoubptrstructmember(struct_doubptr* ptrstructmember); 

marshal struct intptr:

var obj = activator.createinstance(type.gettype("struct_doubptr")); intptr ptr = marshal.allochglobal(marshal.sizeof(obj)); 

the "obj" initialized member x = 20 , xx = intptr before calling marshal.structuretoptr(obj, ptr, false);

marshal intptr struct:

type type = type.gettype("struct_doubptr"); var newobj = activator.createinstance(type); fieldinfo[] fields = type.getfields(); foreach (fieldinfo field in fields) {        //if field intptr      //a seperate function iscalled here determine if memeber intptr     {            field.setvalue(newobj, intptr.zero);     } } marshal.ptrtostructure(dataptr, newobj);  //where dataptr strcut parameter invoking passoutdoubptrstructmembe() 

any comments/suggestion greate help.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -