internal void EnsureActive() { uint pid; if (TryGetProcessId(out pid)) { return; } // Setup a communication channel. try { host = new CHlslHost(); } catch (System.Runtime.InteropServices.COMException ctorErr) { System.Diagnostics.Debug.WriteLine(ctorErr); // Start the host process. ProcessStartInfo psi = new ProcessStartInfo("HLSLHost.exe"); try { Process p = System.Diagnostics.Process.Start(psi); } catch (System.ComponentModel.Win32Exception startErr) { System.Diagnostics.Debug.WriteLine(startErr); throw; } System.Threading.Thread.Sleep(200); host = new CHlslHost(); } }
internal HhMessageReply GetReply() { try { var str = host as System.Runtime.InteropServices.ComTypes.IStream; byte[] response = new byte[8]; str.Read(response, (int)HhMessageHeader.FixedSize, IntPtr.Zero); System.IO.BinaryReader r = new System.IO.BinaryReader(new System.IO.MemoryStream(response)); uint len = r.ReadUInt32(); if (len == 0) { return(null); } uint kind = r.ReadUInt32(); switch (kind) { case GetPidMsgReplyId: str.Read(response, 4, IntPtr.Zero); return(new HhGetPidReply(BytesAsUInt32(response))); case StartRendererMsgReplyId: case StopRendererMsgReplyId: case SetPayloadMsgReplyId: case (uint)HhMessageId.SetParentHwndMsgReplyId: str.Read(response, 4, IntPtr.Zero); return(new HhResultReply(kind, BytesAsUInt32(response))); case ReadLogMsgReplyId: response = new byte[len - 8]; str.Read(response, response.Length, IntPtr.Zero); System.IO.BinaryReader logReader = new System.IO.BinaryReader(new System.IO.MemoryStream(response), Encoding.Unicode); uint charCount = logReader.ReadUInt32(); // text size. string text = new string(logReader.ReadChars((int)charCount)); return(new HhLogReply(text)); default: throw new InvalidOperationException("Unknown reply kind from host: " + kind); } } catch (Exception runError) { System.Diagnostics.Debug.WriteLine(runError); host = null; throw; } }