Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The following code example creates a private queue on the local machine.
If a queue with the same pathname exists, an error message is displayed and no queue is created.
//
// MSMQ COM sample using smart pointer
//
// following sample code creates a private queue named "Q1"
//
#include <atlbase.h>
#include <mqoai.h>
// should include mqoa.lib to the projet
// mqoa.lib is under Public\SERVERS\OAK\LIB\X86\RETAIL
//#import "mqoa.dll" no_namespace // not supported
HRESULT CreateQueueQ1()
{
CComQIPtr<IMSMQQueueInfo, &IID_IMSMQQueueInfo> ipQueueInfo;
HRESULT hr = S_OK;
// hr = ipQueueInfo.CoCreateInstance(CLSID_MSMQQueueInfo); // this form is not supported
hr = CoCreateInstance(
CLSID_MSMQQueueInfo,
NULL,
CLSCTX_SERVER,
IID_IMSMQQueueInfo,
(void**)(&ipQueueInfo.p));
if(hr != S_OK)
return hr;
hr = ipQueueInfo->put_PathName(L".\\private$\\Q1");
if(hr != S_OK)
return hr;
VARIANT vtFalse;
VariantInit(&vtFalse);
vtFalse.vt = VT_BOOL;
vtFalse.boolVal = FALSE;
hr = ipQueueInfo->Create(&vtFalse, &vtFalse);
return hr;
}
int main(int argc, WCHAR* argv[])
{
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if(hr == S_OK)
{
CreateQueueQ1();
CoUninitialize();
}
return 0;
}
See Also
MSMQ Application Development | MSMQ COM Support | Using the COM Components | MSMQ Security
Send Feedback on this topic to the authors