本文介绍了CreateNamedPipe ERROR_INVALID_NAME的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码片段:

void RunThread(void* unused_args)
{
    PSECURITY_DESCRIPTOR sdsc;
    ULONG size;
    ConvertStringSecurityDescriptorToSecurityDescriptor("S:(ML;;NW;;;LW)", SDDL_REVISION_1, &sdsc, &size);
    SECURITY_ATTRIBUTES sa;
    sa.nLength = sizeof(sa);
    sa.bInheritHandle = false;
    sa.lpSecurityDescriptor = sdsc;
    HANDLE pipe = CreateNamedPipe("\\.\pipe\mmaivpc_test_pipe", PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE, 255, 1024, 1024, 0, &sa);
    DWORD error = GetLastError();
}

如果你还没有从函数名中弄清楚,这个函数正在被 _beginthread 调用.GetLastError() 正在返回 ERROR_INVALID_NAME,我不知道为什么.

If you haven't figured it out from the function name, this function is getting called by _beginthread. GetLastError() is returning ERROR_INVALID_NAME and I can not figure out why.

推荐答案

您需要对用于管道名称的字符串文字中的反斜杠进行转义:

You need to escape the backslashes in the string literal being used for the pipe name:

HANDLE pipe = CreateNamedPipe("\\\\.\\pipe\\mmaivpc_test_pipe",
                              PIPE_ACCESS_DUPLEX, 
                              PIPE_TYPE_BYTE, 255, 1024, 1024, 0, &sa);

这篇关于CreateNamedPipe ERROR_INVALID_NAME的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 03:49