相关疑难解决方法(0)

如何从umnanaged到托管代码空间发送命名管道字符串?

我似乎有一个命名管道101问题.我有一个非常简单的设置来连接从C++非托管应用程序传输到C#托管应用程序的单工命名管道.管道连接,但我不能通过管道发送"消息",除非我关闭看起来冲洗缓冲区并传递消息的句柄.就像消息被阻止一样.我试过反转客户端/服务器的角色,并使用不同的标志组合调用它们,没有任何运气.我可以轻松地从C#托管到C++非托管的另一个方向发送消息.有没有人有任何见解.你们中的任何人都可以成功地将C++中的消息发送到C#managed吗?我可以找到许多内部管理或非管理管道的例子,但不能管理到非管理的管道 - 只是声称能够做到这一点.

在清单中,为了清楚起见,我省略了很多包装材料.我认为相关的关键位是管道连接/创建/读取和写入方法.这里不要过分担心阻塞/线程.

C#服务器端

    // This runs in its own thread and so it is OK to block
    private void ConnectToClient()
    {
        // This server will listen to the sending client
        if (m_InPipeStream == null)
        {
            m_InPipeStream =
                new NamedPipeServerStream("TestPipe", PipeDirection.In, 1);
        }

        // Wait for client to connect to our server
        m_InPipeStream.WaitForConnection();

        // Verify client is running
        if (!m_InPipeStream.IsConnected)
        {
            return;
        }

        // Start listening for messages on the client stream
        if (m_InPipeStream != null && m_InPipeStream.CanRead)
        { …
Run Code Online (Sandbox Code Playgroud)

c# c++ windows mfc named-pipes

8
推荐指数
1
解决办法
4549
查看次数

标签 统计

c# ×1

c++ ×1

mfc ×1

named-pipes ×1

windows ×1