Click here to Skip to main content
15,886,919 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Value of an object in visual studio Pin
Richard Andrew x641-Aug-11 13:48
professionalRichard Andrew x641-Aug-11 13:48 
QuestionCreateNamedPipe() Pin
Member 38520241-Aug-11 12:36
Member 38520241-Aug-11 12:36 
AnswerRe: CreateNamedPipe() Pin
Richard Andrew x641-Aug-11 12:45
professionalRichard Andrew x641-Aug-11 12:45 
GeneralRe: CreateNamedPipe() Pin
Member 38520241-Aug-11 12:54
Member 38520241-Aug-11 12:54 
GeneralRe: CreateNamedPipe() Pin
Richard Andrew x641-Aug-11 12:59
professionalRichard Andrew x641-Aug-11 12:59 
GeneralRe: CreateNamedPipe() Pin
Member 38520241-Aug-11 12:59
Member 38520241-Aug-11 12:59 
GeneralRe: CreateNamedPipe() Pin
Richard Andrew x641-Aug-11 13:05
professionalRichard Andrew x641-Aug-11 13:05 
GeneralRe: CreateNamedPipe() Pin
Member 38520241-Aug-11 13:16
Member 38520241-Aug-11 13:16 
Hiya.

The following code is bit of a mess - cos - I dont know how to submit stuff in a web friendly way - sorry about that - but if you can spot where I am going wrong in-terms of process control - especially in this server stuff - great - below - note - the peek before the read is for good reson!


