0

So recently I've just started out working with named pipes/pipes. As of right now I have a process called y2 on my local computer. That is the server process. I am trying to connect to that server by opening a pipe. However the WaitNamedPipe function is hanging, apparently the CC server pipe never initializes even though i called CreateNamedPipe right before. Therefore I conclude there's something wrong with my pipe logic. Help would be appreciated, thanks.

int main(){
PROCESS_INFORMATION po;
STARTUPINFO s;

GetStartupInfo (&s);

if(CreateProcess ("c:\\y2.exe", NULL, NULL, NULL, false, 0, NULL, NULL, &s, &po) == FALSE)
{
	printf("Error %d starting CC\n", GetLastError());
	exit(-1);



}

char pipe_name[32];
sprintf(pipe_name, "\\\\.\\pipe\\CC-%d", po.dwProcessId);


HANDLE pipe=CreateNamedPipe (pipe_name, 0x00000003, FILE_FLAG_FIRST_PIPE_INSTANCE, PIPE_UNLIMITED_INSTANCES,128, 128, 0, NULL);


while(WaitNamedPipe(pipe_name, INFINITE)==FALSE)
	Sleep(300);

HANDLE CC = CreateFile (pipe_name, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);



bool fConnected = ConnectNamedPipe(pipe, NULL) ? 
TRUE : (GetLastError() == ERROR_PIPE_CONNECTED); 

if(fConnected) 
printf("true");
else
printf("false");

}

Edited by bfprii: n/a

1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by bfprii
0

Ok, it seems like I have fixed part of the problem.. The pipe name was in hexadecimal. Now i'm getting ERROR 109 after I have connected.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.