protected void SendMessage(IPC.IConnectionMessage message) { if (first) { first = false; } connection.Send(message); }
public IntPtr LoadDotNetModule(string path, string typeName, string method, string args) { bool x64 = Process.Is64Bit(); if (x64 != Environment.Is64BitProcess) { string helper = null; //Use helper if (x64) { helper = CreateFile(string.Format(BOOTSTRAP_EXE, "x64"), Properties.Resources.StUtil_Native_Bootstrapper_x64); } else { helper = CreateFile(string.Format(BOOTSTRAP_EXE, "x86"), Properties.Resources.StUtil_Native_Bootstrapper_x86); } helper = System.IO.Path.GetFullPath(helper); IPC.NamedPipes.NamedPipeServer server = new IPC.NamedPipes.NamedPipeServer(); Guid guid = Guid.NewGuid(); IntPtr result = IntPtr.Zero; Exception ex = null;; server.ConnectionRecieved += (s, e) => { IPC.IConnectionMessage msg = e.Value.SendAndReceive(new InjectionMessage { File = path, Type = typeName, Method = method, Args = args, ProcessId = Process.Id }); if (msg is IPC.ValueMessage <IntPtr> ) { result = ((IPC.ValueMessage <IntPtr>)msg).Value; } else { ex = ((IPC.ValueMessage <Exception>)msg).Value; } }; var p = System.Diagnostics.Process.Start(helper, guid.ToString()); server.Start(new IPC.NamedPipes.NamedPipeInitialisation(guid.ToString())); if (ex != null) { throw ex; } else { return(result); } } else { return(LoadDotNetModuleImpl(path, typeName, method, args)); } }