简体   繁体   English

Windows命名管道无效

[英]Windows Named Pipe is invalid

I have no idea why this pipe is invalid. 我不知道为什么这个管道无效。 everything seems fine to me. 在我看来一切都很好。 This is just a test, i don't write or read from it. 这只是一个测试,我不会从中写入或读取。 Anyone can tell me what's wrong? 谁能告诉我怎么了?

#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;
}

Without more detail about the error it is difficult to help. 如果没有有关该错误的更多详细信息,很难提供帮助。 However, as a general rule create the server using CreateNamedPipe then use ConnectNamedPipe. 但是,作为一般规则,请使用CreateNamedPipe创建服务器,然后使用ConnectNamedPipe。 On the client side you can now use CreateFile, which ConnectNamedPipe is waiting for on the server side. 在客户端,您现在可以使用CreateFile,ConnectNamedPipe在服务器端正在等待。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM