Reputation: 300
I cannot figure out why I am getting an ERROR_NOT_FOUND
/ 1168 (0x490) error code. If I replace GetNamedPipeClientProcessId
with GetNamedPipeServerProcessId
, I successfully get the server's process ID.
Code:
[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;
}
}
Upvotes: 1
Views: 763
Reputation: 7170
You need to call GetNamedPipeClientProcessId
after the Client has called the CallNamedPipe
or CreateFile
to connect to the Name Pipe. If the client haven't connect to the Name Pipe, The GetNamedPipeClientProcessId
will failed with ERROR_NOT_FOUND
(0x490).
Upvotes: 3