Platform SDK: Logon Authentication

Example Code: ReceiveMsg

//--------------------------------------------------------------------
//     Define ReceiveMsg()
//     Receives a message over the socket. The first DWORD in the 
//     message will be the message size. The remainder of the bytes 
//     will be the actual message. 

BOOL ReceiveMsg (SOCKET s, PBYTE pBuf, DWORD cbBuf, DWORD *pcbRead) 
{ 
DWORD cbRead; 
DWORD cbData; 

//--------------------------------------------------------------------
//      Find the length of the message 
 
if (!(ReceiveBytes (
     s, 
     (PBYTE)&cbData, 
     sizeof(cbData), 
     &cbRead))) 
{
     HandleError("Did not receive bytes from ReceiveBytes.");
}

//--------------------------------------------------------------------
//      Receive the full message 
 
if (!(ReceiveBytes (
     s, 
     pBuf, 
     cbData, 
     &cbRead)))
{
     HandleError("Did not read the message."); 
}

if (cbRead == cbData)
{
     *pcbRead = cbRead;
}
else
{
     HandleError("Message not read corretly.");
}
return(TRUE); 
} // end ReceiveMsg