#import "mqoa.dll"no_namespace// MSMQ COM object
#import "..\bin\GraphObj.dll" no_namespace// Point and Line object
#include <stdio.h>
#include <tchar.h>
#include <iostream.h>
#include <mq.h>
#include "../GraphObj/GraphObj_i.c" // For IID_IPoint and IID_ILine
#include "../QueueDef.h"
// 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
IMSMQQueueInfosPtrpQueueInfos;
IMSMQQueueInfoPtrpQueueInfo;
IMSMQQueuePtrpQueue;
IUnknownPtrpIUnknown;
// Instanciate the follwing ActiveX components
IMSMQQueryPtrpQuery(__uuidof(MSMQQuery));
IMSMQMessagePtrpMessage(__uuidof(MSMQMessage));
ILinePtrpLine(__uuidof(Line));
IPointPtrpPoint(__uuidof(Point));
intn = 1;
_variant_tvarQueueNameInit(STR_QUEUE_LABEL);
VARIANTvarQueueName;
cout << "\n\nMSMQ IPersistStream Test\n";
cout << "==========================\n\n";
varQueueName = varQueueNameInit.Detach();
// Find the queue
pQueueInfos = pQuery->LookupQueue(&vtMissing, &vtMissing, &varQueueName);
varQueueNameInit.Attach(varQueueName);
pQueueInfos->Reset();
if ((pQueueInfo = pQueueInfos->Next()) == NULL) {
// The queue was not found create it on the local system
pQueueInfo = new IMSMQQueueInfoPtr( __uuidof(MSMQQueueInfo) );
pQueueInfo->PathName = STR_QUEUE_NAME;
pQueueInfo->Label = STR_QUEUE_LABEL;
pQueueInfo->Create();
cout << "\nNew Queue created\n";
}
cout << "Which object should be send ?\n";
cout << "1 - Point\n";
cout << "2 - Line\n";
cout << ":";
cin >> n;
// Open the queue
pQueue = pQueueInfo->Open(MQ_SEND_ACCESS, MQ_DENY_NONE);
if (n == 1) {
// Initialize point object
pPoint->x = 8;
pPoint->y = 9;
pMessage->Body = static_cast<IUnknown*>(pPoint); // The message body gets the IUnknown pointer
}
else {
// Initialize line object
pLine->x1 = 1;
pLine->y1 = 2;
pLine->x2 = 3;
pLine->y2 = 4;
pMessage->Body = static_cast<IUnknown*>(pLine); // The message body gets the IUnknown pointer
}
cout << "Sending Object\n";
pMessage->Send(pQueue);
// Close the Queue
pQueue->Close();
} catch (_com_error& e) {
dump_com_error(e);
}
}