Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

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.

Copy Code
//
// 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