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 [] StructureToByteArray(object obj)
>
> {
>
> int len = Marshal.SizeOf(obj);
>
> byte [] arr = new byte[len];
>
> IntPtr ptr = Marshal.AllocHGlobal(len);
>
> Marshal.StructureToPtr(obj, ptr, true);
>
> Marshal.Copy(ptr, arr, 0, len);
>
> Marshal.FreeHGlobal(ptr);
>
> return arr;
>
> }
>
> static void ByteArrayToStructure(byte [] bytearray, ref object obj)
>
> {
>
> int len = Marshal.SizeOf(obj);
>
> IntPtr i = Marshal.AllocHGlobal(len);
>
> Marshal.Copy(bytearray,0, i,len);
>
> obj = Marshal.PtrToStructure(i, obj.GetType());
>
> Marshal.FreeHGlobal(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