【问题标题】:Windows Named Pipe is invalidWindows 命名管道无效
【发布时间】:2012-10-21 20:11:11
【问题描述】:

我不知道为什么这个管道是无效的。对我来说一切都很好。这只是一个测试,我不写也不读。谁能告诉我怎么了?

#include <windows.h>
#include <stdio.h>
#include <tchar.h>

#define BUFSIZE 4096

int main()
{
    HANDLE hPipe;

    LPTSTR Pipename = TEXT("\\\\.\\pipe\\mypipe");

    printf("Start Server\n");

    for(;;)
    {
        hPipe = CreateNamedPipe( Pipename,
                                 PIPE_ACCESS_DUPLEX,
                                 PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
                                 PIPE_UNLIMITED_INSTANCES,
                                 BUFSIZE,
                                 BUFSIZE,
                                 NMPWAIT_USE_DEFAULT_WAIT,
                                 NULL );

        if ( hPipe == INVALID_HANDLE_VALUE )
        {
            printf("CreatePipe failed");
            return 0;
        }

        CloseHandle(hPipe);
    }
    return 1;
}

【问题讨论】:

  • 使用GetLastError()判断失败原因。
  • 另外,为什么是无限循环?对 CreateNamedPipe 的调用在失败之前是否成功了一次或多次?

标签: windows pipe named-pipes handlers


【解决方案1】:

如果没有有关错误的更多详细信息,则很难提供帮助。但是,作为一般规则,使用 CreateNamedPipe 创建服务器,然后使用 ConnectNamedPipe。 在客户端,您现在可以使用 ConnectNamedPipe 在服务器端等待的 CreateFile。

【讨论】:

    猜你喜欢
    • 2018-07-10
    • 2010-12-18
    • 2012-01-19
    • 1970-01-01
    • 1970-01-01
    • 2015-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多