MAIN.CPP

#include "stdafx.h" 
#import "mqoa.dll" no_namespace // MSMQ COM object




#import "..\bin\GraphObj.dll" no_namespace// Point and Line object



// COM exception handler
void dump_com_error(_com_error &e)
{
_tprintf(_T("Oops - hit an error!\n"));
_tprintf(_T("\a\tCode = %08lx\n"), e.Error());
_tprintf(_T("\a\tCode meaning = %s\n"), e.ErrorMessage());
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
_tprintf(_T("\a\tSource = %s\n"), (LPCTSTR) bstrSource);
_tprintf(_T("\a\tDescription = %s\n"), (LPCTSTR) bstrDescription);
}


// Initialize OLE library
struct InitOle _init_InitOle_;



void main()
{
try {
// For these ActiveX components we need only smart interface pointer
IMSMQQueuePtrpQueue;
IMSMQMessagePtrpMessage;

// Instanciate the follwing ActiveX components
IMSMQQueueInfoPtrpQueueInfo(__uuidof(MSMQQueueInfo));

intn = 1;

cout << "\n\nMSMQ IPersistStream Test Object Receiver\n";
cout << "==========================================\n\n";


// Open the queue
pQueueInfo->PathName = ".\\IStreamTest";
try {
pQueue = pQueueInfo->Open(MQ_RECEIVE_ACCESS, MQ_DENY_NONE);
} catch (_com_error& e) {
if (e.Error() == MQ_ERROR_QUEUE_NOT_FOUND) {
cout << "\n\nERROR queue does not exist\n";
exit(-1);
} else
dump_com_error(e);
}

// Get the next message
pMessage = pQueue->Receive();

IPointPtrpPoint((IUnknown*)pMessage->Body);

// Check if it's a Point object
if (pPoint != NULL) {

cout << "\nGot a Point Object: " << pPoint->x << " " << pPoint->y << "\n";

}
else {
ILinePtrpLine((IUnknown*)pMessage->Body);

// Check if it's a Line object
if (pLine != NULL) {
cout << "\nGot a Line Object: " << pLine->x1 << " " << pLine->y1 << " " << pLine->x2 << " " << pLine->y2 << "\n";
}
else
cout << "\nUnknown Object !!!\n";
}
pQueue->Close();


} catch (_com_error& e) {
dump_com_error(e);
}
}