this is in reference to one of the posts i found in the .NET forum
i need to send structure across thru the socket....
static byte [] StructureToByte Array(object obj)
>
> {
>
> int len = Marshal.SizeOf( obj);
>
> byte [] arr = new byte[len];
>
> IntPtr ptr = Marshal.AllocHG lobal(len);
>
> Marshal.Structu reToPtr(obj, ptr, true);
>
> Marshal.Copy(pt r, arr, 0, len);
>
> Marshal.FreeHGl obal(ptr);
>
> return arr;
>
> }
>
> static void ByteArrayToStru cture(byte [] bytearray, ref object obj)
>
> {
>
> int len = Marshal.SizeOf( obj);
>
> IntPtr i = Marshal.AllocHG lobal(len);
>
> Marshal.Copy(by tearray,0, i,len);
>
> obj = Marshal.PtrToSt ructure(i, obj.GetType());
>
> Marshal.FreeHGl obal(i);
>
> }
>
>i was able to convert the struct to byte array but to perform the vice versa wat argument shud be sent in ref object??
is there any other method or modification i could do?
thanks in advance
i need to send structure across thru the socket....
static byte [] StructureToByte Array(object obj)
>
> {
>
> int len = Marshal.SizeOf( obj);
>
> byte [] arr = new byte[len];
>
> IntPtr ptr = Marshal.AllocHG lobal(len);
>
> Marshal.Structu reToPtr(obj, ptr, true);
>
> Marshal.Copy(pt r, arr, 0, len);
>
> Marshal.FreeHGl obal(ptr);
>
> return arr;
>
> }
>
> static void ByteArrayToStru cture(byte [] bytearray, ref object obj)
>
> {
>
> int len = Marshal.SizeOf( obj);
>
> IntPtr i = Marshal.AllocHG lobal(len);
>
> Marshal.Copy(by tearray,0, i,len);
>
> obj = Marshal.PtrToSt ructure(i, obj.GetType());
>
> Marshal.FreeHGl obal(i);
>
> }
>
>i was able to convert the struct to byte array but to perform the vice versa wat argument shud be sent in ref object??
is there any other method or modification i could do?
thanks in advance
Comment