Code Samples In C/C++

A Message Server Thread

This Code Is Really Readable!

DWORD WINAPI Server( LPVOID Parameter )
{
Message = new QueueMessageClass() ;
Message->InitiateQueueTestMode( NULL , QueueMode, OutputFileName, FileMode) ;
MessageCode = RESP_NO_MESSAGE ;
while ( MessageCode != STATUS_SERVICE_STOPPED )
{
Message->ReceiveQueueMessage() ;
Message->GetMessageCode(&MessageCode) ;
if ( MessageCode != RESP_NO_MESSAGE )
{
PrintMessage("Server: ", Message) ;
Message->SendQueueMessage() ;
}
}
Message->TerminateQueueTestMode() ;
delete Message ;
}
The Queue Message Manager

Look At All The Message Details In This Code: Pointer Dereferencing, Record Fields.

void QueueMessageClass::ReceiveQueueMessage(void)
{
Message.MessageCode = RESP_NO_MESSAGE ;
if ( InputRealMode == QueueMode )
{
ReturnValue = PeekMessage(&InputMessage,NULL,0,0,PM_REMOVE) ;
if ( ReturnValue != 0 )
{
Message.MessageCode = (QueueMessageCodeType) InputMessage.message ;
Message.SourceID = (int) InputMessage.wParam ;
Message.DestinationID = (int) InputMessage.hwnd ;
switch( Message.MessageCode )
{
case CMD_START_SERVICE:
case CMD_PERFORM_SERVICE:
case CMD_STOP_SERVICE:
Message.MessageFields.CommandArgument = (int) InputMessage.lParam ;
break ;
case STATUS_SERVICE_STARTED:
case STATUS_SERVICE_STOPPED:
Message.MessageFields.StatusArgument = (int) InputMessage.lParam ;
break ;
case DATA_SERVICE_PERFORMED:
Message.MessageFields.DataArgument = (int) InputMessage.lParam ;
break ;
default:
break ;
}
}
else
Message.MessageCode = RESP_NO_MESSAGE ;
}
else
{
ReadQueueMessageFromFile( *InputFileStream ) ;
}
}
Return