Are you attaching to the pipe with a name of the form : "\\ComputerName\pipe\PipeName", where ComputerName is the name of the machine the pipe server is running on and PipeName is the name of the pipe?
The open call should be something like :
hpipe = CreateFile( pipeName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL );
Here's one rather tricky aspect of the code I was using :
static BOOL EstablishNullSession( const char* computerName )
{
NETRESOURCE nr = { 0 };
char server[MAX_PATH+1] = { 0 };
DWORD ret;
if( streq( computerName, "." ) )
{
strcpy( server, computerName );
}
else
{
strcpy( server, "\\\\" );
strcat( server, computerName );
}
nr.dwType = RESOURCETYPE_ANY;
nr.lpRemoteName = server;
ret = WNetAddConnection2( &nr, "", "", 0 );
if( ret != ERROR_SUCCESS )
{
DisplayError( "WNetAddConnection2" );
return FALSE;
}
return TRUE;
}
TPipe ConnectToPipe( const char * pipename, const char * nodename,
int retries, int waitsecs ) )
{
printf( "connecting to pipe '%s'\n", name );
TPipe hpipe = { 0 };
bool triedLogin = false;
DWORD tries = 0;
DWORD lastError = 0;
DWORD openType = GENERIC_READ | GENERIC_WRITE;
while( TRUE )
{
hpipe = CreateFile( name, openType, 0, NULL, OPEN_EXISTING, 0, NULL );
if( hpipe != INVALID_HANDLE_VALUE )
break;
lastError = GetLastError();
if( lastError == ERROR_FILE_NOT_FOUND )
{
if( tries > retries )
{
DisplayError( "CreateFile" );
return 0;
}
++tries;
Sleep( 500 );
continue;
}
else if( ( lastError == ERROR_LOGON_FAILURE ) ||
( lastError == ERROR_ACCESS_DENIED ) ||
( lastError == ERROR_INVALID_PASSWORD ) )
{
if( triedLogon )
{
return 0;
}
else
{
if( EstablishNullSession( nodename ) )
{
printf( "established Null session.\n" );
}
else
{
return 0;
}
triedLogon = true;
continue;
}
}
else if( lastError == ERROR_PIPE_BUSY )
{
printf( "the pipe was busy - waiting" );
if( ! WaitNamedPipe( name, 1000 * waitsecs ) )
{
DisplayError( "WaitNamedPipe" );
return 0;
}
}
else
{
DisplayError( "CreateFile" );
return 0;
}
}
mode = PIPE_READMODE_MESSAGE;
if( ! SetNamedPipeHandleState( hpipe, &mode, NULL, NULL ) )
{
DisplayError( "SetNamedPipeHandleState " );
return 0;
}
return (TPipe)hpipe;
}
I believe TPipe was defined as a ULONG. This is rather old code that I haven't tried in a while but it worked quite well at the time.
Best of luck with it.