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

This example synchronously retrieves all messages from a known queue.

Copy Code
#include <windows.h>
#include <stdio.h> // for printf
#import "mqoa.dll" no_namespace


int main()
{


  ///////////////////////////////////////////////////////////
  // Initialize OLE
  /////////////////////////////////////////////////////////// 
  OleInitialize(NULL);
  
  // Set value of ReceiveTimout parameter.
  _variant_t vtReceiveTimeout;
  vtReceiveTimeout = (long)1000;
  
  
  try
  {
	IMSMQQueueInfoPtr qinfo("MSMQ.MSMQQueueInfo");
	IMSMQQueuePtr qRec;
	IMSMQMessagePtr msgRec("MSMQ.MSMQMessage");

	qinfo->PathName = ".\\testqueue"; 
	try
	{
	qinfo->Create();
}
	catch (_com_error comerr) 
	{
	HRESULT hr = comerr.Error();
	if (hr == MQ_ERROR_QUEUE_EXISTS)
	{
		printf("Opening existing queue.\n");
}
	else 
	{
		throw comerr;
}
};
  
  ////////////////////////////////////////////////////////////
  // Open queue to retrieve message.
  ////////////////////////////////////////////////////////////
  qRec = qinfo->Open(MQ_RECEIVE_ACCESS, MQ_DENY_NONE);
  
  
  ////////////////////////////////////////////////////////////
  // Retrieve messages from queue.
  ////////////////////////////////////////////////////////////
  msgRec = qRec->Receive(&vtMissing, &vtMissing,
&vtMissing, &vtReceiveTimeout);
  if (msgRec == NULL)
  {
	 printf("There are no messages in the queue.\n");
	 return 0;
  }
  
  while (msgRec != NULL)
  {
	 printf("Message removed from queue.\n");
	 msgRec = qRec->Receive(&vtMissing, &vtMissing,
&vtMissing, &vtReceiveTimeout);
  }
  printf("All messages are removed from the queue.\n");
  
  
  ////////////////////////////////////////////////////////////
  // Close queue.
  ////////////////////////////////////////////////////////////
  qRec->Close();
  return 0;
  
  }
  
  
  catch (_com_error comerr) 
  {
	HRESULT hr = comerr.Error();
	printf("unexpected error: %x\n", hr);
	exit(-1);  // failure
  }
}

See Also

500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at webmaster@systemmanager.forsenergy.ru to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.