c# - convert struct object into byte[] and vice versa in windows phone 7 application -
i want convert struct object byte[]
, vice versa
in windows phone 7 application have used code works in windows form application perfect not working in windows phone application , error
'system.runtime.interopservices.marshal' not contain definition 'allochglobal' 'system.runtime.interopservices.marshal' not contain definition 'freehglobal'
my code
public static byte[] getbytes(object o) { int size = marshal.sizeof(o); byte[] arr = new byte[size]; intptr ptr = marshal.allochglobal(size); marshal.structuretoptr(o, ptr, true); marshal.copy(ptr, arr, 0, size); marshal.freehglobal(ptr); return arr; } public static object getstruct(byte[] arr, object o) { int size = marshal.sizeof(o); intptr ptr = marshal.allochglobal(size); marshal.copy(arr, 0, ptr, size); o = (object)marshal.ptrtostructure(ptr, o.gettype()); marshal.freehglobal(ptr); return o; }
Comments
Post a Comment