>>        byte[] received;
>>        aMsg myMsg=(aMsg)received;

>>Is this possible?

Actually here is how you do it,

                struct MyMessage
                {
                        int x;
                        int y;
                        int z;
                        int u;
                }

                /// <summary>
                /// The main entry point for the application.
                /// </summary>
                [STAThread]
                static void Main(string[] args)
                {
                        byte[] b = new byte[16];
                        b[4] = 9;

                        GCHandle handle = GCHandle.Alloc(b,
GCHandleType.Pinned);
                        IntPtr ptr =
Marshal.UnsafeAddrOfPinnedArrayElement((Array)handle.Target, 0);

                        MyMessage rc =
(MyMessage)Marshal.PtrToStructure(ptr, typeof(MyMessage));

                        handle.Free();
                }

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to