Hi. I'm trying out the MSMQ API using VC++ v6 on NT4. I have written the following code, and I seem to be managing to both open and peek at the queue, but I don't get intelligible responses when trying to display the message label and body...
Code:
void CReadMSMQDlg::OnRead()
{
HRESULT hr = S_OK;
IMSMQQueuePtr pQueue; // The pointer to the queue (contents level)
CString msg;
try
{
IMSMQQueueInfoPtr pInfo("MSMQ.MSMQQueueInfo"); // The pointer to the queue itself
pInfo->FormatName = "DIRECT=TCP:IPAddress\\QName";
// Open the queue for receive access
pQueue = pInfo->Open( MQ_PEEK_ACCESS, MQ_DENY_NONE );
IMSMQMessagePtr pMsg("MSMQ.MSMQMessage");
_variant_t vtTimeOut((long)1000); // 1 second until receive time-out
_variant_t bvtWantBody((bool)true); // Set to retrieve message body
// Read all the messages in queue until 1 second time-out
for( ;; )
{
pMsg = pQueue->Peek( &vtMissing, &bvtWantBody, &vtTimeOut );
if( pMsg == NULL )
{
msg.Format( "No messages on %s", pInfo->FormatName );
MessageBox( msg, NULL, MB_OK );
pQueue->Close();
pQueue = NULL;
break;
}
// Display the message label and body
msg.Format( "%s", pMsg->Label );
//msg.Format( "%s", pMsg->Body );
MessageBox( "DEBUG Label", msg, MB_OK );
}
}
catch( const _com_error& comerr )
{
hr = comerr.Error();
msg.Format( "Error Code = 0x%X", hr );
MessageBox( msg, "COM ERR", MB_OK );
msg.Format( "Error Description = %s", (WCHAR *)comerr.Description() );
MessageBox( msg, "COM ERR", MB_OK );
if( pQueue )
pQueue->Close();
}
}
From looking on MSDN, Label is supposed to be a string, but it doesn't display the message label I'd expect, and is just showing rubbish really. Also, MSDN says that the body variable is a 'variant', does anybody know how too handle this data type?
Thanks.