home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / msmqocm.cab / mainfrm.cpp < prev    next >
C/C++ Source or Header  |  1997-10-06  |  61KB  |  1,833 lines

  1. /* ************************************************************************ */
  2. /*                                                                          */
  3. /* Main file of the application MQ API test.                                */
  4. /*                                                                          */
  5. /* ************************************************************************ */
  6.  
  7. //
  8. // MainFrm.cpp : implementation of the CMainFrame class
  9. //
  10.  
  11. #include "stdafx.h"
  12. #include "MQApitst.h"
  13. #include <afxtempl.h>
  14.  
  15. #include "MainFrm.h"
  16. #include "CrQDlg.h"
  17. #include "DelQDlg.h"
  18. #include "OpenQDlg.h"
  19. #include "ClosQDlg.h"
  20. #include "SendMDlg.h"
  21. #include "RecvMDlg.h"
  22. #include "RecWDlg.h"
  23. #include "LocatDlg.h"
  24.  
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30.  
  31. LPSTR UnicodeStringToAnsiString(LPCWSTR lpcsUnicode)
  32. {
  33.     LPSTR lpAnsiString = NULL;
  34.  
  35.     if (lpcsUnicode)
  36.     {
  37.         DWORD dwSize = wcstombs(NULL, lpcsUnicode, 0);
  38.         lpAnsiString = new char[dwSize+1];
  39.         size_t rc = wcstombs(lpAnsiString, lpcsUnicode, dwSize);
  40.         ASSERT(rc != (size_t)(-1));
  41.         lpAnsiString[dwSize] = '\0';
  42.     }
  43.  
  44.     return lpAnsiString;
  45. }
  46.  
  47. void AnsiStringToUnicode(LPWSTR lpsUnicode, LPSTR  lpsAnsi, DWORD  nSize)
  48. {
  49.     if (lpsUnicode == NULL)
  50.     {
  51.         return;
  52.     }
  53.  
  54.     ASSERT(lpsAnsi != NULL);
  55.  
  56.     size_t rc = mbstowcs(lpsUnicode, lpsAnsi, nSize);
  57.     ASSERT(rc != (size_t)(-1));
  58.     if (lpsUnicode[nSize-1] != L'\0')
  59.         lpsUnicode[nSize] = L'\0';
  60. }
  61.  
  62. #ifdef UNICODE
  63. #define _mqscpy(dest, src)  wcscpy(dest, src)
  64. #else
  65. #define _mqscpy(dest, src)  AnsiStringToUnicode(dest, src, _tcslen(src)+1)
  66. #endif
  67.  
  68. BOOL GetTextualSid(
  69.     PSID pSid,          // binary SID
  70.     LPTSTR TextualSID,   // buffer for textual representation of SID
  71.     LPDWORD dwBufferLen // required/provided TextualSid buffersize
  72.     )
  73. {
  74.     PSID_IDENTIFIER_AUTHORITY psia;
  75.     DWORD dwSubAuthorities;
  76.     DWORD dwSidRev=SID_REVISION;
  77.     DWORD dwCounter;
  78.     DWORD dwSidSize;
  79.  
  80.     // obtain SidIdentifierAuthority
  81.     psia=&((SID *)pSid)->IdentifierAuthority;
  82.  
  83.     // obtain sidsubauthority count
  84.     dwSubAuthorities=(DWORD)((SID *)pSid)->SubAuthorityCount;
  85.  
  86.     //
  87.     // compute buffer length
  88.     // S-SID_REVISION- + identifierauthority- + subauthorities- + NULL
  89.     //
  90.     dwSidSize = (15 + 12 + (12 * dwSubAuthorities) + 1) * sizeof(TCHAR);
  91.  
  92.     //
  93.     // check provided buffer length.
  94.     // If not large enough, indicate proper size and setlasterror
  95.     //
  96.     if (*dwBufferLen < dwSidSize)
  97.     {
  98.         *dwBufferLen = dwSidSize;
  99.         SetLastError(ERROR_INSUFFICIENT_BUFFER);
  100.         return FALSE;
  101.     }
  102.  
  103.     //
  104.     // prepare S-SID_REVISION-
  105.     //
  106.     TextualSID += _stprintf(TextualSID, TEXT("S-%lu-"), dwSidRev );
  107.  
  108.     //
  109.     // prepare SidIdentifierAuthority
  110.     //
  111.     if ( (psia->Value[0] != 0) || (psia->Value[1] != 0) )
  112.     {
  113.         TextualSID += _stprintf(TextualSID,
  114.                     TEXT("0x%02hx%02hx%02hx%02hx%02hx%02hx"),
  115.                     (USHORT)psia->Value[0],
  116.                     (USHORT)psia->Value[1],
  117.                     (USHORT)psia->Value[2],
  118.                     (USHORT)psia->Value[3],
  119.                     (USHORT)psia->Value[4],
  120.                     (USHORT)psia->Value[5]);
  121.     }
  122.     else
  123.     {
  124.         TextualSID += _stprintf(TextualSID, TEXT("%lu"),
  125.                     (ULONG)(psia->Value[5]      )   +
  126.                     (ULONG)(psia->Value[4] <<  8)   +
  127.                     (ULONG)(psia->Value[3] << 16)   +
  128.                     (ULONG)(psia->Value[2] << 24)   );
  129.     }
  130.  
  131.     //
  132.     // loop through SidSubAuthorities
  133.     //
  134.     for (dwCounter=0 ; dwCounter < dwSubAuthorities ; dwCounter++)
  135.     {
  136.         TextualSID += _stprintf(TextualSID, TEXT("-%lu"),
  137.                     ((SID *)pSid)->SubAuthority[ dwCounter] );
  138.     }
  139.  
  140.     return TRUE;
  141. }
  142.  
  143. /////////////////////////////////////////////////////////////////////////////
  144. // CMainFrame
  145.  
  146. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  147.  
  148. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  149.    //{{AFX_MSG_MAP(CMainFrame)
  150.    ON_WM_CREATE()
  151.    ON_COMMAND(ID_API_CREATE_QUEUE, OnApiCreateQueue)
  152.    ON_COMMAND(ID_API_DELETE_QUEUE, OnApiDeleteQueue)
  153.    ON_COMMAND(ID_API_OPEN_QUEUE, OnApiOpenQueue)
  154.    ON_COMMAND(ID_API_CLOSE_QUEUE, OnApiCloseQueue)
  155.    ON_COMMAND(ID_API_SEND_MESSAGE, OnApiSendMessage)
  156.    ON_COMMAND(ID_API_RECEIVE_MESSAGE, OnApiReceiveMessage)
  157.    ON_COMMAND(ID_API_LOCATE, OnApiLocate)
  158.    //}}AFX_MSG_MAP
  159. END_MESSAGE_MAP()
  160.  
  161. static UINT indicators[] =
  162. {
  163.    ID_SEPARATOR,           // status line indicator
  164.    ID_INDICATOR_CAPS,
  165.    ID_INDICATOR_NUM,
  166.    ID_INDICATOR_SCRL,
  167. };
  168.  
  169. /////////////////////////////////////////////////////////////////////////////
  170. // CMainFrame construction/destruction
  171.  
  172. CMainFrame::CMainFrame()
  173. {
  174.    // TODO: add member initialization code here.
  175. }
  176.  
  177. CMainFrame::~CMainFrame()
  178. {
  179. }
  180.  
  181. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  182. {
  183.     if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  184.         return -1;
  185.  
  186.     if (!m_wndToolBar.Create(this) ||
  187.         !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  188.     {
  189.         TRACE0("Failed to create toolbar\n");
  190.         return -1;      // fail to create
  191.     }
  192.  
  193.     if (!m_wndStatusBar.Create(this) ||
  194.         !m_wndStatusBar.SetIndicators(indicators,
  195.         sizeof(indicators)/sizeof(UINT)))
  196.     {
  197.         TRACE0("Failed to create status bar\n");
  198.         return -1;      // fail to create
  199.     }
  200.  
  201.     // TODO: Remove this if you don't want tool tips or a resizeable toolbar
  202.     m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
  203.         CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  204.  
  205.     // TODO: Delete these three lines if you don't want the toolbar to
  206.     //  be dockable
  207.     m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  208.     EnableDocking(CBRS_ALIGN_ANY);
  209.     DockControlBar(&m_wndToolBar);
  210.  
  211.     return 0;
  212. }
  213.  
  214. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  215. {
  216.     // TODO: Modify the Window class or styles here by modifying
  217.     //  the CREATESTRUCT cs
  218.  
  219.     return CFrameWnd::PreCreateWindow(cs);
  220. }
  221.  
  222. /////////////////////////////////////////////////////////////////////////////
  223. // CMainFrame diagnostics
  224.  
  225. #ifdef _DEBUG
  226. void CMainFrame::AssertValid() const
  227. {
  228.     CFrameWnd::AssertValid();
  229. }
  230.  
  231. void CMainFrame::Dump(CDumpContext& dc) const
  232. {
  233.     CFrameWnd::Dump(dc);
  234. }
  235.  
  236. #endif //_DEBUG
  237.  
  238. /////////////////////////////////////////////////////////////////////////////
  239. // CMainFrame message handlers
  240.  
  241. #define MAXINDEX 31
  242.  
  243.  
  244. /* ************************************************************************ */
  245. /*                        RemoveFromPathNameArray                           */
  246. /* ************************************************************************ */
  247. /* This function goes through the PathName Array and compares the given     */
  248. /* PathName to the PathName's of the items in the array.                    */
  249. /* If a match is found the item is removed from the array and the function  */
  250. /* returns a pointer to the item, otherwise a NULL pointer is returned.     */
  251. /* ************************************************************************ */
  252. ARRAYQ* CMainFrame::RemoveFromPathNameArray(TCHAR szPathName[MAX_Q_PATHNAME_LEN])
  253. {
  254.     int Index;
  255.     int MaxIndex = m_PathNameArray.GetSize();
  256.     ARRAYQ* pQueue;
  257.  
  258.     //
  259.     // Loop through the PathName array.
  260.     //
  261.     for (Index=0; Index<MaxIndex; Index++)
  262.     {
  263.         if (_tcscmp(szPathName, m_PathNameArray[Index]->szPathName) == 0)
  264.         {
  265.             //
  266.             // Found a match.
  267.             //
  268.             pQueue = m_PathNameArray[Index];
  269.             m_PathNameArray.RemoveAt(Index);
  270.             return pQueue;
  271.         }
  272.     }
  273.     return NULL; // ERROR - no match was found.
  274. }
  275.  
  276. /* ************************************************************************ */
  277. /*                             CleanPathNameArray                           */
  278. /* ************************************************************************ */
  279. /* This function goes through the PathName array and deletes all the items  */
  280. /* in it. the function frees the allocated memory.                          */
  281. /* ************************************************************************ */
  282. void CMainFrame::CleanPathNameArray()
  283. {
  284.     ARRAYQ* pQueue;
  285.  
  286.     while (m_PathNameArray.GetSize() > 0)
  287.     {
  288.         pQueue = m_PathNameArray[0];
  289.         m_PathNameArray.RemoveAt(0);
  290.         delete pQueue;
  291.     }
  292. }
  293.  
  294. /* ************************************************************************ */
  295. /*                        RemoveFromOpenedQueuePathNameArray                */
  296. /* ************************************************************************ */
  297. /* This function goes through the OpenedPathName Array and compares the     */
  298. /* given PathName to the PathName's of the items in the array.              */
  299. /* If a match is found the item is removed from the array and the function  */
  300. /* returns a pointer to the item, otherwise a NULL pointer is returned.     */
  301. /* ************************************************************************ */
  302. ARRAYQ* CMainFrame::RemoveFromOpenedQueuePathNameArray(TCHAR szPathName[MAX_Q_PATHNAME_LEN])
  303. {
  304.     int Index;
  305.     int MaxIndex = m_OpenedQueuePathNameArray.GetSize();
  306.     ARRAYQ* pQueue;
  307.  
  308.     //
  309.     // Loop through the OpenedPathName array.
  310.     //
  311.     for (Index=0; Index<MaxIndex; Index++)
  312.     {
  313.         if (_tcscmp(szPathName, m_OpenedQueuePathNameArray[Index]->szPathName) == 0)
  314.         {
  315.             //
  316.             // Found a match.
  317.             //
  318.             pQueue = m_OpenedQueuePathNameArray[Index];
  319.             m_OpenedQueuePathNameArray.RemoveAt(Index);
  320.             return pQueue;
  321.         }
  322.     }
  323.     return NULL; // ERROR - no match was found.
  324. }
  325.  
  326. /* ************************************************************************ */
  327. /*                           IsOpenedQueueArrayEmpty                        */
  328. /* ************************************************************************ */
  329. /* This function checks if the size of the OpenedPathName array is zero or  */
  330. /* less and if so it returns TRUE otherwise it returns FALSE.               */
  331. /* ************************************************************************ */
  332. BOOL CMainFrame::IsOpenedQueueArrayEmpty()
  333. {
  334.     if (m_OpenedQueuePathNameArray.GetSize() <= 0)
  335.     {
  336.         return TRUE;
  337.     }
  338.     else
  339.     {
  340.         return FALSE;
  341.     }
  342. }
  343.  
  344. /* ************************************************************************ */
  345. /*                        MoveToOpenedQueuePathNameArray                    */
  346. /* ************************************************************************ */
  347. /* This function moves an item from the PathName array to the               */
  348. /* OpenedPathName array. also it updates the hadle and the access rights    */
  349. /* to the moved queue.                                                      */
  350. /* ************************************************************************ */
  351. void CMainFrame::MoveToOpenedQueuePathNameArray(TCHAR szPathName[MAX_Q_PATHNAME_LEN],
  352.                                                 QUEUEHANDLE hQueue, DWORD dwAccess)
  353. {
  354.     ARRAYQ* pQueue;
  355.  
  356.     pQueue = RemoveFromPathNameArray(szPathName);
  357.     pQueue->hHandle = hQueue;                     // add Queue Handle.
  358.     pQueue->dwAccess = dwAccess;                  // add Queue Access rights.
  359.     Add2OpenedQueuePathNameArray(pQueue);
  360. }
  361.  
  362. /* ************************************************************************ */
  363. /*                              MoveToPathNameArray                         */
  364. /* ************************************************************************ */
  365. /* This function moves an item from the OpenedPathName array to the         */
  366. /* PathName array.                                                          */
  367. /* ************************************************************************ */
  368. void CMainFrame::MoveToPathNameArray(TCHAR szPathName[MAX_Q_PATHNAME_LEN])
  369. {
  370.     ARRAYQ* pQueue;
  371.  
  372.     pQueue = RemoveFromOpenedQueuePathNameArray(szPathName);
  373.     Add2PathNameArray(pQueue);
  374. }
  375.  
  376. /* ************************************************************************ */
  377. /*                             UpdatePathNameArrays                         */
  378. /* ************************************************************************ */
  379. /* This function goes through the Opened Queue PathName array and for every */
  380. /* item in it, it checkes if the item is found in the PathName array as     */
  381. /* well, if so the function removes the item from the PathName array.       */
  382. /* ************************************************************************ */
  383. void CMainFrame::UpdatePathNameArrays()
  384. {
  385.     int PathNameIndex;
  386.     int OpenedPathNameIndex;
  387.     int MaxPathNameIndex = m_PathNameArray.GetSize();
  388.     int MaxOpenedPathNameIndex = m_OpenedQueuePathNameArray.GetSize();
  389.     ARRAYQ* pQueue;
  390.  
  391.     //
  392.     // Loop through the OpenedPathName array.
  393.     //
  394.     for (OpenedPathNameIndex=0; OpenedPathNameIndex<MaxOpenedPathNameIndex; OpenedPathNameIndex++)
  395.     {
  396.         for (PathNameIndex=0; PathNameIndex<MaxPathNameIndex; PathNameIndex++)
  397.         {
  398.             if (_tcscmp(m_OpenedQueuePathNameArray[OpenedPathNameIndex]->szPathName,
  399.                 m_PathNameArray[PathNameIndex]->szPathName) == 0)
  400.             {
  401.                 //
  402.                 // Found a match, remove it from PathName Array.
  403.                 //
  404.                 pQueue = m_PathNameArray[PathNameIndex];
  405.                 m_PathNameArray.RemoveAt(PathNameIndex);
  406.                 delete pQueue;
  407.                 //
  408.                 // get out of inner for loop.
  409.                 //
  410.                 break;
  411.             }
  412.         }
  413.     }
  414. }
  415.  
  416.  
  417. /* ************************************************************************ */
  418. /*                              GetQueueHandle                              */
  419. /* ************************************************************************ */
  420. /* This function goes through the OpenedPathName array and retrieve the     */
  421. /* Handle to the queue which matches the given PathName. If no match was    */
  422. /* found the function returns FALSE.                                        */
  423. /* ************************************************************************ */
  424. BOOL CMainFrame::GetQueueHandle(TCHAR szPathName[MAX_Q_PATHNAME_LEN],
  425.                                 QUEUEHANDLE* phClosedQueueHandle)
  426. {
  427.     int Index;
  428.     int MaxIndex = m_OpenedQueuePathNameArray.GetSize();
  429.     ARRAYQ* pQueue;
  430.  
  431.     //
  432.     // Loop through the OpenedPathName array.
  433.     //
  434.     for (Index=0; Index<MaxIndex; Index++)
  435.     {
  436.         if (_tcscmp(szPathName, m_OpenedQueuePathNameArray[Index]->szPathName) == 0)
  437.         {
  438.             //
  439.             // Found a match.
  440.             //
  441.             pQueue = m_OpenedQueuePathNameArray[Index];
  442.             *phClosedQueueHandle = pQueue->hHandle;
  443.             return TRUE;
  444.         }
  445.     }
  446.     return FALSE; // ERROR - no match was found.
  447. }
  448.  
  449. /* ************************************************************************ */
  450. /*                       TranslatePathNameToFormatName                      */
  451. /* ************************************************************************ */
  452. /* This function goes through the PathName array and retrieve the           */
  453. /* FormatName to the queue which matches the given PathName. If no match    */
  454. /* was found the function returns FALSE.                                    */
  455. /* ************************************************************************ */
  456. BOOL CMainFrame::TranslatePathNameToFormatName(TCHAR szPathName[MAX_Q_PATHNAME_LEN],
  457.                                                TCHAR szFormatName[MAX_Q_FORMATNAME_LEN])
  458. {
  459.     int Index;
  460.     int MaxIndex = m_PathNameArray.GetSize();
  461.     ARRAYQ* pQueue;
  462.  
  463.     //
  464.     // Loop through the PathName array.
  465.     //
  466.     for (Index=0; Index<MaxIndex; Index++)
  467.     {
  468.         if (_tcscmp(szPathName, m_PathNameArray[Index]->szPathName) == 0)
  469.         {
  470.             //
  471.             // Found a match.
  472.             //
  473.             pQueue = m_PathNameArray[Index];
  474.             _tcsncpy (szFormatName, pQueue->szFormatName, MAX_Q_FORMATNAME_LEN);
  475.             return TRUE;
  476.         }
  477.     }
  478.     return FALSE; // ERROR - no match was found.
  479. }
  480.  
  481. /* ************************************************************************ */
  482. /*                  TranslateOpenedQueuePathNameToFormatName                */
  483. /* ************************************************************************ */
  484. /* This function goes through the OpenedPathName array and retrieve the     */
  485. /* FormatName to the queue which matches the given PathName. If no match    */
  486. /* was found the function returns FALSE.                                    */
  487. /* ************************************************************************ */
  488. BOOL CMainFrame::TranslateOpenedQueuePathNameToFormatName(
  489.     TCHAR szPathName[MAX_Q_PATHNAME_LEN],
  490.     TCHAR szFormatName[MAX_Q_FORMATNAME_LEN]
  491.     )
  492. {
  493.     int Index;
  494.     int MaxIndex = m_OpenedQueuePathNameArray.GetSize();
  495.     ARRAYQ* pQueue;
  496.  
  497.     //
  498.     // Loop through the OpenedPathName array.
  499.     //
  500.     for (Index=0; Index<MaxIndex; Index++)
  501.     {
  502.         if (_tcscmp(szPathName, m_OpenedQueuePathNameArray[Index]->szPathName) == 0)
  503.         {
  504.             //
  505.             // Found a match.
  506.             //
  507.             pQueue = m_OpenedQueuePathNameArray[Index];
  508.             _tcsncpy (szFormatName, pQueue->szFormatName, MAX_Q_FORMATNAME_LEN);
  509.             return TRUE;
  510.         }
  511.     }
  512.     return FALSE; // ERROR - no match was found.
  513. }
  514.  
  515.  
  516. /* ************************************************************************ */
  517. /*                         DisplayPathNameArray                             */
  518. /* ************************************************************************ */
  519. /* This function goes through the PathName Array and prints it to screen.   */
  520. /* ************************************************************************ */
  521. void CMainFrame::DisplayPathNameArray()
  522. {
  523.     int Index;
  524.     int MaxIndex = m_PathNameArray.GetSize();
  525.     TCHAR szMsgBuffer[BUFFERSIZE];
  526.  
  527.     _stprintf(szMsgBuffer, TEXT("   Located Queues Path Name :"));
  528.     PrintToScreen(szMsgBuffer);
  529.     //
  530.     // Loop through the PathName array.
  531.     //
  532.     for (Index=0; Index<MaxIndex; Index++)
  533.     {
  534.         //
  535.         // Print the PathNames.
  536.         //
  537.         _stprintf(szMsgBuffer, TEXT("\t%d. %s"),Index+1, m_PathNameArray[Index]->szPathName);
  538.         PrintToScreen(szMsgBuffer);
  539.     }
  540. }
  541.  
  542. /* ************************************************************************ */
  543. /*                    DisplayOpenedQueuePathNameArray                       */
  544. /* ************************************************************************ */
  545. /* This function goes through the Opened Queues PathName Array and          */
  546. /* prints it to screen.                                                     */
  547. /* ************************************************************************ */
  548. void CMainFrame::DisplayOpenedQueuePathNameArray()
  549. {
  550.     int Index;
  551.     int MaxIndex = m_OpenedQueuePathNameArray.GetSize();
  552.     TCHAR szMsgBuffer[BUFFERSIZE];
  553.  
  554.     _stprintf(szMsgBuffer, TEXT("   Currently Opened Queues Path Names:"));
  555.     PrintToScreen(szMsgBuffer);
  556.     //
  557.     // Loop through the OpenedQueuePathName array.
  558.     //
  559.     for (Index=0; Index<MaxIndex; Index++)
  560.     {
  561.         //
  562.         // Print the PathNames.
  563.         //
  564.         _stprintf(szMsgBuffer, TEXT("\t%d. %s"),Index+1, m_OpenedQueuePathNameArray[Index]->szPathName);
  565.         PrintToScreen(szMsgBuffer);
  566.     }
  567. }
  568.  
  569. /* ************************************************************************ */
  570. /*                          GetMsgClassStatus                               */
  571. /* ************************************************************************ */
  572. /* This function sets proper status string based on a given MQMSG class.    */
  573. /* ************************************************************************ */
  574.  
  575. struct
  576. {
  577.     unsigned short    mclass;
  578.     LPTSTR          pszDescription;
  579. } StringClass[] =
  580.   {
  581.     { MQMSG_CLASS_NORMAL, TEXT("The Message was received successfully.")},
  582.     { MQMSG_CLASS_ACK_REACH_QUEUE, TEXT("The REACH QUEUE ACK Message was read successfully.")},
  583.     { MQMSG_CLASS_ACK_RECEIVE, TEXT("The RECEIVE ACK Message was read successfully.")},
  584.     { MQMSG_CLASS_NACK_BAD_DST_Q, TEXT("The DESTINATION QUEUE HANDLE INVALID Nack Message was read successfully.")},
  585.     { MQMSG_CLASS_NACK_RECEIVE_TIMEOUT, TEXT("The TIME TO RECEIVE EXPIRED Nack Message was read successfully.")},
  586.     { MQMSG_CLASS_NACK_REACH_QUEUE_TIMEOUT, TEXT("The TIME TO REACH QUEUE EXPIRED Nack Message was read successfully.")},
  587.     { MQMSG_CLASS_NACK_Q_EXCEED_QUOTA, TEXT("The QUEUE IS FULL Nack Message was read successfully.")},
  588.     { MQMSG_CLASS_NACK_ACCESS_DENIED, TEXT("The SENDER HAVE NO SEND ACCESS RIGHTS ON QUEUE Nack Message was read successfully.")},
  589.     { MQMSG_CLASS_NACK_HOP_COUNT_EXCEEDED, TEXT("The HOP COUNT EXCEEDED Nack Message was read successfully.")},
  590.     { MQMSG_CLASS_NACK_BAD_SIGNATURE, TEXT("The MESSAGE RECEIVED WITH BAD SIGNATURE Nack Message was read successfully.")},
  591.     { MQMSG_CLASS_NACK_BAD_ENCRYPTION, TEXT("The MSG COULD NOT DECRYPTED Nack Message was read successfully.")},
  592.     { MQMSG_CLASS_NACK_COULD_NOT_ENCRYPT, TEXT("The SOURCE QM COULD NOT ENCRYPT MSG FOR DEST QM Nack Message was read successfully.")},
  593.     { 0, NULL}
  594.   };
  595.     
  596. void CMainFrame::ClassToString(unsigned short MsgClass,LPTSTR pszStatus)
  597. {
  598.     //
  599.     // loop the StringClass array to find MsgClass
  600.     //
  601.     DWORD dwIndex = 0;
  602.     while (StringClass[dwIndex].pszDescription != NULL)
  603.     {
  604.         if (StringClass[dwIndex].mclass == MsgClass)
  605.         {
  606.             _stprintf(pszStatus,StringClass[dwIndex].pszDescription);
  607.             return;
  608.         }
  609.         dwIndex++;
  610.     }
  611.  
  612.     //
  613.     // MsgClass not found - print default error
  614.     //
  615.     _stprintf(pszStatus,TEXT("The NACK (0x%X) Message was read successfully."),MsgClass);
  616. }
  617.  
  618.  
  619. /* ************************************************************************ */
  620. /*                            OnApiCreateQueue                              */
  621. /* ************************************************************************ */
  622. /* This function opens a dialog box and asks the user for the queue's       */
  623. /* PathName and Label. Then it creates the specified queue.                 */
  624. /*                                                                          */
  625. /* Uses: MQCreateQueue.                                                     */
  626. /* ************************************************************************ */
  627. void CMainFrame::OnApiCreateQueue()
  628. {
  629.     // TODO: Add your command handler code here
  630.  
  631.     TCHAR szMsgBuffer[BUFFERSIZE];
  632.  
  633.     MQQUEUEPROPS QueueProps;
  634.     MQPROPVARIANT aVariant[MAXINDEX];
  635.     QUEUEPROPID aPropId[MAXINDEX];
  636.     DWORD PropIdCount = 0;
  637.     HRESULT hr;
  638.  
  639.     PSECURITY_DESCRIPTOR pSecurityDescriptor;
  640.  
  641.     TCHAR szPathNameBuffer[MAX_Q_PATHNAME_LEN];
  642.     TCHAR szFormatNameBuffer[MAX_Q_FORMATNAME_LEN];
  643.     TCHAR szLabelBuffer[MAX_Q_PATHNAME_LEN];
  644.     DWORD dwFormatNameBufferLength = MAX_Q_FORMATNAME_LEN;
  645.  
  646.  
  647.     //
  648.     // Display CreateQueue Dialog.
  649.     //
  650.     CCreateQueueDialog CreateQueueDialog;
  651.  
  652.     if(CreateQueueDialog.DoModal() == IDCANCEL)
  653.     {
  654.         return;
  655.     }
  656.     CreateQueueDialog.GetPathName(szPathNameBuffer);
  657.     CreateQueueDialog.GetLabel(szLabelBuffer);
  658.  
  659.     //
  660.     // Get the input fields from the dialog box
  661.     // and prepare the property array PROPVARIANT
  662.     //
  663.  
  664.  
  665.     //
  666.     // Set the PROPID_Q_PATHNAME property
  667.     //
  668.     aPropId[PropIdCount] = PROPID_Q_PATHNAME;    //PropId
  669.     aVariant[PropIdCount].vt = VT_LPWSTR;        //Type
  670.     aVariant[PropIdCount].pwszVal = new WCHAR[MAX_Q_PATHNAME_LEN];
  671.     _mqscpy(aVariant[PropIdCount].pwszVal, szPathNameBuffer); //Value
  672.  
  673.     PropIdCount++;
  674.  
  675.     //
  676.     // Set the PROPID_Q_LABEL property
  677.     //
  678.     aPropId[PropIdCount] = PROPID_Q_LABEL;    //PropId
  679.     aVariant[PropIdCount].vt = VT_LPWSTR;     //Type
  680.     aVariant[PropIdCount].pwszVal = new WCHAR[MAX_Q_PATHNAME_LEN];
  681.     _mqscpy(aVariant[PropIdCount].pwszVal, szLabelBuffer); //Value
  682.  
  683.     PropIdCount++;
  684.  
  685.  
  686.     //
  687.     // Set the MQEUEUPROPS structure
  688.     //
  689.     QueueProps.cProp = PropIdCount;           //No of properties
  690.     QueueProps.aPropID = aPropId;             //Id of properties
  691.     QueueProps.aPropVar = aVariant;           //Value of properties
  692.     QueueProps.aStatus = NULL;                //No error reports
  693.  
  694.     //
  695.     // No security (default)
  696.     //
  697.     pSecurityDescriptor = NULL;
  698.  
  699.     //
  700.     // Create the queue
  701.     //
  702. #ifdef UNICODE
  703.     hr = MQCreateQueue(
  704.             pSecurityDescriptor,            //Security
  705.             &QueueProps,                    //Queue properties
  706.             szFormatNameBuffer,             //Output: Format Name
  707.             &dwFormatNameBufferLength       //Output: Format Name len
  708.             );
  709. #else
  710.     WCHAR szwFormatNameBuffer[MAX_Q_FORMATNAME_LEN];
  711.     hr = MQCreateQueue(
  712.             pSecurityDescriptor,            //Security
  713.             &QueueProps,                    //Queue properties
  714.             szwFormatNameBuffer,            //Output: Format Name
  715.             &dwFormatNameBufferLength       //Output: Format Name len
  716.             );
  717.  
  718.     if (SUCCEEDED(hr))
  719.     {
  720.         size_t rc =wcstombs(szFormatNameBuffer, szwFormatNameBuffer, dwFormatNameBufferLength);
  721.         ASSERT(rc != (size_t)(-1));
  722.     }
  723. #endif
  724.  
  725.     if (FAILED(hr))
  726.     {
  727.         //
  728.         // Error - display message
  729.         //
  730.         _stprintf(szMsgBuffer, TEXT("MQCreateQueue failed, Error code = 0x%x."),hr);
  731.         MessageBox(szMsgBuffer, TEXT("ERROR"), MB_OK);
  732.     }
  733.     else
  734.     {
  735.         //
  736.         // Success - write in edit control.
  737.         //
  738.         _stprintf(szMsgBuffer, TEXT("The queue %s was created successfully. ( FormatName: %s )"),
  739.             szPathNameBuffer, szFormatNameBuffer);
  740.         PrintToScreen(szMsgBuffer);
  741.  
  742.         //
  743.         // Add the new queue to the PathName Array.
  744.         //
  745.         ARRAYQ* pNewQueue = new ARRAYQ;
  746.         //
  747.         // Save PathName and FormatName in the ARRAYQ structure.
  748.         //
  749.         _tcsncpy (pNewQueue->szPathName, szPathNameBuffer, MAX_Q_PATHNAME_LEN);
  750.         _tcsncpy (pNewQueue->szFormatName, szFormatNameBuffer, MAX_Q_FORMATNAME_LEN);
  751.         Add2PathNameArray(pNewQueue);
  752.     }
  753.  
  754.     //
  755.     // Free allocated memory
  756.     //
  757.     delete   aVariant[0].pwszVal;
  758.     delete   aVariant[1].pwszVal;
  759. }
  760.  
  761. /* ************************************************************************ */
  762. /*                            OnApiDeleteQueue                              */
  763. /* ************************************************************************ */
  764. /* This function opens a dialog box and asks the user for the queue's       */
  765. /* PathName. then it deletes the specified queue.                           */
  766. /*                                                                          */
  767. /* Uses: MQDeleteQueue.                                                     */
  768. /* ************************************************************************ */
  769. void CMainFrame::OnApiDeleteQueue()
  770. {
  771.     // TODO: Add your command handler code here
  772.     TCHAR szPathNameBuffer[MAX_Q_PATHNAME_LEN];
  773.     TCHAR szFormatNameBuffer[MAX_Q_PATHNAME_LEN];
  774.     TCHAR szMsgBuffer[BUFFERSIZE];
  775.  
  776.     HRESULT hr;
  777.  
  778.     DWORD dwFormatNameBufferLength = MAX_Q_PATHNAME_LEN;
  779.  
  780.     CDeleteQueueDialog DeleteQueueDialog(&m_PathNameArray);
  781.  
  782.     //
  783.     // Display DeleteQueue Dialog.
  784.     //
  785.     if (DeleteQueueDialog.DoModal() == IDCANCEL)
  786.     {
  787.         return;
  788.     }
  789.  
  790.     DeleteQueueDialog.GetPathName(szPathNameBuffer);
  791.  
  792.     //
  793.     // Translate the path name to format name using the ARRAYQ arrays.
  794.     //
  795.     if (TranslatePathNameToFormatName(szPathNameBuffer, szFormatNameBuffer) == FALSE)
  796.     {
  797.         //
  798.         // Error - display message
  799.         //
  800.         _stprintf(szMsgBuffer, TEXT("Queue wasn't found"));
  801.         MessageBox(szMsgBuffer, TEXT("ERROR"), MB_OK);
  802.         return;
  803.     }
  804.  
  805.     //
  806.     // Delete the queue.
  807.     //
  808. #ifdef UNICODE
  809.     hr = MQDeleteQueue(szFormatNameBuffer);  // FormatName of the Queue to be deleted.
  810. #else
  811.     WCHAR szwFormatNameBuffer[MAX_Q_FORMATNAME_LEN];
  812.     size_t rc = mbstowcs(szwFormatNameBuffer, szFormatNameBuffer, _tcslen(szFormatNameBuffer)+1);
  813.     ASSERT(rc != (size_t)(-1));
  814.     hr = MQDeleteQueue(szwFormatNameBuffer);  // FormatName of the Queue to be deleted.
  815. #endif
  816.  
  817.     if (FAILED(hr))
  818.     {
  819.         //
  820.         // Error - display message
  821.         //
  822.         _stprintf(szMsgBuffer, TEXT("MQDeleteQueue failed, Error code = 0x%x."),hr);
  823.         MessageBox(szMsgBuffer, TEXT("ERROR"), MB_OK);
  824.     }
  825.     else
  826.     {
  827.         //
  828.         // Success - write in edit control
  829.         //
  830.         _stprintf(szMsgBuffer, TEXT("The queue %s was deleted successfully."), szPathNameBuffer);
  831.         PrintToScreen(szMsgBuffer);
  832.         //
  833.         // Delete the name from the Path Names array.
  834.         //
  835.         ARRAYQ* DeletedQueue = RemoveFromPathNameArray(szPathNameBuffer);
  836.         if (DeletedQueue != NULL)
  837.         {
  838.             delete DeletedQueue;
  839.         }
  840.     }
  841. }
  842.  
  843. /* ************************************************************************ */
  844. /*                             OnApiOpenQueue                               */
  845. /* ************************************************************************ */
  846. /* This function opens a dialog box and asks the user for the queue's       */
  847. /* PathName. then it opens the specified queue.                             */
  848. /*                                                                          */
  849. /* Uses: MQOpenQueue.                                                       */
  850. /* ************************************************************************ */
  851. void CMainFrame::OnApiOpenQueue()
  852. {
  853.     // TODO: Add your command handler code here
  854.     TCHAR szPathNameBuffer[MAX_Q_PATHNAME_LEN];
  855.     TCHAR szFormatNameBuffer[MAX_Q_PATHNAME_LEN];
  856.     TCHAR szAccessBuffer[50]; // BUGBUG - maybe set with a define
  857.     TCHAR szMsgBuffer[BUFFERSIZE];
  858.  
  859.     HRESULT hr;
  860.  
  861.     DWORD dwFormatNameBufferLength = MAX_Q_PATHNAME_LEN;
  862.     DWORD dwAccess;
  863.  
  864.     QUEUEHANDLE hQueue;
  865.  
  866.     COpenQueueDialog OpenQueueDialog(&m_PathNameArray);
  867.  
  868.     //
  869.     // Display the OpenQueue dialog.
  870.     //
  871.     if (OpenQueueDialog.DoModal() == IDCANCEL)
  872.     {
  873.         return;
  874.     }
  875.  
  876.     OpenQueueDialog.GetPathName(szPathNameBuffer);
  877.     dwAccess = OpenQueueDialog.GetAccess();
  878.     //
  879.     // Set the access buffer string.
  880.     //
  881.     switch (dwAccess)
  882.     {
  883.     case (MQ_RECEIVE_ACCESS | MQ_SEND_ACCESS):
  884.  
  885.         _tcscpy(szAccessBuffer, TEXT("MQ_RECEIVE_ACCESS, MQ_SEND_ACCESS."));
  886.         break;
  887.  
  888.     case MQ_RECEIVE_ACCESS:
  889.  
  890.         _tcscpy(szAccessBuffer, TEXT("MQ_RECEIVE_ACCESS."));
  891.         break;
  892.  
  893.     case MQ_SEND_ACCESS:
  894.  
  895.         _tcscpy(szAccessBuffer, TEXT("MQ_SEND_ACCESS."));
  896.         break;
  897.  
  898.     default:
  899.  
  900.         _tcscpy(szAccessBuffer, TEXT("NONE."));
  901.         break;
  902.     }
  903.  
  904.     //
  905.     // Translate the path name to format name using the ARRAYQ arrays.
  906.     //
  907.     if (TranslatePathNameToFormatName(szPathNameBuffer, szFormatNameBuffer) == FALSE)
  908.     {
  909.         //
  910.         // Error - display message
  911.         //
  912.         _stprintf(szMsgBuffer, TEXT("Queue wasn't found"));
  913.         MessageBox(szMsgBuffer, TEXT("ERROR"), MB_OK);
  914.         return;
  915.     }
  916.  
  917.     //
  918.     // Open the queue. (no sharing)
  919.     //
  920. #ifdef UNICODE
  921.     hr = MQOpenQueue(
  922.             szFormatNameBuffer,     // Format Name of the queue to be opened.
  923.             dwAccess,               // Access rights to the Queue.
  924.             0,                      // No receive Exclusive.
  925.             &hQueue                 // OUT: handle to the opened Queue.
  926.             );
  927. #else
  928.     WCHAR szwFormatNameBuffer[MAX_Q_FORMATNAME_LEN];
  929.     size_t rc = mbstowcs(szwFormatNameBuffer, szFormatNameBuffer, _tcslen(szFormatNameBuffer)+1);
  930.     ASSERT(rc != (size_t)(-1));
  931.  
  932.     hr = MQOpenQueue(
  933.             szwFormatNameBuffer,    // Format Name of the queue to be opened.
  934.             dwAccess,               // Access rights to the Queue.
  935.             0,                      // No receive Exclusive.
  936.             &hQueue                 // OUT: handle to the opened Queue.
  937.             );
  938. #endif
  939.  
  940.     if (FAILED(hr))
  941.     {
  942.         //
  943.         // Error - display message
  944.         //
  945.         _stprintf(szMsgBuffer, TEXT("MQOpenQueue failed, Error code = 0x%x."),hr);
  946.         MessageBox(szMsgBuffer, TEXT("ERROR"), MB_OK);
  947.     }
  948.     else
  949.     {
  950.         //
  951.         // Success - write in edit control
  952.         //
  953.         _stprintf(szMsgBuffer,
  954.             TEXT("The queue %s was opened successfully.\r\n\tQueueHandle: 0x%x\r\n\tQueue Access : %s"),
  955.             szPathNameBuffer,
  956.             hQueue,
  957.             szAccessBuffer);
  958.         PrintToScreen(szMsgBuffer);
  959.  
  960.         //
  961.         // move the queue to the opened queues array.
  962.         //
  963.         MoveToOpenedQueuePathNameArray(szPathNameBuffer, hQueue, dwAccess);
  964.     }
  965. }
  966.  
  967. /* ************************************************************************ */
  968. /*                            OnApiCloseQueue                               */
  969. /* ************************************************************************ */
  970. /* This function opens a dialog box and asks the user for the queue's       */
  971. /* PathName. then it closes the specified queue.                            */
  972. /*                                                                          */
  973. /* Uses: MQCloseQueue.                                                      */
  974. /* ************************************************************************ */
  975. void CMainFrame::OnApiCloseQueue()
  976. {
  977.     // TODO: Add your command handler code here
  978.  
  979.     TCHAR szPathNameBuffer[MAX_Q_PATHNAME_LEN];
  980.     TCHAR szMsgBuffer[BUFFERSIZE];
  981.  
  982.     HRESULT hr;
  983.  
  984.     DWORD dwFormatNameBufferLength = MAX_Q_PATHNAME_LEN;
  985.  
  986.     QUEUEHANDLE hClosedQueueHandle;
  987.  
  988.     //
  989.     // Display CloseQueue Dialog.
  990.     //
  991.     CCloseQueueDialog CloseQueueDialog(&m_OpenedQueuePathNameArray);
  992.  
  993.     if (CloseQueueDialog.DoModal() == IDCANCEL)
  994.     {
  995.         return;
  996.     }
  997.  
  998.     CloseQueueDialog.GetPathName(szPathNameBuffer);
  999.  
  1000.     //
  1001.     // Get the closed queue handle.
  1002.     //
  1003.     if (GetQueueHandle(szPathNameBuffer, &hClosedQueueHandle) == FALSE)
  1004.     {
  1005.         //
  1006.         // Error - display message
  1007.         //
  1008.         _stprintf(szMsgBuffer, TEXT("The Queue couldn't be closed since it was not opened before."));
  1009.         MessageBox(szMsgBuffer, TEXT("ERROR"), MB_OK);
  1010.         return;
  1011.     }
  1012.  
  1013.     //
  1014.     // Close the queue.
  1015.     //
  1016.     hr = MQCloseQueue(hClosedQueueHandle);   // the handle of the Queue to be closed.
  1017.     if (FAILED(hr))
  1018.     {
  1019.         //
  1020.         // Error - display message
  1021.         //
  1022.         _stprintf(szMsgBuffer, TEXT("MQCloseQueue failed, Error code = 0x%x."),hr);
  1023.         MessageBox(szMsgBuffer, TEXT("ERROR"), MB_OK);
  1024.     }
  1025.     else
  1026.     {
  1027.         //
  1028.         // Success - write in edit control
  1029.         //
  1030.         _stprintf(szMsgBuffer, TEXT("The queue %s was closed successfully."), szPathNameBuffer);
  1031.         PrintToScreen(szMsgBuffer);
  1032.         //
  1033.         // Move the queue form the opened queues array to the path name array.
  1034.         //
  1035.         MoveToPathNameArray(szPathNameBuffer);
  1036.     }
  1037. }
  1038.  
  1039. /* ************************************************************************ */
  1040. /*                            OnApiSendMessage                              */
  1041. /* ************************************************************************ */
  1042. /* This function opens a dialog box and asks the user for the queue's       */
  1043. /* PathName and some message properties. Then it sends the message to the   */
  1044. /* specified queue.                                                         */
  1045. /*                                                                          */
  1046. /* Uses: MQSendMessage.                                                     */
  1047. /* ************************************************************************ */
  1048.  
  1049. //
  1050. // two static buffers to hold the last message body and label for the next time.
  1051. //
  1052. TCHAR szLastMessageBody[BUFFERSIZE];
  1053. TCHAR szLastMessageLabel[BUFFERSIZE];
  1054.  
  1055. void CMainFrame::OnApiSendMessage()
  1056. {
  1057.     // TODO: Add your command handler code here
  1058.  
  1059.     TCHAR szPathNameBuffer[MAX_Q_PATHNAME_LEN];
  1060.     TCHAR szAdminPathNameBuffer[MAX_Q_PATHNAME_LEN];
  1061.     TCHAR szAdminFormatNameBuffer[MAX_Q_FORMATNAME_LEN];
  1062.     TCHAR szMsgBuffer[BUFFERSIZE];
  1063.  
  1064.     MQMSGPROPS MsgProps;
  1065.     MQPROPVARIANT aVariant[MAXINDEX];
  1066.     MSGPROPID aPropId[MAXINDEX];
  1067.     DWORD PropIdCount = 0;
  1068.  
  1069.     HRESULT hr;
  1070.  
  1071.     unsigned char bPriority;
  1072.     unsigned char bDelivery;
  1073.     unsigned char bJournal;
  1074.     unsigned char bDeadLetter;
  1075.     unsigned char bAuthenticated;
  1076.     unsigned char bEncrypted;
  1077.     unsigned char bAcknowledge;
  1078.  
  1079.     WCHAR szMessageBodyBuffer [BUFFERSIZE];
  1080.     WCHAR szMessageLabelBuffer[BUFFERSIZE];
  1081.     DWORD dwTimeToReachQueue;
  1082.     DWORD dwTimeToBeReceived;
  1083.  
  1084.     QUEUEHANDLE hQueue;
  1085.  
  1086.     CSendMessageDialog SendMessageDialog(&m_OpenedQueuePathNameArray);
  1087.  
  1088.     //
  1089.     // Display the SendMessage dialog.
  1090.     //
  1091.     if (SendMessageDialog.DoModal() == IDCANCEL)
  1092.     {
  1093.         return;
  1094.     }
  1095.  
  1096.     //
  1097.     // Retrieve the properties from the dialog box.
  1098.     //
  1099.     SendMessageDialog.GetPathName(szPathNameBuffer);
  1100.     SendMessageDialog.GetAdminPathName(szAdminPathNameBuffer);
  1101.     bPriority = SendMessageDialog.GetPriority();
  1102.     bDelivery = SendMessageDialog.GetDelivery();
  1103.     bJournal = SendMessageDialog.GetJournal();
  1104.     bDeadLetter = SendMessageDialog.GetDeadLetter();
  1105.     bAuthenticated = SendMessageDialog.GetAuthenticated();
  1106.     bEncrypted = SendMessageDialog.GetEncrypted();
  1107.     bAcknowledge = SendMessageDialog.GetAcknowledge();
  1108.     SendMessageDialog.GetMessageBody(szLastMessageBody);
  1109.     SendMessageDialog.GetMessageLabel(szLastMessageLabel);
  1110.     dwTimeToReachQueue = SendMessageDialog.GetTimeToReachQueue();
  1111.     dwTimeToBeReceived = SendMessageDialog.GetTimeToBeReceived();
  1112.  
  1113.     //
  1114.     // Update the Last message properties.
  1115.     //
  1116.     _mqscpy(szMessageBodyBuffer, szLastMessageBody);
  1117.     _mqscpy(szMessageLabelBuffer, szLastMessageLabel);
  1118.  
  1119.     //
  1120.     // Get the target queue handle.
  1121.     //
  1122.     if (GetQueueHandle(szPathNameBuffer, &hQueue) == FALSE)
  1123.     {
  1124.         //
  1125.         // Error - display message
  1126.         //
  1127.         _stprintf(szMsgBuffer, TEXT("GetQueueHandle failed. Queue not opened yet."));
  1128.         MessageBox(szMsgBuffer, TEXT("ERROR"), MB_OK);
  1129.         return;
  1130.     }
  1131.  
  1132.     //
  1133.     // Get the admin queue FormatName.
  1134.     //
  1135.     if (TranslateOpenedQueuePathNameToFormatName(szAdminPathNameBuffer, szAdminFormatNameBuffer) == FALSE)
  1136.     {
  1137.         //
  1138.         // Error - display message
  1139.         //
  1140.         _stprintf(szMsgBuffer, TEXT("TranslatePathNameToFormatName failed, Queue has not been opened yet."));
  1141.         MessageBox(szMsgBuffer, TEXT("ERROR"), MB_OK);
  1142.         return;
  1143.     }
  1144.  
  1145.     //
  1146.     // prepare the property array PROPVARIANT.
  1147.     //
  1148.  
  1149.     //
  1150.     // Set the PROPID_M_PRIORITY property.
  1151.     //
  1152.     aPropId[PropIdCount] = PROPID_M_PRIORITY;    //PropId
  1153.     aVariant[PropIdCount].vt = VT_UI1;           //Type
  1154.     aVariant[PropIdCount].bVal = bPriority;      //Value
  1155.  
  1156.     PropIdCount++;
  1157.  
  1158.     //
  1159.     // Set the PROPID_M_DELIVERY property.
  1160.     //
  1161.     aPropId[PropIdCount] = PROPID_M_DELIVERY;    //PropId
  1162.     aVariant[PropIdCount].vt = VT_UI1;           //Type
  1163.     aVariant[PropIdCount].bVal = bDelivery;      //Value
  1164.  
  1165.     PropIdCount++;
  1166.  
  1167.     //
  1168.     // Set the PROPID_M_ACKNOWLEDGE property.
  1169.     //
  1170.     aPropId[PropIdCount] = PROPID_M_ACKNOWLEDGE; //PropId
  1171.     aVariant[PropIdCount].vt = VT_UI1;           //Type
  1172.     aVariant[PropIdCount].bVal = bAcknowledge;   //Value
  1173.  
  1174.     PropIdCount++;
  1175.  
  1176.     //
  1177.     // Set the PROPID_M_BODY property.
  1178.     //
  1179.     aPropId[PropIdCount] = PROPID_M_BODY;                  //PropId
  1180.     aVariant[PropIdCount].vt = VT_VECTOR|VT_UI1;           //Type
  1181.     aVariant[PropIdCount].caub.cElems =
  1182.         (wcslen(szMessageBodyBuffer) + 1) * sizeof(WCHAR); //Value
  1183.     aVariant[PropIdCount].caub.pElems = (unsigned char *)szMessageBodyBuffer;
  1184.  
  1185.     PropIdCount++;
  1186.  
  1187.     //
  1188.     // Set the PROPID_M_LABEL property.
  1189.     //
  1190.     aPropId[PropIdCount] = PROPID_M_LABEL;                  //PropId
  1191.     aVariant[PropIdCount].vt = VT_LPWSTR;                   //Type
  1192.     aVariant[PropIdCount].pwszVal = szMessageLabelBuffer;     //Value
  1193.  
  1194.     PropIdCount++;
  1195.  
  1196.     //
  1197.     // Set the PROPID_M_TIME_TO_REACH_QUEUE property.
  1198.     //
  1199.     aPropId[PropIdCount] = PROPID_M_TIME_TO_REACH_QUEUE;    //PropId
  1200.     aVariant[PropIdCount].vt = VT_UI4;                      //Type
  1201.     aVariant[PropIdCount].ulVal = dwTimeToReachQueue;       //Value
  1202.  
  1203.     PropIdCount++;
  1204.  
  1205.     //
  1206.     // Set the PROPID_M_TIME_TO_BE_RECEIVED property.
  1207.     //
  1208.     aPropId[PropIdCount] = PROPID_M_TIME_TO_BE_RECEIVED;    //PropId
  1209.     aVariant[PropIdCount].vt = VT_UI4;                      //Type
  1210.     aVariant[PropIdCount].ulVal = dwTimeToBeReceived;       //Value
  1211.  
  1212.     PropIdCount++;
  1213.  
  1214.  
  1215.     if (bJournal || bDeadLetter)
  1216.     {
  1217.         //
  1218.         // Set the PROPID_M_JOURNAL property.
  1219.         //
  1220.         aPropId[PropIdCount] = PROPID_M_JOURNAL;            //PropId
  1221.         aVariant[PropIdCount].vt = VT_UI1;                  //Type
  1222.  
  1223.         if (bJournal)
  1224.             aVariant[PropIdCount].bVal = MQMSG_JOURNAL;
  1225.         else
  1226.             aVariant[PropIdCount].bVal = 0;
  1227.         if (bDeadLetter)
  1228.             aVariant[PropIdCount].bVal |= MQMSG_DEADLETTER;
  1229.  
  1230.         PropIdCount++;
  1231.     }
  1232.  
  1233.  
  1234.     if (bAuthenticated)
  1235.     {
  1236.         //
  1237.         // Set the PROPID_M_AUTH_LEVEL property.
  1238.         //
  1239.         aPropId[PropIdCount] = PROPID_M_AUTH_LEVEL;            //PropId
  1240.         aVariant[PropIdCount].vt = VT_UI4;                     //Type
  1241.         aVariant[PropIdCount].ulVal = MQMSG_AUTH_LEVEL_ALWAYS; //Value
  1242.  
  1243.         PropIdCount++;
  1244.     }
  1245.  
  1246.     if (bEncrypted)
  1247.     {
  1248.         //
  1249.         // Set the PROPID_M_ENCRYPTION_ALG property.
  1250.         //
  1251.         aPropId[PropIdCount] = PROPID_M_PRIV_LEVEL;            //PropId
  1252.         aVariant[PropIdCount].vt = VT_UI4;                     //Type
  1253.         aVariant[PropIdCount].ulVal = MQMSG_PRIV_LEVEL_BODY;   //Value
  1254.  
  1255.         PropIdCount++;
  1256.     }
  1257.  
  1258.  
  1259.     //
  1260.     // Set the PROPID_M_ADMIN_QUEUE property.
  1261.     //
  1262.     aPropId[PropIdCount] = PROPID_M_ADMIN_QUEUE;               //PropId
  1263.     aVariant[PropIdCount].vt = VT_LPWSTR;                      //Type
  1264. #ifdef UNICODE
  1265.     aVariant[PropIdCount].pwszVal = szAdminFormatNameBuffer;   //Value
  1266. #else
  1267.     WCHAR szwAdminFormatNameBuffer[MAX_Q_FORMATNAME_LEN];
  1268.     size_t rc = mbstowcs(szwAdminFormatNameBuffer,
  1269.                     szAdminFormatNameBuffer,
  1270.                     _tcslen(szAdminFormatNameBuffer)+1);
  1271.     ASSERT(rc != (size_t)(-1));
  1272.     aVariant[PropIdCount].pwszVal = szwAdminFormatNameBuffer;  //Value
  1273. #endif
  1274.  
  1275.     PropIdCount++;
  1276.  
  1277.     //
  1278.     // Set the MQMSGPROPS structure
  1279.     //
  1280.     MsgProps.cProp = PropIdCount;       //Number of properties.
  1281.     MsgProps.aPropID = aPropId;         //Id of properties.
  1282.     MsgProps.aPropVar = aVariant;       //Value of properties.
  1283.     MsgProps.aStatus  = NULL;           //No Error report.
  1284.  
  1285.     //
  1286.     // Send the message.
  1287.     //
  1288.     hr = MQSendMessage(
  1289.             hQueue,                     // handle to the Queue.
  1290.             &MsgProps,                  // Message properties to be sent.
  1291.             NULL                        // No transaction
  1292.             );
  1293.  
  1294.     if (FAILED(hr))
  1295.     {
  1296.         //
  1297.         // Error - display message
  1298.         //
  1299.         _stprintf(szMsgBuffer, TEXT("MQSendMessage failed, Error code = 0x%x."),hr);
  1300.         MessageBox(szMsgBuffer, TEXT("ERROR"), MB_OK);
  1301.     }
  1302.     else
  1303.     {
  1304.         //
  1305.         // Success - write in edit control
  1306.         //
  1307.         _stprintf(szMsgBuffer, TEXT("The Message \"%s\" was sent successfully."), szLastMessageLabel);
  1308.         PrintToScreen(szMsgBuffer);
  1309.     }
  1310. }
  1311.  
  1312. /* ************************************************************************ */
  1313. /*                           OnApiReceiveMessage                            */
  1314. /* ************************************************************************ */
  1315. /* This function opens a dialog box and asks the user for the queue's       */
  1316. /* PathName and the Time to wait for the message. Then it tries to get a    */
  1317. /* message from the specified queue at the given time.                      */
  1318. /*                                                                          */
  1319. /* Uses: MQReceiveMessage, MQFreeMemory.                                    */
  1320. /* ************************************************************************ */
  1321. void CMainFrame::OnApiReceiveMessage()
  1322. {
  1323.     TCHAR szPathNameBuffer[MAX_Q_PATHNAME_LEN];
  1324.     TCHAR szMsgBuffer[2*BUFFERSIZE];
  1325.     TCHAR szDomainName[BUFFERSIZE];
  1326.      TCHAR szAccountName[BUFFERSIZE];
  1327.     DWORD dwActNameSize = sizeof(szAccountName);
  1328.     DWORD dwDomNameSize = sizeof(szDomainName);
  1329.     TCHAR szTextSid[BUFFERSIZE];
  1330.     DWORD dwTextSidSize = sizeof(szTextSid);
  1331.     BYTE  blobBuffer[BUFFERSIZE];
  1332.  
  1333.     MQMSGPROPS MsgProps;
  1334.     MQPROPVARIANT aVariant[MAXINDEX];
  1335.     MSGPROPID aPropId[MAXINDEX];
  1336.     DWORD PropIdCount = 0;
  1337.  
  1338.     HRESULT hr;
  1339.  
  1340.     WCHAR szMessageLabelBuffer[BUFFERSIZE];
  1341.     DWORD dwTimeout;
  1342.  
  1343.     QUEUEHANDLE hQueue;
  1344.  
  1345.     CReceiveWaitDialog    WaitDialog;
  1346.     CReceiveMessageDialog ReceiveMessageDialog(&m_OpenedQueuePathNameArray);
  1347.  
  1348.     //
  1349.     // Display the ReceiveMessage dialog.
  1350.     //
  1351.     if (ReceiveMessageDialog.DoModal() == IDCANCEL)
  1352.     {
  1353.         return;
  1354.     }
  1355.  
  1356.     ReceiveMessageDialog.DestroyWindow();
  1357.     ReceiveMessageDialog.GetPathName(szPathNameBuffer);
  1358.  
  1359.     //
  1360.     // Get the queue handle.
  1361.     //
  1362.     if (GetQueueHandle(szPathNameBuffer, &hQueue) == FALSE)
  1363.     {
  1364.         //
  1365.         // Error - display message
  1366.         //
  1367.         _stprintf(szMsgBuffer, TEXT("GetQueueHandle failed. Queue was not found in Opened Queue Array"));
  1368.         MessageBox(szMsgBuffer, TEXT("ERROR"), MB_OK);
  1369.         return;
  1370.     }
  1371.  
  1372.     //
  1373.     // Retrieve the properties form the dialog box.
  1374.     //
  1375.     dwTimeout = ReceiveMessageDialog.GetTimeout();
  1376.  
  1377.  
  1378.     //
  1379.     // prepare the property array PROPVARIANT of
  1380.     // message properties that we want to receive
  1381.     //
  1382.  
  1383.     //
  1384.     // Set the PROPID_M_BODY property.
  1385.     //
  1386.     aPropId[PropIdCount] = PROPID_M_BODY;                                //PropId
  1387.     aVariant[PropIdCount].vt = VT_VECTOR|VT_UI1;                         //Type
  1388.     aVariant[PropIdCount].caub.cElems = ReceiveMessageDialog.GetBodySize() ;
  1389.     aVariant[PropIdCount].caub.pElems = (unsigned char *) new
  1390.                                char [ aVariant[PropIdCount].caub.cElems ] ;
  1391.  
  1392.     int iBodyIndex = PropIdCount ;
  1393.     PropIdCount++;
  1394.  
  1395.     //
  1396.     // Set the PROPID_M_LABEL property.
  1397.     //
  1398.     aPropId[PropIdCount] = PROPID_M_LABEL;                   //PropId
  1399.     aVariant[PropIdCount].vt = VT_LPWSTR;                    //Type
  1400.     aVariant[PropIdCount].pwszVal = szMessageLabelBuffer;
  1401.  
  1402.     PropIdCount++;
  1403.  
  1404.     //
  1405.     // Set the PROPID_M_PRIORITY property.
  1406.     //
  1407.     aPropId[PropIdCount] = PROPID_M_PRIORITY;               //PropId
  1408.     aVariant[PropIdCount].vt = VT_UI1;                      //Type
  1409.  
  1410.     PropIdCount++;
  1411.  
  1412.     //
  1413.     // Set the PROPID_M_CLASS property.
  1414.     //
  1415.     aPropId[PropIdCount] = PROPID_M_CLASS;                  //PropId
  1416.     aVariant[PropIdCount].vt = VT_UI2;                      //Type
  1417.  
  1418.     PropIdCount++;
  1419.  
  1420.     //
  1421.     // Set the PROPID_M_AUTHENTICATED property.
  1422.     //
  1423.     aPropId[PropIdCount] = PROPID_M_AUTHENTICATED;          //PropId
  1424.     aVariant[PropIdCount].vt = VT_UI1;                      //Type
  1425.  
  1426.     PropIdCount++;
  1427.  
  1428.     //
  1429.     // Set the PROPID_M_SENDERID property
  1430.     //
  1431.     aPropId[PropIdCount] = PROPID_M_SENDERID;               //PropId
  1432.     aVariant[PropIdCount].vt = VT_UI1|VT_VECTOR;            //Type
  1433.     aVariant[PropIdCount].blob.pBlobData = blobBuffer;
  1434.     aVariant[PropIdCount].blob.cbSize = sizeof(blobBuffer);
  1435.  
  1436.     PropIdCount++;
  1437.  
  1438.     //
  1439.     // Set the PROPID_M_PRIV_LEVEL property
  1440.     //
  1441.     aPropId[PropIdCount] = PROPID_M_PRIV_LEVEL;             //PropId
  1442.     aVariant[PropIdCount].vt = VT_UI4          ;            //Type
  1443.  
  1444.     PropIdCount++;
  1445.  
  1446.     //
  1447.     // Set the PROPID_M_LABEL_LEN property.
  1448.     //
  1449.     aPropId[PropIdCount] = PROPID_M_LABEL_LEN;              //PropId
  1450.     aVariant[PropIdCount].vt = VT_UI4;                      //Type
  1451.     aVariant[PropIdCount].ulVal = BUFFERSIZE;               //Value
  1452.  
  1453.     PropIdCount++;
  1454.  
  1455.  
  1456.     //
  1457.     // Set the MQMSGPROPS structure
  1458.     //
  1459.     MsgProps.cProp = PropIdCount;       //Number of properties.
  1460.     MsgProps.aPropID = aPropId;         //Id of properties.
  1461.     MsgProps.aPropVar = aVariant;       //Value of properties.
  1462.     MsgProps.aStatus  = NULL;           //No Error report.
  1463.  
  1464.     //
  1465.     // Display a message window until the message from the queue will be received.
  1466.     //
  1467.     WaitDialog.Create(IDD_WAIT_DIALOG,pMainView);
  1468.     WaitDialog.ShowWindow(SW_SHOWNORMAL);
  1469.     WaitDialog.UpdateWindow();
  1470.     WaitDialog.CenterWindow();
  1471.     pMainView->RedrawWindow();
  1472.  
  1473.     //
  1474.     // Receive the message.
  1475.     //
  1476.     hr = MQReceiveMessage(
  1477.                hQueue,               // handle to the Queue.
  1478.                dwTimeout,            // Max time (msec) to wait for the message.
  1479.                MQ_ACTION_RECEIVE,    // Action.
  1480.                &MsgProps,            // properties to retrieve.
  1481.                NULL,                 // No overlaped structure.
  1482.                NULL,                 // No callback function.
  1483.                NULL,                 // No Cursor.
  1484.                NULL                  // No transaction
  1485.                );
  1486.  
  1487.     WaitDialog.ShowWindow(SW_HIDE);
  1488.  
  1489.  
  1490.     if(hr == MQ_ERROR_IO_TIMEOUT)
  1491.     {
  1492.         _stprintf(szMsgBuffer, TEXT("MQReceiveMessage failed, Timeout expired."),hr);
  1493.         MessageBox(szMsgBuffer, TEXT("ERROR"), MB_OK);
  1494.     }
  1495.     else if(hr != MQ_OK)
  1496.     {
  1497.         //
  1498.         // Error - display message
  1499.         //
  1500.         _stprintf(szMsgBuffer, TEXT("MQReceiveMessage failed, Error code = 0x%x."),hr);
  1501.         MessageBox(szMsgBuffer, TEXT("ERROR"), MB_OK);
  1502.     }
  1503.     else
  1504.     {
  1505.         //
  1506.         // Success - write in edit control
  1507.         //
  1508.         ClassToString(aVariant[3].uiVal,szMsgBuffer);
  1509.         PrintToScreen(szMsgBuffer);
  1510.  
  1511.         //
  1512.         // Print some of the Message properties.
  1513.         //
  1514. #ifdef UNICODE
  1515.         _stprintf(szMsgBuffer, TEXT("\tLabel: %s"), (WCHAR *)(aVariant[1].pwszVal));
  1516. #else
  1517.         {
  1518.             PCHAR lpLable = UnicodeStringToAnsiString((WCHAR *)(aVariant[1].pwszVal));
  1519.             _stprintf(szMsgBuffer, TEXT("\tLabel: %s"), lpLable);
  1520.             delete [] lpLable;
  1521.         }
  1522. #endif
  1523.         PrintToScreen(szMsgBuffer);
  1524.  
  1525.         //
  1526.         // Only if the message is not a falcon message print the body.
  1527.         // (this is done since in ACK messages there is no message body).
  1528.         //
  1529.         if (aVariant[3].bVal == MQMSG_CLASS_NORMAL)
  1530.         {
  1531. #ifdef UNICODE
  1532.             _stprintf(szMsgBuffer, TEXT("\tBody : %s"), (WCHAR *)(aVariant[0].caub.pElems));
  1533. #else
  1534.             {
  1535.                 PCHAR pBody = UnicodeStringToAnsiString((WCHAR *)(aVariant[0].caub.pElems));
  1536.                 _stprintf(szMsgBuffer, TEXT("\tBody : %s"), pBody);
  1537.                 delete [] pBody;
  1538.             }
  1539. #endif
  1540.             PrintToScreen(szMsgBuffer);
  1541.         }
  1542.  
  1543.         _stprintf(szMsgBuffer, TEXT("\tPriority : %d"), aVariant[2].bVal);
  1544.         PrintToScreen(szMsgBuffer);
  1545.  
  1546.  
  1547.         //
  1548.         // Print Sender ID
  1549.         //
  1550.         //
  1551.         // See if we're running on NT or Win95.
  1552.         //
  1553.         OSVERSIONINFO OsVerInfo;
  1554.  
  1555.         OsVerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  1556.         GetVersionEx(&OsVerInfo);
  1557.  
  1558.         if (OsVerInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
  1559.         {
  1560.             //
  1561.             //  On NT
  1562.             //
  1563.             SID_NAME_USE peUse;
  1564.             if (LookupAccountSid(NULL,
  1565.                                  blobBuffer,
  1566.                                  szAccountName,
  1567.                                  &dwActNameSize,
  1568.                                  szDomainName,
  1569.                                  &dwDomNameSize,
  1570.                                  &peUse) )
  1571.             {
  1572.                 _stprintf(szMsgBuffer, TEXT("\tUser: %s\\%s"),
  1573.                     (WCHAR *)(szDomainName),(WCHAR *)(szAccountName));
  1574.                 PrintToScreen(szMsgBuffer);
  1575.             }
  1576.         }
  1577.         else
  1578.         {
  1579.             //
  1580.             // LookupAccountSid is not implemented on Win95,
  1581.             // instead print textual sid
  1582.             //
  1583.             if ( GetTextualSid((PSID)blobBuffer, szTextSid, &dwTextSidSize))
  1584.             {
  1585.                 _stprintf(szMsgBuffer, TEXT("\tUser SID : %s"), szTextSid);
  1586.                 PrintToScreen(szMsgBuffer);
  1587.             }
  1588.         }
  1589.         //
  1590.         // Print "Authenticated" or "Non Authenticated"
  1591.         //
  1592.         if (aVariant[4].bVal)
  1593.             PrintToScreen(TEXT("\tMessage is Authenticated."));
  1594.         else
  1595.             PrintToScreen(TEXT("\tMessage is Not Authenticated."));
  1596.  
  1597.  
  1598.         //
  1599.         // Print "Encrypted" or "Non Encrypted"
  1600.         //
  1601.         if (aVariant[6].ulVal)
  1602.             PrintToScreen(TEXT("\tMessage is Encrypted."));
  1603.         else
  1604.             PrintToScreen(TEXT("\tMessage is Not Encrypted."));
  1605.    }
  1606.  
  1607.    delete aVariant[ iBodyIndex ].caub.pElems ;
  1608. }
  1609.  
  1610. /* ************************************************************************ */
  1611. /*                               OnApiLocate                                */
  1612. /* ************************************************************************ */
  1613. /* This function opens a dialog box and ask the user to give a Label. Then  */
  1614. /* it locates all the Queues in the DS with a matching label.               */
  1615. /* The function updates the PathName Array with those queues.               */
  1616. /*                                                                          */
  1617. /* Uses: MQLocateBegin, MQLocateNext, MQLocateEnd,                          */
  1618. /*       MQInstanceToFormatName, MQFreeMemory.                              */
  1619. /* ************************************************************************ */
  1620. void CMainFrame::OnApiLocate()
  1621. {
  1622.     // TODO: Add your command handler code here
  1623.     TCHAR szMsgBuffer[BUFFERSIZE];
  1624.     TCHAR szLabelBuffer[BUFFERSIZE];
  1625.  
  1626.     HRESULT hr;
  1627.  
  1628.     MQPROPERTYRESTRICTION PropertyRestriction;
  1629.     MQRESTRICTION  Restriction;
  1630.     MQCOLUMNSET    Column;
  1631.     QUEUEPROPID    aPropId[2]; // only two properties to retrieve.
  1632.     HANDLE         hEnum;
  1633.     DWORD       cQueue;
  1634.     MQPROPVARIANT   aPropVar[MAX_VAR] = {0};
  1635.     ARRAYQ*         pArrayQ;
  1636.     DWORD       i;
  1637.     DWORD           dwColumnCount = 0;
  1638.     DWORD dwFormatNameLength = MAX_Q_FORMATNAME_LEN;
  1639.  
  1640.     CLocateDialog LocateDialog;
  1641.  
  1642.     //
  1643.     // Display the ReceiveMessage dialog.
  1644.     //
  1645.     if (LocateDialog.DoModal() == IDCANCEL)
  1646.     {
  1647.         return;
  1648.     }
  1649.  
  1650.     //
  1651.     // Retrieve the label from the dialog box.
  1652.     //
  1653.     LocateDialog.GetLabel(szLabelBuffer);
  1654.  
  1655.     //
  1656.     // Clean the PathNameArray before locate.
  1657.     //
  1658.     CleanPathNameArray();
  1659.  
  1660.     //
  1661.     // Prepare Parameters to locate a queue.
  1662.     //
  1663.  
  1664.     //
  1665.     // Prepare property restriction.
  1666.     // Restriction = All queue with PROPID_Q_LABEL equal to "MQ API test".
  1667.     //
  1668.     PropertyRestriction.rel = PREQ;
  1669.     PropertyRestriction.prop = PROPID_Q_LABEL;
  1670.     PropertyRestriction.prval.vt = VT_LPWSTR;
  1671. #ifdef UNICODE
  1672.     PropertyRestriction.prval.pwszVal = szLabelBuffer;
  1673. #else
  1674.     DWORD size = _tcslen(szLabelBuffer) +1;
  1675.     PropertyRestriction.prval.pwszVal = new WCHAR[size];
  1676.     AnsiStringToUnicode(PropertyRestriction.prval.pwszVal, szLabelBuffer,size);
  1677. #endif
  1678.  
  1679.     //
  1680.     // prepare a restriction with one property restriction.
  1681.     //
  1682.     Restriction.cRes = 1;
  1683.     Restriction.paPropRes = &PropertyRestriction;
  1684.  
  1685.     //
  1686.     // Columset (In other words what property I want to retrieve).
  1687.     // Only the PathName is important.
  1688.     //
  1689.     aPropId[dwColumnCount] = PROPID_Q_PATHNAME;
  1690.     dwColumnCount++;
  1691.  
  1692.     aPropId[dwColumnCount] = PROPID_Q_INSTANCE;
  1693.     dwColumnCount++;
  1694.  
  1695.     Column.cCol = dwColumnCount;
  1696.     Column.aCol = aPropId;
  1697.  
  1698.     //
  1699.     // Locate the queues. Issue the query
  1700.     //
  1701.     hr = MQLocateBegin(
  1702.             NULL,           //start search at the top.
  1703.             &Restriction,   //Restriction
  1704.             &Column,        //ColumnSet
  1705.             NULL,           //No sort order
  1706.             &hEnum          //Enumeration Handle
  1707.             );
  1708.  
  1709.     if(FAILED(hr))
  1710.     {
  1711.         //
  1712.         // Error - display message
  1713.         //
  1714.         _stprintf(szMsgBuffer,
  1715.             TEXT("MQLocateBegin failed, Error code = 0x%x."),hr);
  1716.         MessageBox(szMsgBuffer, TEXT("ERROR"), MB_OK);
  1717.         return;
  1718.     }
  1719.  
  1720.     //
  1721.     // Get the results.
  1722.     //
  1723.     cQueue = MAX_VAR;
  1724.  
  1725.     //
  1726.     // If cQueue == 0 it means that no Variants were retrieved in the last MQLocateNext.
  1727.     //
  1728.     while (cQueue != 0)
  1729.     {
  1730.         hr = MQLocateNext(
  1731.                 hEnum,      // handle returned by MQLocateBegin.
  1732.                 &cQueue,    // size of aPropVar array.
  1733.                 aPropVar    // OUT: an array of MQPROPVARIANT to get the results in.
  1734.                 );
  1735.  
  1736.         if(FAILED(hr))
  1737.         {
  1738.             //
  1739.             // Error - display message
  1740.             //
  1741.             _stprintf(szMsgBuffer,
  1742.                 TEXT("MQLocateNext failed, Error code = 0x%x."),hr);
  1743.             MessageBox(szMsgBuffer, TEXT("ERROR"), MB_OK);
  1744.             return;
  1745.         }
  1746.  
  1747.         for (i=0; i<cQueue; i++)
  1748.         {
  1749.             //
  1750.             // add the new path names to the path name array.
  1751.             //
  1752.             pArrayQ = new ARRAYQ;
  1753. #ifdef UNICODE
  1754.             wcsncpy (pArrayQ->szPathName, aPropVar[i].pwszVal, MAX_Q_PATHNAME_LEN);
  1755. #else
  1756.             size_t rc = wcstombs(pArrayQ->szPathName, aPropVar[i].pwszVal, MAX_Q_PATHNAME_LEN);
  1757.             ASSERT(rc != (size_t)(-1));
  1758. #endif
  1759.             //
  1760.             // move to the next property.
  1761.             //
  1762.             i = i + 1;
  1763.  
  1764.             //
  1765.             // Get the FormatName of the queue and set it in the PathName array.
  1766.             //
  1767. #ifdef UNICODE
  1768.             hr = MQInstanceToFormatName(aPropVar[i].puuid, pArrayQ->szFormatName, &dwFormatNameLength);
  1769. #else
  1770.             WCHAR szwFormatNameBuffer[MAX_Q_FORMATNAME_LEN];
  1771.             hr = MQInstanceToFormatName(aPropVar[i].puuid, szwFormatNameBuffer, &dwFormatNameLength);
  1772.             if (SUCCEEDED(hr))
  1773.             {
  1774.                 size_t rwc =wcstombs(pArrayQ->szFormatName, szwFormatNameBuffer, dwFormatNameLength);
  1775.                 ASSERT(rwc != (size_t)(-1));
  1776.             }
  1777. #endif
  1778.  
  1779.             if(FAILED(hr))
  1780.             {
  1781.                 //
  1782.                 // Error - display message
  1783.                 //
  1784.                 _stprintf (szMsgBuffer,
  1785.                     TEXT("MQGUIDToFormatName failed, Error code = 0x%x."),hr);
  1786.                 MessageBox(szMsgBuffer, TEXT("ERROR"), MB_OK);
  1787.             }
  1788.  
  1789.             //
  1790.             // Free the memory allocated by MSMQ
  1791.             //
  1792.             MQFreeMemory(aPropVar[i].pwszVal);
  1793.  
  1794.             //
  1795.             // Add the new Queue to the PathNameArray.
  1796.             //
  1797.             Add2PathNameArray(pArrayQ);
  1798.         }
  1799.     }
  1800.  
  1801.     //
  1802.     // End the locate operation.
  1803.     //
  1804.     hr = MQLocateEnd(hEnum);   // handle returned by MQLocateBegin.
  1805.     if(FAILED(hr))
  1806.     {
  1807.         //
  1808.         // Error - display message
  1809.         //
  1810.         _stprintf (szMsgBuffer,
  1811.             TEXT("MQLocateEnd failed, Error code = 0x%x."),hr);
  1812.         MessageBox(szMsgBuffer, TEXT("ERROR"), MB_OK);
  1813.         return;
  1814.     }
  1815.  
  1816.     //
  1817.     // Display the Queues found on the locate.
  1818.     //
  1819.     _stprintf (szMsgBuffer, TEXT("Locate Operation completed successfully"));
  1820.     PrintToScreen(szMsgBuffer);
  1821.     UpdatePathNameArrays();
  1822.     DisplayPathNameArray();
  1823.     DisplayOpenedQueuePathNameArray();
  1824. }
  1825.  
  1826. /* ************************************************************************ */
  1827. /*                           OnUpdateFrameTitle                             */
  1828. /* ************************************************************************ */
  1829. void CMainFrame::OnUpdateFrameTitle(BOOL bAddToTitle)
  1830. {
  1831.     SetWindowText (TEXT("MQ API test"));
  1832. }
  1833.