小编Bob*_*ore的帖子

使用命名管道的双向C++到C#通信

我想在VC++ 6应用程序和C#应用程序之间进行双向通信.我正在使用命名管道.在我的C++代码中,我可以从C#客户端读取消息,但随后服务器"死机",我必须重新启动它.

我想要做的是让C#应用程序连接到C++应用程序,请求状态,然后C++应用程序关闭并检查状态,然后返回"忙"或"空闲".

我不能把任何东西写回C#客户端,因为它说连接已经关闭.我已经评论过的一些事情是我已经尝试过的事情.

C++代码(作为线程启动)

UINT CNamedPipe::StartNamedPipeServer()
{
LPTSTR lpszPipename = "\\\\.\\pipe\\SAPipe"; 
    HANDLE hPipe; 
    BOOL flg;
    DWORD dwWrite,dwRead;
    char szServerUpdate[200];
    char szClientUpdate[200];

    hPipe = CreateNamedPipe (    lpszPipename, 
                                PIPE_ACCESS_DUPLEX,
                                PIPE_TYPE_MESSAGE | 
                                PIPE_READMODE_MESSAGE | 
                                PIPE_NOWAIT,                    //changed from nowait
                                PIPE_UNLIMITED_INSTANCES,    // max. instances 
                                BUFSIZE,                    // output buffer size 
                                BUFSIZE,                    // input buffer size 
                                PIPE_TIMEOUT,                // client time-out 
                                NULL);                        // no security attribute 

    if (hPipe == INVALID_HANDLE_VALUE) 
        return 0;

    ConnectNamedPipe(hPipe, NULL);

    while(m_bServerActive)  //This seems to work well ....
    {

        //Read from client
        flg = …
Run Code Online (Sandbox Code Playgroud)

c# c++ named-pipes visual-c++

7
推荐指数
2
解决办法
1万
查看次数

标签 统计

c# ×1

c++ ×1

named-pipes ×1

visual-c++ ×1