示例#1
0
文件: Driver.cs 项目: sibaoli/Moirai
            public static uint Request(
                SafeFileHandle hPort,
                uint tenantId,
                uint flowId,
                uint flags)
            {
                uint HRESULT         = 0;
                uint lpBytesReturned = 0;

                OKTOPUS_CREATE_FLOW_REQUEST Request = new OKTOPUS_CREATE_FLOW_REQUEST();
                OKTOPUS_CREATE_FLOW_REPLY   Reply   = new OKTOPUS_CREATE_FLOW_REPLY();

                Request.OpCode   = (ulong)IOFLOWUSER_OPCODE.OpCodeCreateFlow;
                Request.TenantId = tenantId;
                Request.FlowId   = flowId;
                Request.Flags    = flags;
                Reply.Result     = 0;

                // Pin buffers for duration of synchronous call to FilterSendMessage.
                GCHandle gchRequest = GCHandle.Alloc(Request, GCHandleType.Pinned);
                GCHandle gchReply   = GCHandle.Alloc(Reply, GCHandleType.Pinned);

                // FilterSendMessage() ref http://msdn.microsoft.com/en-us/library/windows/hardware/ff541513(v=vs.85).aspx
                HRESULT = FilterSendMessage(hPort,                           // HANDLE hPort,
                                            gchRequest.AddrOfPinnedObject(), // LPVOID lpInBuffer,
                                            (uint)Marshal.SizeOf(Request),   // DWORD dwInBufferSize,
                                            gchReply.AddrOfPinnedObject(),   // LPVOID lpOutBuffer,
                                            (uint)Marshal.SizeOf(Reply),     // DWORD dwOutBufferSize,
                                            out lpBytesReturned);            // LPDWORD lpBytesReturned

                if (HRESULT != S_OK)
                {
                    Marshal.ThrowExceptionForHR((int)HRESULT);
                }

                if (Reply.Result != (uint)RESULTCODES.OKTO_RESULT_SUCCESS)
                {
                    throw new ExceptionIoFlow(DecodeOktoResult(Reply.Result));
                }

                gchRequest.Free();
                gchReply.Free();

                return(HRESULT);
            }
示例#2
0
            public static uint Request(
                SafeFileHandle hPort,
                uint tenantId,
                uint flowId,
                uint flags)
            {
                uint HRESULT = 0;
                uint lpBytesReturned = 0;

                OKTOPUS_CREATE_FLOW_REQUEST Request = new OKTOPUS_CREATE_FLOW_REQUEST();
                OKTOPUS_CREATE_FLOW_REPLY Reply = new OKTOPUS_CREATE_FLOW_REPLY();

                Request.OpCode = (ulong)IOFLOWUSER_OPCODE.OpCodeCreateFlow;
                Request.TenantId = tenantId;
                Request.FlowId = flowId;
                Request.Flags = flags;
                Reply.Result = 0;

                // Pin buffers for duration of synchronous call to FilterSendMessage.
                GCHandle gchRequest = GCHandle.Alloc(Request, GCHandleType.Pinned);
                GCHandle gchReply = GCHandle.Alloc(Reply, GCHandleType.Pinned);

                // FilterSendMessage() ref http://msdn.microsoft.com/en-us/library/windows/hardware/ff541513(v=vs.85).aspx
                HRESULT = FilterSendMessage(hPort,                           // HANDLE hPort,
                                            gchRequest.AddrOfPinnedObject(), // LPVOID lpInBuffer,
                                            (uint)Marshal.SizeOf(Request),   // DWORD dwInBufferSize,
                                            gchReply.AddrOfPinnedObject(),   // LPVOID lpOutBuffer,
                                            (uint)Marshal.SizeOf(Reply),     // DWORD dwOutBufferSize,
                                            out lpBytesReturned);            // LPDWORD lpBytesReturned

                if (HRESULT != S_OK)
                {
                    Marshal.ThrowExceptionForHR((int)HRESULT);
                }

                if (Reply.Result != (uint)RESULTCODES.OKTO_RESULT_SUCCESS)
                {
                    throw new ExceptionIoFlow(DecodeOktoResult(Reply.Result));
                }

                gchRequest.Free();
                gchReply.Free();

                return HRESULT;
            }