Updated: July 19, 2016

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.

  QUEUEHANDLE hQueue    


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


Indicates success.


The queue handle specified in hQueue is not valid.

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.

The following code example is included in Using Message Queuing.

For an example ofSee
Opening a destination queue to send or read messagesC/C++ Code Example: Opening a Queue

The following sample code shows how to close a subqueue.

HANDLE hQueue = NULL;  
PCWSTR wszRejectedOrdersQueue =   
hr = MQOpenQueue(wszRejectedOrdersQueue, MQ_RECEIVE_ACCESS,   
                                                          MQ_DENY_RECEIVE_SHARE, &hQueue);  
if (FAILED(hr))  
    return hr;  

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.

Message Queuing Functions

Community Additions