home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / sdk / mapi / win16 / dev / statusvu / statvu.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-11  |  28.8 KB  |  1,012 lines

  1. /*
  2.  -  S T A T V U . C P P
  3.  -  Copyright (C) 1995 Microsoft Corporation
  4.  -
  5.  *  Purpose:
  6.  *
  7.  */
  8.  
  9. #ifdef WIN32
  10. #ifdef _WIN95
  11. #define _INC_OLE
  12. #endif
  13. #define INC_OLE2
  14. #define INC_RPC
  15. #endif
  16.  
  17. #include <afxwin.h>     
  18. #include <windowsx.h>
  19. #include <stdio.h>
  20. #include <string.h>
  21.  
  22. #ifdef WIN16
  23. #include <compobj.h>
  24. #endif
  25.  
  26. #ifdef WIN32
  27. #include <objbase.h>
  28. #include <objerror.h>
  29. #ifdef _WIN95
  30. #include <ole2.h>
  31. #endif
  32. #endif
  33.  
  34.  
  35. #include <mapiwin.h>
  36. #include <mapix.h>
  37. #include <strtbl.h>
  38. #include <misctool.h>
  39. #include <pvalloc.h>
  40. #include <stentry.h>
  41. #include <limits.h>
  42. #include "resource.h"
  43. #include "statvu.h"
  44. #include "oper.h"
  45.  
  46. /* Global Objects */
  47. CWnd *pStatusWnd;
  48. CWnd *pLogWnd;
  49.  
  50.  
  51. SizedSPropTagArray(5,sptaStatus) = 
  52. {
  53.     5, 
  54.     { 
  55.         PR_DISPLAY_NAME,
  56.         PR_ENTRYID,
  57.         PR_RESOURCE_TYPE,
  58.         PR_PROVIDER_DLL_NAME,
  59.         PR_RESOURCE_FLAGS 
  60.     }
  61. };
  62.  
  63. SizedSPropTagArray(3,sptaStatDisplay) = 
  64. {
  65.     3, 
  66.     { 
  67.         PR_DISPLAY_NAME,
  68.         PR_RESOURCE_METHODS,
  69.         PR_STATUS_STRING
  70.     }
  71. };
  72.  
  73.  
  74. /* PROPVU functions */
  75.  
  76.  
  77. extern HINSTANCE    hlibPROPVU;
  78.  
  79. typedef BOOL (*LPFNVIEWMAPIPROP)(
  80.     LPSTR           lpszName,
  81.     LPMAPIPROP FAR *lppMAPIProp,
  82.     LPVOID          lpvDest,
  83.     HWND            hWnd);    
  84.  
  85. extern LPFNVIEWMAPIPROP lpfnViewMapiProp;
  86.  
  87. #define PROPVUViewMapiProp (*lpfnViewMapiProp)
  88.  
  89.  
  90. HINSTANCE           hlibPROPVU          = (HINSTANCE)NULL;
  91. LPFNVIEWMAPIPROP    lpfnViewMapiProp    = NULL;
  92.  
  93.  
  94.  
  95.  
  96. /*
  97.  -  ViewStatusObj
  98.  -
  99.  *  Purpose:
  100.  *
  101.  *  Parameters:
  102.  *
  103.  *  Returns:
  104.  *      void.
  105.  *
  106.  */
  107.  
  108. extern "C"
  109. BOOL ViewStatusObj(LPMAPISESSION FAR *lppMAPISession, HWND hWnd)
  110. {
  111.     COpenStatusDlg     ChooseDlg(*lppMAPISession, hWnd);
  112.     return (ChooseDlg.DoModal() == IDOK);
  113. }
  114.  
  115.  
  116. /*******************************************************************/
  117.  
  118. /* COpenStatusDlg implementation */
  119.  
  120. BEGIN_MESSAGE_MAP(COpenStatusDlg, CModalDialog)
  121.  
  122.     ON_COMMAND(     IDC_CHOOSE_OPEN,            OnOpen)
  123.     ON_BN_CLICKED(  IDC_CHOOSE_MODIFY,          OnReadOnly)
  124.     ON_COMMAND(     IDC_CHOOSE_XPORT,           OnTargetXport)
  125.  
  126. END_MESSAGE_MAP()
  127.  
  128.  
  129. /*******************************************************************/
  130. /*
  131.  -  COpenStatus::
  132.  -  OnInitDialog
  133.  *
  134.  *  Purpose:
  135.  *  Parameters
  136.  *  Returns:
  137.  *
  138.  */
  139. /*******************************************************************/
  140.  
  141. BOOL COpenStatusDlg::OnInitDialog()
  142. {
  143.     int             rgTabStops[5];
  144.     DWORD           dwReturn    = 0;
  145.  
  146.     SetWindowText( "Select Status Object To Open" );
  147.  
  148.     CheckDlgButton(IDC_CHOOSE_MODIFY,0);
  149.  
  150.     // load properties into listbox
  151.     dwReturn = SendDlgItemMessage(IDC_CHOOSE_STATUS,LB_SETHORIZONTALEXTENT,
  152.                     (WPARAM) PROP_LISTBOX_HORIZONTAL_SIZE ,0 );
  153.  
  154.     rgTabStops[0] = 120 ;
  155.     rgTabStops[1] = 200 ;
  156.  
  157.     dwReturn = SendDlgItemMessage(IDC_CHOOSE_STATUS,LB_SETTABSTOPS,
  158.                     (WPARAM) 2,(LPARAM)rgTabStops );
  159.  
  160.     DisplayStatus();
  161.     
  162.     return TRUE;
  163. }
  164.  
  165. /*******************************************************************/
  166.  
  167. void COpenStatusDlg::OnReadOnly()
  168. {   
  169.     CheckDlgButton(IDC_CHOOSE_MODIFY, !IsDlgButtonChecked(IDC_CHOOSE_MODIFY) );
  170. }
  171.    
  172.  
  173. /*******************************************************************/
  174.  
  175. void COpenStatusDlg::OnTargetXport()
  176. {   
  177.     LONG            lSelection  = 0;
  178.  
  179.     if( (lSelection = SendDlgItemMessage(IDC_CHOOSE_STATUS,LB_GETCURSEL,0,0 )) < 0 )
  180.     {
  181.         MessageBox("Select a Status Object to Set as Target Xport for FlushQueues", 
  182.                 "OnOpen", MBS_ERROR );
  183.         return;
  184.     }
  185.  
  186.     m_cbEntryIDTarget = m_lpRows->aRow[lSelection].lpProps[1].Value.bin.cb;
  187.     m_lpEntryIDTarget = (LPENTRYID)m_lpRows->aRow[lSelection].lpProps[1].Value.bin.lpb;
  188.     m_szTarget = m_lpRows->aRow[lSelection].lpProps[0].Value.lpszA;
  189. }
  190.    
  191.    
  192. /*******************************************************************/
  193. /*
  194.  -  COpenStatus::
  195.  -  OnOpen
  196.  *
  197.  *  Purpose:
  198.  *  Parameters
  199.  *  Returns:
  200.  *
  201.  */
  202. /*******************************************************************/
  203.  
  204. void COpenStatusDlg::OnOpen()
  205. {
  206.     LONG            lSelection  = 0;
  207.     ULONG           ulFlags     = 0;
  208.     HRESULT         hResult     = hrSuccess;
  209.     CGetError       E;
  210.     LPMAPIPROP      lpObj       = NULL;
  211.     ULONG           ulObjType   = 0;
  212.     CStatusDlg      StatusDlg(this);
  213.                      
  214.     
  215.     if( (lSelection = SendDlgItemMessage(IDC_CHOOSE_STATUS,LB_GETCURSEL,0,0 )) < 0 )
  216.     {
  217.         MessageBox("Select a Status Object to open", "OnOpen", MBS_ERROR );
  218.         return;
  219.     }
  220.     
  221.     // determine access privileges
  222.     if( IsDlgButtonChecked(IDC_CHOOSE_MODIFY) )
  223.         ulFlags = MAPI_MODIFY;
  224.     else
  225.         ulFlags = 0;
  226.  
  227.     if( HR_FAILED( hResult = m_lpSession->OpenEntry( 
  228.                     (ULONG)     m_lpRows->aRow[lSelection].lpProps[1].Value.bin.cb,
  229.                     (LPENTRYID) m_lpRows->aRow[lSelection].lpProps[1].Value.bin.lpb,
  230.                     NULL,
  231.                     ulFlags,
  232.                     &ulObjType,
  233.                     (LPUNKNOWN*) &lpObj ) ) )
  234.     {
  235.         MessageBox( E.SzError("lpSession->OpenEntry()", hResult),
  236.                  "Client", MBS_ERROR );
  237.         return;
  238.     }               
  239.  
  240.     if(ulObjType == MAPI_STATUS)
  241.     {   
  242.  
  243.  
  244.         if(m_cbEntryIDTarget == 0)
  245.         { 
  246.             m_szTarget = "No Target Xport Specified";
  247.         }
  248.         
  249.         StatusDlg.m_lResourceType   = m_lpRows->aRow[lSelection].lpProps[2].Value.l;
  250.         StatusDlg.m_szDLLName       = m_lpRows->aRow[lSelection].lpProps[3].Value.lpszA;
  251.         StatusDlg.m_lResourceFlags  = m_lpRows->aRow[lSelection].lpProps[4].Value.l;
  252.         StatusDlg.m_lpStatus        = (LPMAPISTATUS)lpObj;
  253.         StatusDlg.m_cbEntryIDTargetXport = m_cbEntryIDTarget; 
  254.         StatusDlg.m_lpEntryIDTargetXport = m_lpEntryIDTarget; 
  255.         StatusDlg.m_szTargetXport   = m_szTarget;
  256.         StatusDlg.DoModal();
  257.     }        
  258.     else
  259.     {
  260.         MessageBox( "ulObjType != MAPI_STATUS, exiting ",
  261.                  "Client", MBS_ERROR );
  262.         return;
  263.     }               
  264.  
  265.     if(lpObj)
  266.         lpObj->Release();
  267.                
  268.     EndDialog(IDOK);
  269. }
  270.  
  271.    
  272. /*******************************************************************/
  273. /*
  274.  -  COpenStatus::
  275.  -  ~COpenStatusDlg
  276.  *
  277.  *  Purpose:
  278.  *  Parameters
  279.  *  Returns:
  280.  *
  281.  */
  282. /*******************************************************************/
  283.  
  284. COpenStatusDlg::~COpenStatusDlg()
  285. {
  286.     // FREE MEMORY AND OBJECTS, and exit dialog
  287.  
  288.     FreeRowSet(m_lpRows);
  289.  
  290.     if(m_lptblStatus)
  291.     {
  292.         m_lptblStatus->Release();
  293.         m_lptblStatus = NULL;
  294.     }
  295. }
  296.    
  297. /*******************************************************************/
  298. /*
  299.  -  COpenStatus::
  300.  -  OnDisplayStatus
  301.  *
  302.  *  Purpose:
  303.  *  Parameters
  304.  *  Returns:
  305.  *
  306.  */
  307. /*******************************************************************/
  308.  
  309. void COpenStatusDlg::DisplayStatus()
  310. {
  311.     CGetError       E;
  312.     LPSRowSet       lpRows                  = NULL;
  313.     ULONG           iRow                    = 0;
  314.     HRESULT         hResult                 = hrSuccess;
  315.     ULONG           ulRows                  = 0;
  316.     char            szBuffer[512];
  317.     DWORD           dwReturn        = 0;
  318.     
  319.     SendDlgItemMessage(IDC_CHOOSE_STATUS,LB_RESETCONTENT,0,0);
  320.  
  321.     if(m_lptblStatus)
  322.     {
  323.         FreeRowSet(m_lpRows);
  324.         m_lptblStatus->Release();
  325.         m_lptblStatus = NULL;
  326.     }
  327.  
  328.     if( HR_FAILED(hResult = m_lpSession->GetStatusTable(0,&m_lptblStatus) ) )
  329.     {
  330.         MessageBox( E.SzError("m_lpSession->GetStatusTable", hResult), 
  331.                             "Client", MBS_ERROR );
  332.         return;
  333.     }
  334.  
  335.     if( HR_FAILED(hResult = m_lptblStatus->SetColumns( (LPSPropTagArray) &sptaStatus, 0) ) )
  336.     {
  337.         MessageBox( E.SzError("m_lptblStatus->SetColumns", hResult), 
  338.                             "Client", MBS_ERROR );
  339.         return;
  340.     }
  341.  
  342.     if( HR_FAILED(hResult = m_lptblStatus->GetRowCount(0,&ulRows) ) )
  343.     {
  344.         MessageBox( E.SzError("m_lptblStatus->GetRowCount", hResult), 
  345.                             "Client", MBS_ERROR );
  346.         return;
  347.     }
  348.             
  349.     if( HR_FAILED(hResult = m_lptblStatus->SeekRow( BOOKMARK_BEGINNING,0 , NULL ) ) )
  350.     {
  351.         MessageBox( E.SzError("m_lptblStatus->SeekRow", hResult), 
  352.                             "Client", MBS_ERROR );
  353.         return;
  354.     }
  355.     
  356.     if( !HR_FAILED(hResult = m_lptblStatus->QueryRows( ulRows, 0, &m_lpRows ) ) )
  357.     {    
  358.         // if there is at least one row, find column of EntryID and Default Status
  359.         if(m_lpRows->cRows)
  360.         {
  361.             // find out which row has the Default Status and open it
  362.             for(iRow = 0; iRow < m_lpRows->cRows; iRow++)
  363.             {            
  364.                 // display PR_DISPLAY_NAME
  365.                 strcpy(szBuffer,m_lpRows->aRow[iRow].lpProps[0].Value.lpszA);       
  366.                 strcat(szBuffer,"\t");
  367.  
  368.                 // display PR_ENTRYID
  369.                 char    lpszHex[9];
  370.                 ULONG   cb      = 0;
  371.                 ULONG   cChars  = 0;
  372.                 LPBYTE  lpb     = m_lpRows->aRow[iRow].lpProps[1].Value.bin.lpb;
  373.  
  374.                 while((cb < m_lpRows->aRow[iRow].lpProps[1].Value.bin.cb) && (cChars < 255 -16 ) )
  375.                 {
  376.                     wsprintf(lpszHex, "%02X ", *lpb);
  377.                     lstrcat(szBuffer, lpszHex);
  378.                     cChars += 3;
  379.                     lpb++;
  380.                     cb++;
  381.                 }
  382.                 
  383.                 dwReturn = SendDlgItemMessage(IDC_CHOOSE_STATUS,LB_ADDSTRING,0,
  384.                             (LPARAM)szBuffer);
  385.             }
  386.         }
  387.     }
  388. }    
  389.  
  390. /*******************************************************************/
  391. /*
  392.  -  COpenStatus::
  393.  -  OnCancel
  394.  -
  395.  *  Purpose:
  396.  *
  397.  */
  398. /*******************************************************************/
  399.  
  400. void COpenStatusDlg::OnCancel()
  401. {
  402.  
  403.     EndDialog(IDCANCEL);
  404. }
  405.  
  406. /*******************************************************************/
  407. /*******************************************************************/
  408. /*******************************************************************/
  409.  
  410. /* COpenStatusDlg implementation */
  411.  
  412. BEGIN_MESSAGE_MAP(CStatusDlg, CModalDialog)
  413.  
  414.     ON_COMMAND(     IDC_STATUS_PROPS,           OnStatusProps)
  415.     ON_COMMAND(     IDC_STATUS_VALIDATE,        OnValidateState)
  416.     ON_COMMAND(     IDC_STATUS_SETTINGS,        OnSettingsDialog)
  417.     ON_COMMAND(     IDC_STATUS_FLUSH,           OnFlushQueues)
  418.     ON_COMMAND(     IDC_STATUS_CHANGEPASS,      OnChangePassword)
  419.     ON_COMMAND(     IDC_STATUS_REGNOTIF,        OnRegisterNotification)
  420.  
  421. END_MESSAGE_MAP()
  422.  
  423.  
  424.  
  425.    
  426. /*******************************************************************/
  427. /*
  428.  -  CStatus::
  429.  -  ~CStatusDlg
  430.  *
  431.  *  Purpose:
  432.  *  Parameters
  433.  *  Returns:
  434.  *
  435.  */
  436. /*******************************************************************/
  437.  
  438. CStatusDlg::~CStatusDlg()
  439. {
  440.     // FREE MEMORY AND OBJECTS, and exit dialog
  441.  
  442. }
  443.  
  444.  
  445. /********************************************************************/
  446. /*
  447.  -  CStatusDlg::
  448.  -  OnInitDialog
  449.  -
  450.  *  Purpose:
  451.  *      Constructor for main dialog class.
  452.  *
  453.  */
  454. /********************************************************************/
  455.  
  456. BOOL CStatusDlg::OnInitDialog()
  457. {
  458.     char   *szPropLibName;
  459.     char    szPropMsgBuf[256];
  460.  
  461.     // ASSERTS
  462.     if(!m_lpStatus)
  463.         return FALSE;
  464.  
  465.         
  466.     // LOAD UP PROPERTY DLL
  467.  
  468.  
  469. #ifdef WIN16
  470.     szPropLibName = "propvu.dll";
  471.     if ((UINT)(hlibPROPVU = LoadLibrary (szPropLibName)) < 32)
  472. #else
  473.     szPropLibName = "propvu32.dll";
  474.     if (!(hlibPROPVU = LoadLibrary (szPropLibName)))
  475. #endif
  476.     {
  477.         wsprintf(szPropMsgBuf,"Cannot Load %s.  Make sure this DLL is available and in your path.",szPropLibName);
  478.         MessageBox(szPropMsgBuf,"Error", MB_ICONSTOP | MB_OK);
  479.         return FALSE;
  480.     }
  481.     
  482.     if (!(lpfnViewMapiProp  =  (LPFNVIEWMAPIPROP)GetProcAddress (hlibPROPVU, "ViewMapiProp") ))
  483.     {
  484.         MessageBox("Cannot Load ViewMapiProp process address.","Error", MB_ICONSTOP | MB_OK);
  485.         return FALSE;
  486.     }
  487.  
  488.  
  489.     DisplayProps();
  490.  
  491.     return TRUE;
  492. }
  493.  
  494.  
  495.  
  496. /********************************************************************/
  497.  
  498.  
  499. void CStatusDlg::DisplayProps()
  500. {
  501.     DWORD           dwIndex     = 0;    
  502.     ULONG           cValues     = 0;
  503.     LPSPropValue    lpspva      = NULL;
  504.     HRESULT         hResult     = hrSuccess;
  505.     char            szBuffer[80];
  506.     CGetError       E;
  507.        
  508.     if( HR_FAILED( hResult = m_lpStatus->GetProps( (LPSPropTagArray) &sptaStatDisplay,0, &cValues, &lpspva) ) )
  509.     {
  510.         MessageBox( E.SzError("CPropDlg::OnBldProps()  lpStatus->GetProps()",
  511.              hResult), "Client", MBS_ERROR );
  512.         return;
  513.     }
  514.  
  515.     
  516.     // PR_DISPLAY_NAME
  517.     if( PROP_TYPE(lpspva[0].ulPropTag) == PT_ERROR)
  518.     {
  519.         
  520.         if(GetString( "MAPIErrors", lpspva[0].Value.err, szBuffer ))
  521.             wsprintf( szBuffer, "PT_ERROR: %04X", lpspva[0].Value.err );
  522.  
  523.         dwIndex = SendDlgItemMessage(IDC_STATUS_DISPLAY_NAME,LB_ADDSTRING,0,
  524.                         (LPARAM) szBuffer );
  525.     }
  526.     else
  527.     {
  528.         dwIndex = SendDlgItemMessage(IDC_STATUS_DISPLAY_NAME,LB_ADDSTRING,0,
  529.                         (LPARAM) lpspva[0].Value.lpszA );
  530.     }
  531.     
  532.     // REQUIRED
  533.     // PR_RESOURCE_TYPE
  534.     GetString("ResourceType",m_lResourceType,szBuffer);
  535.     dwIndex = SendDlgItemMessage(IDC_STATUS_TYPE,LB_ADDSTRING,0,
  536.                         (LPARAM) szBuffer );
  537.     
  538.     // REQUIRED
  539.     // PR_PROVIDER_DLL_NAME
  540.     dwIndex = SendDlgItemMessage(IDC_STATUS_DLL_NAME,LB_ADDSTRING,0,
  541.                             (LPARAM) m_szDLLName.GetBuffer(30) );
  542.  
  543.     // PR_RESOURCE_FLAGS    
  544.     if( (m_lResourceFlags &  STATUS_DEFAULT_OUTBOUND) )
  545.     {
  546.          strcpy(szBuffer,"STATUS_DEFAULT_OUTBOUND");
  547.          dwIndex = SendDlgItemMessage(IDC_STATUS_FLAGS,LB_ADDSTRING,0,
  548.                         (LPARAM) szBuffer );
  549.     }
  550.     if( (m_lResourceFlags &  STATUS_DEFAULT_STORE) )
  551.     {
  552.          strcpy(szBuffer,"STATUS_DEFAULT_STORE");
  553.          dwIndex = SendDlgItemMessage(IDC_STATUS_FLAGS,LB_ADDSTRING,0,
  554.                         (LPARAM) szBuffer );
  555.     }
  556.     if( (m_lResourceFlags &  STATUS_PRIMARY_IDENTITY) )
  557.     {
  558.          strcpy(szBuffer,"STATUS_PRIMARY_IDENTITY");
  559.          dwIndex = SendDlgItemMessage(IDC_STATUS_FLAGS,LB_ADDSTRING,0,
  560.                         (LPARAM) szBuffer );
  561.     }
  562.     if( (m_lResourceFlags &  STATUS_SIMPLE_STORE) )
  563.     {
  564.          strcpy(szBuffer,"STATUS_SIMPLE_STORE");
  565.          dwIndex = SendDlgItemMessage(IDC_STATUS_FLAGS,LB_ADDSTRING,0,
  566.                         (LPARAM) szBuffer );
  567.     }
  568.     if( (m_lResourceFlags &  STATUS_XP_PREFER_LAST) )
  569.     {
  570.          strcpy(szBuffer,"STATUS_XP_PREFER_LAST");
  571.          dwIndex = SendDlgItemMessage(IDC_STATUS_FLAGS,LB_ADDSTRING,0,
  572.                         (LPARAM) szBuffer );
  573.     }
  574.  
  575.  
  576.  
  577.     // PR_RESOURCE_METHODS
  578.     if( PROP_TYPE(lpspva[1].ulPropTag) == PT_ERROR)
  579.     {
  580.         
  581.         if(GetString( "MAPIErrors", lpspva[1].Value.err, szBuffer ))
  582.             wsprintf( szBuffer, "PT_ERROR: %04X", lpspva[1].Value.err );
  583.  
  584.         dwIndex = SendDlgItemMessage(IDC_STATUS_METHODS,LB_ADDSTRING,0,
  585.                         (LPARAM) szBuffer );
  586.     }
  587.     else
  588.     {
  589.         if( (lpspva[1].Value.l &  STATUS_VALIDATE_STATE) )
  590.         {
  591.              strcpy(szBuffer,"STATUS_VALIDATE_STATE");
  592.              dwIndex = SendDlgItemMessage(IDC_STATUS_METHODS,LB_ADDSTRING,0,
  593.                             (LPARAM) szBuffer );
  594.         }
  595.         if( (lpspva[1].Value.l &  STATUS_SETTINGS_DIALOG) )
  596.         {
  597.              strcpy(szBuffer,"STATUS_SETTINGS_DIALOG");
  598.              dwIndex = SendDlgItemMessage(IDC_STATUS_METHODS,LB_ADDSTRING,0,
  599.                             (LPARAM) szBuffer );
  600.         }
  601.         if( (lpspva[1].Value.l &  STATUS_CHANGE_PASSWORD) )
  602.         {
  603.              strcpy(szBuffer,"STATUS_CHANGE_PASSWORD");
  604.              dwIndex = SendDlgItemMessage(IDC_STATUS_METHODS,LB_ADDSTRING,0,
  605.                             (LPARAM) szBuffer );
  606.         }
  607.         if( (lpspva[1].Value.l &  STATUS_FLUSH_QUEUES) )
  608.         {
  609.              strcpy(szBuffer,"STATUS_FLUSH_QUEUES");
  610.              dwIndex = SendDlgItemMessage(IDC_STATUS_METHODS,LB_ADDSTRING,0,
  611.                             (LPARAM) szBuffer );
  612.         }
  613.         if( (lpspva[1].Value.l &  STATUS_OWN_STORE) )
  614.         {
  615.              strcpy(szBuffer,"STATUS_OWN_STORE");
  616.              dwIndex = SendDlgItemMessage(IDC_STATUS_METHODS,LB_ADDSTRING,0,
  617.                             (LPARAM) szBuffer );
  618.         }
  619.     }
  620.     
  621.     
  622.     // PR_STATUS_STRING
  623.     if( PROP_TYPE(lpspva[2].ulPropTag) == PT_ERROR)
  624.     {
  625.         
  626.         if(GetString( "MAPIErrors", lpspva[2].Value.err, szBuffer ))
  627.             wsprintf( szBuffer, "PT_ERROR: %04X", lpspva[2].Value.err );
  628.  
  629.         dwIndex = SendDlgItemMessage(IDC_STATUS_CODE,LB_ADDSTRING,0,
  630.                         (LPARAM) szBuffer );
  631.     }
  632.     else
  633.     {
  634.         dwIndex = SendDlgItemMessage(IDC_STATUS_CODE,LB_ADDSTRING,0,
  635.                                 (LPARAM) lpspva[2].Value.lpszA );
  636.     }    
  637.  
  638.     // FREE MEMORY    
  639.     if(lpspva)
  640.         MAPIFreeBuffer(lpspva);
  641.  
  642. }
  643.  
  644. /********************************************************************/
  645.  
  646. void CStatusDlg::OnStatusProps()
  647. {
  648.     PROPVUViewMapiProp("Status Props", 
  649.                 (LPMAPIPROP FAR *)&m_lpStatus,NULL, (HWND)this->m_hWnd );
  650. }
  651.  
  652. /********************************************************************/
  653.  
  654. void CStatusDlg::OnValidateState()
  655. {
  656.     HRESULT         hResult         = hrSuccess;
  657.     COperation      ValidateStateDlg(this);
  658.     ULONG           ulFlags         = 0;
  659.     CGetError       E;
  660.     ULONG           ulUIParam       = 0;
  661.     int             dRet            = 0;
  662.     char            szBuff[80];        
  663.  
  664.     ValidateStateDlg.m_CurrentOperation= "lpStatus->ValidateState()";
  665.     ValidateStateDlg.m_CBText1         = "ulUIParam:";
  666.     ValidateStateDlg.m_FlagText1       = "SUPPRESS_UI";
  667.     ValidateStateDlg.m_FlagText2       = "REFRESH_XP_HEADER_CACHE";
  668.     ValidateStateDlg.m_FlagText3       = "PROCESS_XP_HEADER_CACHE";
  669.     ValidateStateDlg.m_FlagText4       = "FORCE_XP_CONNECT";
  670.     ValidateStateDlg.m_FlagText5       = "FORCE_XP_DISCONNECT";
  671.     ValidateStateDlg.m_FlagText6       = "CONFIG_CHANGED";
  672.  
  673.     dRet = ValidateStateDlg.m_CBContents1.Add("NULL");
  674.     wsprintf(szBuff,"Parent hWnd == %X",this->m_hWnd);
  675.     dRet = ValidateStateDlg.m_CBContents1.Add(szBuff);
  676.  
  677.     // bring up modal dialog box, and if user hits OK, process operation
  678.     if( ValidateStateDlg.DoModal() == IDOK )   
  679.     {       
  680.         if( !lstrcmp(ValidateStateDlg.m_szCB1,"NULL") )
  681.             ulUIParam = (ULONG)NULL;
  682.         else
  683.             ulUIParam = (ULONG)(void *)this->m_hWnd;                    
  684.  
  685.         if( ValidateStateDlg.m_bFlag1 )                
  686.             ulFlags |= SUPPRESS_UI;
  687.  
  688.         if( ValidateStateDlg.m_bFlag2 )                
  689.             ulFlags |= REFRESH_XP_HEADER_CACHE;
  690.  
  691.         if( ValidateStateDlg.m_bFlag3 )                
  692.             ulFlags |= PROCESS_XP_HEADER_CACHE;
  693.  
  694.         if( ValidateStateDlg.m_bFlag4 )                
  695.             ulFlags |= FORCE_XP_CONNECT;
  696.  
  697.         if( ValidateStateDlg.m_bFlag5 )                
  698.             ulFlags |= FORCE_XP_DISCONNECT;
  699.  
  700.         if( ValidateStateDlg.m_bFlag6 )                
  701.             ulFlags |= CONFIG_CHANGED;
  702.                 
  703.         if( HR_FAILED(hResult = m_lpStatus->ValidateState(
  704.                         ulUIParam,
  705.                         ulFlags ) ) ) 
  706.         {
  707.             MessageBox( E.SzError("lpStatus->ValidateState()",
  708.                      hResult),"Client", MBS_ERROR );
  709.             return;
  710.         }        
  711.     }
  712.  
  713.  
  714. }
  715.  
  716. /********************************************************************/
  717.  
  718. void CStatusDlg::OnSettingsDialog()
  719. {
  720.     HRESULT         hResult         = hrSuccess;
  721.     COperation      SettingsDlg(this);
  722.     ULONG           ulFlags             = 0;
  723.     CGetError       E;
  724.     ULONG           ulUIParam       = 0;
  725.     int             dRet            = 0;
  726.     char            szBuff[80];        
  727.  
  728.     SettingsDlg.m_CurrentOperation= "lpStatus->SettingsDialog()";
  729.     SettingsDlg.m_CBText1         = "ulUIParam:";
  730.     SettingsDlg.m_FlagText1       = "UI_READONLY";
  731.     SettingsDlg.m_FlagText2       = "Invalid Flag";
  732.  
  733.     dRet = SettingsDlg.m_CBContents1.Add("NULL");
  734.     wsprintf(szBuff,"Parent hWnd == %X",this->m_hWnd);
  735.     dRet = SettingsDlg.m_CBContents1.Add(szBuff);
  736.  
  737.     // bring up modal dialog box, and if user hits OK, process operation
  738.     if( SettingsDlg.DoModal() == IDOK )   
  739.     {       
  740.         if( !lstrcmp(SettingsDlg.m_szCB1,"NULL") )
  741.             ulUIParam = (ULONG)NULL;
  742.         else
  743.             ulUIParam = (ULONG)(void *)this->m_hWnd;                    
  744.  
  745.         if( SettingsDlg.m_bFlag1 )                
  746.             ulFlags |= UI_READONLY;
  747.  
  748.         if( SettingsDlg.m_bFlag2 )                
  749.             ulFlags |= TEST_INVALID_FLAG;
  750.                 
  751.         if( HR_FAILED(hResult = m_lpStatus->SettingsDialog(
  752.                         ulUIParam,
  753.                         ulFlags ) ) ) 
  754.         {
  755.             MessageBox( E.SzError("lpStatus->SettingsDialog()",
  756.                      hResult),"Client", MBS_ERROR );
  757.             return;
  758.         }        
  759.     }
  760. }
  761.  
  762. /********************************************************************/
  763.  
  764. void CStatusDlg::OnFlushQueues()
  765. {
  766.     HRESULT         hResult         = hrSuccess;
  767.     COperation      FlushQueuesDlg(this);
  768.     ULONG           ulFlags         = 0;
  769.     CGetError       E;
  770.     ULONG           ulUIParam       = 0;
  771.     int             dRet            = 0;
  772.     char            szBuff[80];        
  773.  
  774.     FlushQueuesDlg.m_CurrentOperation= "lpStatus->FlushQueues()";
  775.     FlushQueuesDlg.m_CBText1         = "ulUIParam:";
  776.     FlushQueuesDlg.m_FlagText1       = "FLUSH_NO_UI";
  777.     FlushQueuesDlg.m_FlagText2       = "FLUSH_UPLOAD";
  778.     FlushQueuesDlg.m_FlagText3       = "FLUSH_DOWNLOAD";
  779.     FlushQueuesDlg.m_FlagText4       = "FLUSH_FORCE";
  780.     FlushQueuesDlg.m_FlagText5       = "Invalid Flag";
  781.  
  782.     FlushQueuesDlg.m_EditText1       = "cbTargetXport:";
  783.     FlushQueuesDlg.m_EditText2       = "lpTargetXport:";
  784.     FlushQueuesDlg.m_EditText3       = "Target DisplayName:";
  785.     
  786.     wsprintf(szBuff,"%lu",m_cbEntryIDTargetXport);    
  787.     FlushQueuesDlg.m_EditDefault1    = szBuff;
  788.  
  789.     wsprintf(szBuff,"0x%X",m_lpEntryIDTargetXport);    
  790.     FlushQueuesDlg.m_EditDefault2    = szBuff;
  791.  
  792.     FlushQueuesDlg.m_EditDefault3    = m_szTargetXport;
  793.  
  794.     dRet = FlushQueuesDlg.m_CBContents1.Add("NULL");
  795.     wsprintf(szBuff,"Parent hWnd == %X",this->m_hWnd);
  796.     dRet = FlushQueuesDlg.m_CBContents1.Add(szBuff);
  797.  
  798.     // bring up modal dialog box, and if user hits OK, process operation
  799.     if( FlushQueuesDlg.DoModal() == IDOK )   
  800.     {       
  801.         if( !lstrcmp(FlushQueuesDlg.m_szCB1,"NULL") )
  802.             ulUIParam = (ULONG)NULL;
  803.         else
  804.             ulUIParam = (ULONG)(void *)this->m_hWnd;                    
  805.  
  806.         if( FlushQueuesDlg.m_bFlag1 )                
  807.             ulFlags |= FLUSH_NO_UI;
  808.  
  809.         if( FlushQueuesDlg.m_bFlag2 )                
  810.             ulFlags |= FLUSH_UPLOAD;
  811.  
  812.         if( FlushQueuesDlg.m_bFlag3 )                
  813.             ulFlags |= FLUSH_DOWNLOAD;
  814.  
  815.         if( FlushQueuesDlg.m_bFlag4 )                
  816.             ulFlags |= FLUSH_FORCE;
  817.  
  818.         if( FlushQueuesDlg.m_bFlag5 )                
  819.             ulFlags |= TEST_INVALID_FLAG;
  820.                 
  821.         if( HR_FAILED(hResult = m_lpStatus->FlushQueues(
  822.                         ulUIParam,
  823.                         m_cbEntryIDTargetXport,
  824.                         m_lpEntryIDTargetXport,
  825.                         ulFlags ) ) ) 
  826.         {
  827.             MessageBox( E.SzError("lpStatus->FlushQueues()",
  828.                      hResult),"Client", MBS_ERROR );
  829.             return;
  830.         }        
  831.     }
  832. }
  833.  
  834. /********************************************************************/
  835.  
  836. void CStatusDlg::OnChangePassword()
  837. {
  838.     HRESULT         hResult         = hrSuccess;
  839.     COperation      ChangePasswordDlg(this);
  840.     ULONG           ulFlags             = 0;
  841.     CGetError       E;
  842.     LPWSTR          lpNewBuffer1        = NULL;
  843.     LPWSTR          lpNewBuffer2        = NULL;
  844.  
  845.     // initalize data for dialog box
  846.     ChangePasswordDlg.m_CurrentOperation= "lpStatus->ChangePassword()";
  847.     ChangePasswordDlg.m_EditText1       = "lpOldPass:";
  848.     ChangePasswordDlg.m_EditText2       = "lpNewPass:";
  849.     ChangePasswordDlg.m_FlagText1       = "MAPI_UNICODE";
  850.     ChangePasswordDlg.m_FlagText2       = "Invalid Flag";
  851.     ChangePasswordDlg.m_EditDefault1    = "Enter your old password here";
  852.     ChangePasswordDlg.m_EditDefault2    = "Enter your new password here";
  853.  
  854.     // bring up modal dialog box, and if user hits OK, process operation
  855.     if( ChangePasswordDlg.DoModal() == IDOK )   
  856.     {       
  857.         // determine state/settings of data in dialog upon closing
  858.         if( ChangePasswordDlg.m_bFlag2 )                
  859.             ulFlags |= TEST_INVALID_FLAG;
  860.                 
  861.         if( ChangePasswordDlg.m_bFlag1 )                
  862.         {
  863.             ulFlags |= MAPI_UNICODE;
  864.  
  865.             String8ToUnicode(ChangePasswordDlg.m_szEdit1, &lpNewBuffer1, NULL);
  866.             String8ToUnicode(ChangePasswordDlg.m_szEdit2, &lpNewBuffer2, NULL);
  867.  
  868.             if( HR_FAILED(hResult = m_lpStatus->ChangePassword(
  869.                             (LPTSTR) lpNewBuffer1,
  870.                             (LPTSTR) lpNewBuffer2,
  871.                             ulFlags ) ) ) 
  872.             {
  873.                 MessageBox( E.SzError("lpStatus->ChangePassword()",
  874.                          hResult),"Client", MBS_ERROR );
  875.                 return;
  876.             }        
  877.         
  878.             PvFree(lpNewBuffer1);
  879.             PvFree(lpNewBuffer2);
  880.         }
  881.         else
  882.         {
  883.  
  884.             if( HR_FAILED(hResult = m_lpStatus->ChangePassword(
  885.                             (LPTSTR) ChangePasswordDlg.m_szEdit1,
  886.                             (LPTSTR) ChangePasswordDlg.m_szEdit2,
  887.                             ulFlags ) ) ) 
  888.             {
  889.                 MessageBox( E.SzError("lpStatus->ChangePassword()",
  890.                          hResult),"Client", MBS_ERROR );
  891.                 return;
  892.             }        
  893.         }
  894.     }
  895. }
  896.  
  897. /********************************************************************/
  898.  
  899. void CStatusDlg::OnRegisterNotification()
  900. {
  901.     MessageBox("TEST Not Yet Implemented", "INFO", MBS_INFO );
  902.  
  903. }
  904.  
  905. /*******************************************************************/
  906. /*
  907.  -  CStatusDlg::
  908.  -  OnCancel
  909.  -
  910.  *  Purpose:
  911.  *
  912.  */
  913. /*******************************************************************/
  914.  
  915. void CStatusDlg::OnCancel()
  916. {
  917.     if (hlibPROPVU)
  918.     {
  919.         FreeLibrary (hlibPROPVU);
  920.         hlibPROPVU = (HINSTANCE) NULL;
  921.     }
  922.  
  923.     EndDialog(IDCANCEL);
  924. }
  925.  
  926.  
  927. /********************************************************************/
  928. /********************** CGetError Member Functions ******************/
  929. /*******************************************************************/
  930.  
  931. /********************************************************************/
  932. /*
  933.  -  CGetError::
  934.  -  SzError       SCODE and ULONG
  935.  -
  936.  *  Purpose:
  937.  *      For printable Error String.  Uses the stringtable
  938.  *      technology from mapitest.
  939.  *
  940.  *  Parameters:
  941.  *      szMsg       - Message Text
  942.  *      scResult    - Error Code
  943.  *
  944.  *  Returns:
  945.  *      szError     - Textized information
  946.  *
  947.  */
  948. /********************************************************************/
  949.  
  950. LPSTR CGetError::SzError( LPSTR szMsg, SCODE scResult )
  951. {
  952.     wsprintf( m_szMessage, "%s: ", szMsg );
  953.  
  954.     if(!GetString( "MAPIErrors", scResult, m_szResult ))
  955.     {
  956.         lstrcpy(  m_szResult, "??" );
  957.         wsprintf( m_szBuffer, " %04X", scResult );
  958.         lstrcat(  m_szResult, m_szBuffer );
  959.     }
  960.  
  961.     lstrcat( m_szMessage, m_szResult );
  962.  
  963.     return m_szMessage;
  964. }
  965.  
  966. /********************************************************************/
  967.  
  968. #ifdef WIN16          
  969. LPSTR CGetError::SzError( LPSTR szMsg, HRESULT hResult )
  970. {
  971.     return( SzError(szMsg, GetScode(hResult) ) );
  972. }
  973.  
  974. #endif
  975.  
  976.  
  977.  
  978. /*******************************************************************/
  979. /*******************************************************************/
  980. /*******************************************************************/
  981.  
  982.  
  983. /*--------------------*/
  984. /* Library Init stuff */
  985. /*--------------------*/
  986.  
  987. class CStatViewDLL : public CWinApp
  988. {
  989. public:
  990.     virtual BOOL InitInstance();
  991.     virtual BOOL ExitInstance();
  992.  
  993.     CStatViewDLL(const char *pszAppName)
  994.             : CWinApp(pszAppName)
  995.         {
  996.         }
  997. };
  998.  
  999. BOOL CStatViewDLL::InitInstance()
  1000. {
  1001.     SetDialogBkColor();
  1002.     return TRUE;
  1003. }
  1004.  
  1005.  
  1006. BOOL CStatViewDLL::ExitInstance()
  1007. {
  1008.     return TRUE;
  1009. }
  1010.  
  1011. CStatViewDLL  vtDLL("statvu32.dll");
  1012.