MQCloseQueue

 

Applies To: Windows 10, Windows 7, Windows 8, Windows 8.1, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2, Windows Server Technical Preview, Windows Vista

The MQCloseQueue function closes a given queue or subqueue.

HRESULT APIENTRY MQCloseQueue(  
  QUEUEHANDLE hQueue    
);  

Parameters

hQueue

[in] The handle to the queue you want to close.

Return Values

MQ_OK

Indicates success.

MQ_ERROR_INVALID_HANDLE (0xC00E0007)

The queue handle specified in hQueue is not valid.

Remarks

When an application closes a queue, the queue handle becomes invalid, but the messages waiting in the queue remain in the queue. These include messages sent to the queue by the application closing the queue.

Closing a queue by calling MQCloseQueue does not close the cursors created for that queue.

Equivalent COM Method

When using COM components, you can close an open instance of a queue by calling MSMQQueue.Close.

Example Code

The following code example is included in Using Message Queuing.

For an example of See
Opening a destination queue to send or read messages C/C++ Code Example: Opening a Queue

The following sample code shows how to close a subqueue.

HANDLE hQueue = NULL;  
PCWSTR wszRejectedOrdersQueue =   
                                 "DIRECT=OS:mymachine\private$\orders;rejectedorders";  
hr = MQOpenQueue(wszRejectedOrdersQueue, MQ_RECEIVE_ACCESS,   
                                                          MQ_DENY_RECEIVE_SHARE, &hQueue);  
if (FAILED(hr))  
{  
    return hr;  
}  
…  
MQCloseQueue(hQueue);  
  

Requirements

Windows NT/2000/XP: Included in Windows NT 4.0 SP3 and later.

Windows 95/98/Me: Included in Windows 95 and later.

Header: Declared in Mq.h.

Library: Use Mqrt.lib.

See Also

Message Queuing Functions
MQOpenQueue