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");

}

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.