ActiveX objects can be invoked using Microsoft® Visual Basic®, C/C++, and VC5 with #import.
The following example shows how to create a queue using Visual Basic, VC5 with #import, and C.
dim qinfo as New MSMQQueueInfo
on error goto ErrHandler
qinfo.PathName = ".\queuename"
qinfo.Create
Exit Function
ErrHandler:
' handle Create error
Using VC5 with #import provides an easy-to-use syntax that is similar to the syntax provided by Visual Basic. This syntax provides:
#import "mqoa.dll;
try {
IMSMQQueueInfoPtr pqinfo ("MSMQ.MSMQQueueInfo");
pqinfo->PutPathName (L".\queuename");
//
// Create non-transactional, non-world-readable queue.
//
pqinfo->Create();
catch (_com_error &e) {
// UNDONE: handle error.
}
}
IMSMQQueueInfo *pqinfo;
HRESULT hresult;
VARIANT varIsTransactional;
VARIANT varIsWorldReadable;
//
// Create MSMQQueueInfo object
//
hresult = CoCreateInstance(
CLSID_MSMQQueueInfo,
NULL, // punkOuter
CLSCTX_SERVER,
IID_IMSMQQueueInfo,
(LPVOID *)&pqinfo
);
if (SUCCEEDED(hresult)) {
// Set the PathName.
pqinfo->put_PathName(L".\queuename");
//
// specify if transactional
//
VariantInit(&varIsTransactional);
varIsTransactional.vt = VT_BOOL;
varIsTransactional.boolVal = MQ_TRANSACTIONAL_NONE;
VariantInit(&varIsWorldReadable);
varIsWorldReadable.vt = VT_BOOL;
varIsWorldReadable.boolVal = FALSE;
//
// create the queue
//
hresult = pqinfo->Create(&varIsTransactional,
&varIsWorldReadable);
//
// UNDONE: need to handle failure...
//
}