private D3Header SendD3Cmd(D3Header SendBuffer) { Thread.Sleep(5); // damit CPU nicht ausgelastet wird. lock (this) { object bufferOBJ = (object)SendBuffer; byte[] ByteStruct = new byte[Marshal.SizeOf(SendBuffer)]; IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(SendBuffer)); Marshal.StructureToPtr(SendBuffer, ptr, true); Marshal.Copy(ptr, ByteStruct, 0, Marshal.SizeOf(SendBuffer)); Marshal.FreeHGlobal(ptr); NamedPipeClientStream pipeClient; SendBuffer.returnValue1.i = -1; SendBuffer.returnValue2.i = -1; SendBuffer.returnValue1.f = -1; SendBuffer.returnValue2.f = -1; try { pipeClient = new NamedPipeClientStream(".", "D3_" + this.D3Process.Id, PipeDirection.InOut); pipeClient.Connect(1000); if (pipeClient.IsConnected) { pipeClient.Write(ByteStruct, 0, Marshal.SizeOf(SendBuffer)); pipeClient.Read(ByteStruct, 0, Marshal.SizeOf(SendBuffer)); } IntPtr i = Marshal.AllocHGlobal(Marshal.SizeOf(bufferOBJ)); Marshal.Copy(ByteStruct, 0, i, Marshal.SizeOf(bufferOBJ)); bufferOBJ = Marshal.PtrToStructure(i, bufferOBJ.GetType()); Marshal.FreeHGlobal(i); pipeClient.Close(); } catch { } return((D3Header)bufferOBJ); } }
private D3Header SendD3Cmd() { Thread.Sleep(10); // damit CPU nicht ausgelastet wird. so CPU is not busy. lock (this) { object bufferOBJ = (object)this.D3Mail; if (this.D3Process != null) { byte[] ByteStruct = new byte[Marshal.SizeOf(this.D3Mail)]; IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(this.D3Mail)); Marshal.StructureToPtr(this.D3Mail, ptr, true); Marshal.Copy(ptr, ByteStruct, 0, Marshal.SizeOf(this.D3Mail)); Marshal.FreeHGlobal(ptr); NamedPipeClientStream pipeClient; pipeClient = new NamedPipeClientStream(".", "D3_" + this.D3Process.Id, PipeDirection.InOut); try { pipeClient.Connect(200); if (pipeClient.IsConnected) { pipeClient.Write(ByteStruct, 0, Marshal.SizeOf(this.D3Mail)); pipeClient.Read(ByteStruct, 0, Marshal.SizeOf(this.D3Mail)); } IntPtr i = Marshal.AllocHGlobal(Marshal.SizeOf(bufferOBJ)); Marshal.Copy(ByteStruct, 0, i, Marshal.SizeOf(bufferOBJ)); bufferOBJ = Marshal.PtrToStructure(i, bufferOBJ.GetType()); Marshal.FreeHGlobal(i); } catch (Exception e) { _logger.Log("[IPlugin] D3 Command Exception." + e); } finally { pipeClient.Close(); } } return(this.D3Mail = (D3Header)bufferOBJ); } }
private D3Header SendD3Cmd() { Thread.Sleep(10); // damit CPU nicht ausgelastet wird. so CPU is not busy. lock (this) { object bufferOBJ = (object)this.D3Mail; if (this.D3Process != null) { byte[] ByteStruct = new byte[Marshal.SizeOf(this.D3Mail)]; IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(this.D3Mail)); Marshal.StructureToPtr(this.D3Mail, ptr, true); Marshal.Copy(ptr, ByteStruct, 0, Marshal.SizeOf(this.D3Mail)); Marshal.FreeHGlobal(ptr); NamedPipeClientStream pipeClient; pipeClient = new NamedPipeClientStream(".", "D3_" + this.D3Process.Id, PipeDirection.InOut); try { pipeClient.Connect(200); if (pipeClient.IsConnected) { pipeClient.Write(ByteStruct, 0, Marshal.SizeOf(this.D3Mail)); pipeClient.Read(ByteStruct, 0, Marshal.SizeOf(this.D3Mail)); } IntPtr i = Marshal.AllocHGlobal(Marshal.SizeOf(bufferOBJ)); Marshal.Copy(ByteStruct, 0, i, Marshal.SizeOf(bufferOBJ)); bufferOBJ = Marshal.PtrToStructure(i, bufferOBJ.GetType()); Marshal.FreeHGlobal(i); } catch (Exception e) { _logger.Log("[IPlugin] D3 Command Exception." + e); } finally { pipeClient.Close(); } } return this.D3Mail = (D3Header)bufferOBJ; } }
private D3Header SendD3Cmd(D3Header SendBuffer) { Thread.Sleep(5); // damit CPU nicht ausgelastet wird. lock (this) { object bufferOBJ = (object)SendBuffer; byte[] ByteStruct = new byte[Marshal.SizeOf(SendBuffer)]; IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(SendBuffer)); Marshal.StructureToPtr(SendBuffer, ptr, true); Marshal.Copy(ptr, ByteStruct, 0, Marshal.SizeOf(SendBuffer)); Marshal.FreeHGlobal(ptr); NamedPipeClientStream pipeClient; SendBuffer.returnValue1.i = -1; SendBuffer.returnValue2.i = -1; SendBuffer.returnValue1.f = -1; SendBuffer.returnValue2.f = -1; try { pipeClient = new NamedPipeClientStream(".", "D3_" + this.D3Process.Id, PipeDirection.InOut); pipeClient.Connect(1000); if (pipeClient.IsConnected) { pipeClient.Write(ByteStruct, 0, Marshal.SizeOf(SendBuffer)); pipeClient.Read(ByteStruct, 0, Marshal.SizeOf(SendBuffer)); } IntPtr i = Marshal.AllocHGlobal(Marshal.SizeOf(bufferOBJ)); Marshal.Copy(ByteStruct, 0, i, Marshal.SizeOf(bufferOBJ)); bufferOBJ = Marshal.PtrToStructure(i, bufferOBJ.GetType()); Marshal.FreeHGlobal(i); pipeClient.Close(); } catch { } return (D3Header)bufferOBJ; } }