The application programmer is responsible for calling MQeFieldsFree to deallocate the message handles.
#include <hmq.h> MQEINT32 MQeQMgrUnlockMsgs( MQEHSESS hSess, MQECHAR * pQMName, MQECHAR * pQName, MQEINT64 * pLockID, MQEHFIELDS pMsgs[], MQEINT32 nMsgs, MQEINT32 * pCompCode, MQEINT32 * pReason)
This parameter must be specified.
If an entry in the pMsgs[] is a NULL, then this NULL entry is skipped and the unlock operation continues on to the next entry in the array. The unlock operation stops when it encounters an exception, and any remaining message object handles not processed are left as-is and remain locked on the queue.
Use the MQeFieldsFree() call to release MQeFields handles stored in this array.
#include <hmq.h> MQEHSESS hSess; MQEHFIELDS hFilter = MQEHANDLE_NULL; MQEINT32 i, n, nMsgs; MQEINT32 compcode; MQEINT32 reason; MQEBMO bmo = MQEBMO_DEFAULT; MQEHFIELDS pMsgs[2]; MQECHAR *qm, *q; qm = "MyQM"; q = "QQ"; hSess = MQeInitialize("MyAppsName", &compcode, &reason); nMsgs = 2; /* Set the browse option for lock and confirm */ bmo.Option = MQE_QMGR_BROWSE_LOCK | MQE_QMGR_CONFIRMID; /* Set the confirm ID */ bmo.ConfirmId.hi = bmo.ConfirmId.lo = 0x12345678; /*--------------------------------------*/ /* Browse and Unlock */ /*--------------------------------------*/ /* Browse nMsgs at a time until no messages are left */ while (1) { /* do forever */ /* Browse the nMsgs matching messages */ n = MQeQMgrBrowseMsgs( hSess, qm, q, &bmo, hFilter, pMsgs, nMsgs, &compcode, &reason); if (n==0) { /* Any resources held by the cookie has been released already */ break; } for(i=0; i<n; i++) { /******************************************/ /* Process the message objects in pMsgs[] */ /******************************************/ } /* Delete the n locked messages in pMsgs[] */ MQeQMgrUnlockMsgs( hSess, qm, q, bmo.LockId, pMsgs, n, &compcode, &reason); /* free pMsgs[] handle resources */ for(i=0; i<n; i++) { MQeFieldsFree(hSess, pMsgs[i], &compcode, &reason); } }; MQeTerminate(hSess, &compcode, &reason);