public unsafe UserParameters ConvertBytesParameters(Byte[] bytes) { ParametersMessage pm = message; UserParameters p = userParameters; var m = Marshal.SizeOf(message); var u = Marshal.SizeOf(userParameters); IntPtr pnt = Marshal.AllocHGlobal(m); try { Marshal.Copy(bytes, 0, pnt, m); pm = (ParametersMessage)Marshal.PtrToStructure(pnt, typeof(ParametersMessage)); p = (UserParameters)pm.parameters; } catch (Exception e) { Console.WriteLine(e); } finally { Marshal.FreeHGlobal(pnt); } return(p); }
public Byte[] GetWriteParametersArrayBytes(ParametersMessage pm) { var size = Marshal.SizeOf(parametersMessage); Byte[] locabBuffer = new Byte[size]; locabBuffer.Initialize(); parametersMessage = pm; IntPtr pnt = Marshal.AllocHGlobal(size); try { // Copy the struct to unmanaged memory. Marshal.StructureToPtr(parametersMessage, pnt, false); // Create another point. // SingleTaskCommand anotherOrder; // Set this Point to the value of the // Point in unmanaged memory. // anotherOrder = (SingleTaskCommand)Marshal.PtrToStructure(pnt, typeof(SingleTaskCommand)); Marshal.Copy(pnt, locabBuffer, 0, size); } finally { // Free the unmanaged memory. Marshal.FreeHGlobal(pnt); } return(locabBuffer); }