UINT ReadWorker( LPVOID a_pParam )
{
// Get the pipeline and stage number for this worker.
CCallpipe *p = ( CCallpipe * )a_pParam;

#ifdef _PIPE_DIAG_MESSAGE_
CString szPrefix;
szPrefix.Format( "CCallpipe::ReadWorker(%d,%d)", p->Pipeline(), p->Stage() );
CApplMessage cons( true, true, ( LPCTSTR )szPrefix );
cons.Write( "Starting ReadWorker" );
#endif // _PIPE_DIAG_MESSAGE_

CHAR szReadBuffer[ _IO_BUFFSIZE_ ];
DWORD dwBytesWritten = 0;
DWORD dwRecCount = 0;

// Create the lock name.
p->m_szLock.Format( "CALLPIPE-%.5d", p->m_dwProcId );

// Connect to the IN stage input stream pipeline.
ConnectNamedPipe( p->m_hInputWrite, NULL );

// Ok, now lets read and process our input stream.
for( ;; )
{
// Read a record from the primary input stream.
if( !p->m_pManager->PeekRecord( *p->m_pProcess, 0, &p->m_szInRecord ) )
{
#ifdef _PIPE_DIAG_MESSAGE_
cons.Write( "Read of stream: %d, failed", 0 );
#endif // _PIPE_DIAG_MESSAGE_
break;
}

#ifdef _PIPE_DIAG_MESSAGE_
cons.Write( "I have read the following: >%s<", ( LPCTSTR )p->m_szInRecord );
#endif // _PIPE_DIAG_MESSAGE_

const char *pszRecord = ( LPCTSTR )p->m_szInRecord;
do
{
// Copy the input record to the buffer we will pass the WriteFile().
int nIndex;
for( nIndex = 0; nIndex < ( _IO_BUFFSIZE_ - 2 ) && *pszRecord; ++nIndex )
{
szReadBuffer[ nIndex ] = *pszRecord;
++pszRecord;
}
szReadBuffer[ nIndex ] = 0;

// If its the end of the record, tag on the newline character.
if( !*pszRecord )
{
szReadBuffer[ nIndex ] = _NEWLINE_;
++nIndex;
szReadBuffer[ nIndex ] = 0;
}

#ifdef _PIPE_DIAG_MESSAGE_
cons.Write( "Writing: %s", szReadBuffer );
#endif // _PIPE_DIAG_MESSAGE_

if( !WriteFile( p->m_hInputWrite, szReadBuffer, ( DWORD )nIndex, &dwBytesWritten, NULL ) )
{
if( GetLastError() == ERROR_NO_DATA )
{
#ifdef _PIPE_DIAG_MESSAGE_
cons.Write( "The pipe is now closed!" );
#endif // _PIPE_DIAG_MESSAGE_
break;
}
else
{
DWORD dwRetCode = GetLastError();
CString szMessage;
FormatMsg( dwRetCode, &szMessage );
p->m_pManager->StageMessage( *( p->m_pProcess ), 27, _ERROR_, dwRetCode, ( LPCTSTR )szMessage );

p->RaiseError();
return( _RC_FAIL_ );
}
}

// A stream number of -2 identifies the STDOUT stream.
if( p->m_pStage->Trace() )
{
++dwRecCount;
p->m_pManager->TraceMessage( *( p->m_pProcess ), _TRACE_WRITE_, -2, dwRecCount, szReadBuffer );
}

// Ensure that the operating system commits the data just written to the pipe.
FlushFileBuffers( p->m_hInputWrite );

// We must wait here for the potential IN stage of the called pipeline to release the lock
// signalling that it has read and consumed the record that we have just written. This
// will ensure that CALLPIPE does not delay the records.

HANDLE hLock = ::CreateEvent( 0, TRUE, FALSE, ( LPCTSTR )p->m_szLock );
#ifdef _PIPE_DIAG_MESSAGE_
cons.Write( "Waiting for lock = %s", ( LPCTSTR )p->m_szLock );
#endif // _PIPE_DIAG_MESSAGE_

::WaitForSingleObject( hLock, INFINITE );
// Reset the lock.
::ResetEvent( hLock );
// Delete the handle.
::CloseHandle( hLock );

#ifdef _PIPE_DIAG_MESSAGE_
cons.Write( "Wait complete for lock = %s", ( LPCTSTR )p->m_szLock );
#endif // _PIPE_DIAG_MESSAGE_

// Determine if the target pipeline has terminated.
DWORD dwExitCode = 0;
GetExitCodeProcess( p->m_pi.hProcess, &dwExitCode );
if( dwExitCode != STILL_ACTIVE )
{
// Disconnect this stages' primary input stream.
p->m_pManager->SeverInStream( *p, 0 );
CloseHandle( p->m_hInputWrite );

#ifdef _PIPE_DIAG_MESSAGE_
cons.Write( "- done" );
#endif // _PIPE_DIAG_MESSAGE_

return( _RC_SUCCESS_ );
}
}
while( *pszRecord );

// Release the stage writing the record.
p->m_pManager->ConsumeRecord( *p->m_pProcess, 0 );
}

// Close the write end of the pipe, causing the input stage of the called pipeline to terminate
// as it will detect that its std input stream is at eof.
DisconnectNamedPipe( p->m_hInputWrite );
CloseHandle( p->m_hInputWrite );

#ifdef _PIPE_DIAG_MESSAGE_
cons.Write( "- done" );
#endif // _PIPE_DIAG_MESSAGE_

return( _RC_SUCCESS_ );
}
GeneralRe: CreateNamedPipe() Pin
Richard Andrew x641-Aug-11 13:23
professionalRichard Andrew x641-Aug-11 13:23 
GeneralRe: CreateNamedPipe() Pin
Member 38520241-Aug-11 13:30
Member 38520241-Aug-11 13:30 
GeneralRe: CreateNamedPipe() Pin
Richard Andrew x641-Aug-11 13:32
professionalRichard Andrew x641-Aug-11 13:32 
GeneralRe: CreateNamedPipe() Pin
Member 38520241-Aug-11 23:27
Member 38520241-Aug-11 23:27 
GeneralRe: CreateNamedPipe() Pin
Richard Andrew x641-Aug-11 13:34
professionalRichard Andrew x641-Aug-11 13:34 
GeneralRe: CreateNamedPipe() Pin
Member 38520242-Aug-11 3:16
Member 38520242-Aug-11 3:16 
AnswerRe: CreateNamedPipe() Pin
Richard Andrew x641-Aug-11 13:14
professionalRichard Andrew x641-Aug-11 13:14 
GeneralRe: CreateNamedPipe() Pin
Member 38520241-Aug-11 13:17
Member 38520241-Aug-11 13:17 
GeneralRe: CreateNamedPipe() Pin
Member 38520241-Aug-11 23:03
Member 38520241-Aug-11 23:03 
AnswerRe: CreateNamedPipe() Pin
Chuck O'Toole2-Aug-11 15:38
Chuck O'Toole2-Aug-11 15:38 
GeneralRe: CreateNamedPipe() Pin
Member 38520242-Aug-11 22:52
Member 38520242-Aug-11 22:52 
QuestionHow a to expose data of an application (.EXE) to a DLL on runtime? Pin
Arris741-Aug-11 3:17
Arris741-Aug-11 3:17 
AnswerRe: How a to expose data of an application (.EXE) to a DLL on runtime? Pin
«_Superman_»1-Aug-11 4:12
professional«_Superman_»1-Aug-11 4:12 
GeneralRe: How a to expose data of an application (.EXE) to a DLL on runtime? Pin
Arris741-Aug-11 6:20
Arris741-Aug-11 6:20 
GeneralRe: How a to expose data of an application (.EXE) to a DLL on runtime? Pin
«_Superman_»1-Aug-11 6:32
professional«_Superman_»1-Aug-11 6:32 
GeneralRe: How a to expose data of an application (.EXE) to a DLL on runtime? Pin
Arris742-Aug-11 1:43
Arris742-Aug-11 1:43 
GeneralRe: How a to expose data of an application (.EXE) to a DLL on runtime? Pin
Albert Holguin1-Aug-11 18:00
professionalAlbert Holguin1-Aug-11 18:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.