I tried the following code to convert a struct to array of bytes:
It works. Is there a problem using this code ?Code:struct PcToTgtIsAlive { int a; int b; int c; public void Init() { a = 1; b = 2; c = 3; } } class Program { static void Main(string[] args) { PcToTgtIsAlive p = new PcToTgtIsAlive(); p.Init(); int rc=Marshal.SizeOf (p); IntPtr pnt = Marshal.AllocHGlobal(Marshal.SizeOf(p)); Marshal.StructureToPtr(p, pnt, false); byte []dest=new byte[12]; Marshal.Copy(pnt, dest, 0, Marshal.SizeOf(p)); } }
Thanks.




Reply With Quote