C# 互操作 GetNamedPipeClientProcessId ERROR_NOT_FOUND 1168 (0x490)

詹姆士

我不知道为什么我会收到ERROR_NOT_FOUND/ 1168 (0x490) 错误代码。如果我替换GetNamedPipeClientProcessIdGetNamedPipeServerProcessId,我成功地获得了服务器的进程 ID。

代码:

[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool GetNamedPipeClientProcessId(IntPtr Pipe, out int ClientProcessId);

int GetNamedPipeClientProcessId(NamedPipeServerStream pipeServer)
{
   var hPipe = pipeServer.SafePipeHandle.DangerousGetHandle();

    if (GetNamedPipeClientProcessId(hPipe, out var clientProcessId))
    {
        return clientProcessId;
    }
    else
    {
        var error = Marshal.GetLastWin32Error();
        return 0;
    }
}
吴德雷克

您需要GetNamedPipeClientProcessId在客户端调用CallNamedPipeCreateFile连接到名称管道后调用如果客户端还没有连接到名称管道,GetNamedPipeClientProcessId将失败ERROR_NOT_FOUND(0x490)。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章