public static bool SetServerObject(IntPtr hFile, Telerik.WinControls.CodedUI.IPCMessage data) { bool flag = true; if (data == null) { return(false); } if (hFile != IntPtr.Zero) { using (MemoryStream memoryStream = new MemoryStream()) { try { memoryStream.Seek(0L, SeekOrigin.Begin); new BinaryFormatter().Serialize((Stream)memoryStream, (object)data); } catch (Exception ex) { flag = false; } byte[] array = memoryStream.ToArray(); IntPtr num = IPCServer.MapViewOfFile(hFile, 2U, 0U, 0U, (UIntPtr)100000U); Marshal.WriteInt32(num, array.Length); Marshal.Copy(array, 0, new IntPtr(num.ToInt64() + 4L), array.Length); IPCServer.UnmapViewOfFile(num); } } return(flag); }
public static Telerik.WinControls.CodedUI.IPCMessage GetServerObject(IntPtr hFile) { Telerik.WinControls.CodedUI.IPCMessage ipcMessage = (Telerik.WinControls.CodedUI.IPCMessage)null; if (hFile != IntPtr.Zero) { IntPtr num = IPCServer.MapViewOfFile(hFile, 4U, 0U, 0U, (UIntPtr)100000U); byte[] numArray = new byte[Marshal.ReadInt32(num)]; Marshal.Copy(new IntPtr(num.ToInt64() + 4L), numArray, 0, numArray.Length); using (MemoryStream memoryStream = new MemoryStream(numArray)) { try { memoryStream.Seek(0L, SeekOrigin.Begin); ipcMessage = new BinaryFormatter().Deserialize((Stream)memoryStream) as Telerik.WinControls.CodedUI.IPCMessage; } catch (Exception ex) { ipcMessage = (Telerik.WinControls.CodedUI.IPCMessage)null; } } IPCServer.UnmapViewOfFile(num); } return(ipcMessage); }