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

  1. /*
  2.  -  A B V I E W . C P P
  3.  -  Copyright (C) 1995 Microsoft Corporation
  4.  -
  5.  *  Purpose:
  6.  *      Main source module for ABVIEW.  This is an MFC application.
  7.  *
  8.  */
  9.  
  10. #ifndef _WIN95
  11.     #define CTL3D
  12. #endif
  13.  
  14. #define CROWSREQUESTED 20
  15.  
  16. #include <memory.h>
  17. #include <stdarg.h>
  18.  
  19. #ifdef WIN32
  20. #ifdef _WIN95
  21. #define _INC_OLE
  22. #endif
  23. #define INC_OLE2
  24. #define INC_RPC
  25. #endif
  26.  
  27. #include <afxwin.h>
  28.  
  29. #ifdef WIN16
  30. #include <compobj.h>
  31. #endif
  32.  
  33. #ifdef WIN32
  34. #include <objbase.h>
  35. #include <objerror.h>
  36. #ifdef _WIN95
  37. #include <ole2.h>
  38. #endif
  39. #endif
  40.  
  41. #ifdef CTL3D
  42.     #include <ctl3d.h>
  43. #endif
  44.  
  45. #include <mapiwin.h>
  46. #include <mapix.h>
  47. #include <strtbl.h>
  48. #include <misctool.h>
  49.  
  50. #include "resource.h"
  51. #include "tbllist.h"
  52. #include "abview.h"
  53.  
  54. HINSTANCE hlibTBLVU = (HINSTANCE)NULL;
  55. LPFNVIEWMAPITABLE lpfnViewMapiTable = NULL;
  56.  
  57. HINSTANCE hlibPROPVU = (HINSTANCE)NULL;
  58. LPFNVIEWMAPIPROP lpfnViewMapiProp = NULL;
  59.  
  60. HINSTANCE hlibPERF = (HINSTANCE)NULL;
  61. LPFNPERFORMANCE lpfnPerformance = NULL;
  62.  
  63. HINSTANCE hlibTEST = (HINSTANCE)NULL;
  64. LPFNTEST lpfnTest = NULL;
  65.  
  66. LPMAPISESSION   lpSession       = NULL;
  67. LPADRBOOK       lpAdrBook       = NULL;
  68. ULONG           ulModlessABHwnd = 0;
  69.  
  70. /*
  71.  -  Global Variables
  72.  */
  73.  
  74. BOOL        fOpenEntry        = FALSE;
  75. BOOL        fSetAsTarget      = FALSE;
  76. BOOL        fUseUNICODE       = FALSE;
  77. BOOL        fQueryForTable    = FALSE;
  78. BOOL        fUNICODE          = FALSE;
  79. BOOL        fCONVENIENT_DEPTH = FALSE;
  80. BOOL        fObjectType       = FALSE;
  81. CFont*      pBoldFont         = NULL;
  82. CFont*      pNormFont         = NULL;
  83. CFont*      pLightFont        = NULL;
  84. ULONG       cbTargetEntryID   = 0;
  85. LPENTRYID   lpTargetEntryID   = NULL;
  86.  
  87. LPSPropTagArray ABH_PropTagArray = NULL;
  88.  
  89. /*
  90.  -  Support Function Prototypes
  91.  */
  92.  
  93. void  _FreeRowSet( LPSRowSet );
  94. void  DisplayError( LPUNKNOWN, HRESULT, LPSTR );
  95. SCODE ScGetRow( LPMAPITABLE, int, LPSRowSet * );
  96. SCODE ScOpenEntry( ULONG, LPENTRYID, ULONG, ULONG, BOOL );
  97. void  CreateMAPIGuid( LPGUID );
  98.  
  99. CTheApp theApp;
  100.  
  101. /*
  102.  *  CTheApp Methods.
  103.  */
  104.  
  105. /*
  106.  -  InitInstance
  107.  -
  108.  *  Purpose:
  109.  *      When any CTheApp object is created, this member function is
  110.  *      automatically  called.  The main window of the application
  111.  *      is created and shown here.
  112.  *
  113.  *  Parameters:
  114.  *      None
  115.  *
  116.  *  Returns:
  117.  *      TRUE if the initialization is successful.
  118.  *
  119.  */
  120.  
  121. BOOL CTheApp::InitInstance()
  122. {
  123.     CRect rect;
  124.     m_MainWnd.LoadAccelTable( "MainAccelTable" );
  125.     MAPIInitialize(NULL);
  126.  
  127. #ifdef CTL3D
  128.     Ctl3dRegister( AfxGetInstanceHandle() );   // Register Ctl3D controls
  129.     Ctl3dAutoSubclass( AfxGetInstanceHandle());
  130. #endif
  131.  
  132.     rect.SetRect(MW_LEFT, MW_TOP, MW_RIGHT, MW_BOTTOM);
  133.  
  134.     if(!m_MainWnd.Create( NULL,
  135.                             "Client Test Application",
  136.                             WS_OVERLAPPEDWINDOW,
  137.                             rect,
  138.                             NULL,
  139.                             MAKEINTRESOURCE(AFX_IDI_STD_FRAME)/*menu*/))
  140.     return FALSE;
  141.  
  142.     TRACE( "ABClnt\n" );
  143.     m_pMainWnd = &m_MainWnd;
  144.     m_MainWnd.ShowWindow( m_nCmdShow );
  145.     m_MainWnd.UpdateWindow();
  146.  
  147.     m_MainWnd.SetupOnStart();
  148.     m_MainWnd.CreateDisplayFonts();
  149.  
  150.     return TRUE;
  151. }
  152.  
  153. /*
  154.  -  ExitInstance
  155.  -
  156.  *  Purpose:
  157.  *      When a CWinApp application is exited, this function is
  158.  *      automatically called.
  159.  *
  160.  *  Parameters:
  161.  *      None
  162.  *
  163.  *  Returns:
  164.  *      TRUE if the Exit is successful.
  165.  *
  166.  */
  167.  
  168. int CTheApp::ExitInstance()
  169. {
  170.  
  171. #ifdef CTL3D
  172.     Ctl3dUnregister(AfxGetInstanceHandle());
  173. #endif
  174.  
  175.     m_MainWnd.DeleteDisplayFonts();
  176.  
  177.     return CWinApp::ExitInstance();
  178. }
  179.  
  180.  
  181. /*
  182.  -  PreTranslateMessage
  183.  -
  184.  *  Purpose:
  185.  *      Allow this application to filter window messages.  This is needed
  186.  *      for the 0 Well Address case.  The dialog must tie into the message
  187.  *      loop.
  188.  *
  189.  *  Parameters:
  190.  *      Pointer to a message structure containing the message to process
  191.  *
  192.  *  Returns:
  193.  *      TRUE if the message was fully processed and should not be passed
  194.  *      to TranslateMessage and PreTranslateMessage.  FALSE if the message
  195.  *      should be processed in the normal way.
  196.  *
  197.  */
  198.  
  199. BOOL CTheApp::PreTranslateMessage(MSG* pMsg)
  200. {
  201.     if (!ulModlessABHwnd || !IsDialogMessage((HWND) ulModlessABHwnd, pMsg))
  202.     {
  203.         return CWinApp::PreTranslateMessage(pMsg);
  204.     }
  205.     
  206.     return TRUE;
  207. }
  208.  
  209. /*
  210.  *  CMainWindow Methods.
  211.  */
  212.  
  213.  
  214. /*
  215.  -  CMainWindow::
  216.  -  OnAbout
  217.  -
  218.  *  Purpose:
  219.  *      Create a CModalDialog object using the "AboutBox" resource.
  220.  *
  221.  */
  222.  
  223. void CMainWindow::OnAbout()
  224. {
  225.     CModalDialog about( "AboutBox", this );
  226.     about.DoModal();
  227. }
  228.  
  229.  
  230. /*
  231.  -  CMainWindow::
  232.  -  SetupOnStart
  233.  -
  234.  *  Purpose:
  235.  *      Called on Startup of Application.  Initializes the
  236.  *      Address Book viewer application.
  237.  *
  238.  */
  239.  
  240. void CMainWindow::SetupOnStart()
  241. {
  242.     int     nOpenEntry;
  243.     int     nSetAsTarget;
  244.     int     nUseUNICODE;
  245.     int     nUNICODE;
  246.     int     nCONVENIENT_DEPTH;
  247.     int     nQueryForTable;
  248.     int     nObjectType;
  249.  
  250.     m_bAutoMenuEnable = FALSE; /*Menu to work like MFC1*/
  251.     CMenu* menu = GetMenu();
  252.  
  253.     menu->EnableMenuItem( IDM_LOGON,            MF_GRAYED );
  254.     menu->EnableMenuItem( IDM_LOGOFF,           MF_GRAYED );
  255.     menu->EnableMenuItem( IDM_ROOTCONTAINER,    MF_GRAYED );
  256.     menu->EnableMenuItem( IDM_ADDRESS0,         MF_GRAYED );
  257.     menu->EnableMenuItem( IDM_ADDRESS1,         MF_GRAYED );
  258.     menu->EnableMenuItem( IDM_ADDRESS2,         MF_GRAYED );
  259.     menu->EnableMenuItem( IDM_ADDRESS3,         MF_GRAYED );
  260.     menu->EnableMenuItem( IDM_RESOLVENAME,      MF_GRAYED );
  261.     menu->EnableMenuItem( IDM_CREATEONEOFF,     MF_GRAYED );
  262.     menu->EnableMenuItem( IDM_NEWENTRY,         MF_GRAYED );
  263.     menu->EnableMenuItem( IDM_PREPARERECIPS,    MF_GRAYED );
  264.  
  265.     CMainWindow::LoadDlls();
  266.     CMainWindow::OnLogon();
  267.  
  268.     if( (nOpenEntry = GetProfileInt( "ABView", "OPENENTRY", 0)) == 1)
  269.         fOpenEntry = TRUE;
  270.  
  271.     if( (nSetAsTarget = GetProfileInt( "ABView", "SETASTARGET", 0)) == 1)
  272.         fSetAsTarget = TRUE;
  273.  
  274.     if( (nUseUNICODE = GetProfileInt( "ABView", "UNICODE", 0)) == 1)
  275.         fUseUNICODE = TRUE;
  276.         
  277.     if( (nUNICODE = GetProfileInt( "ABView", "UNICODEFLAG", 0)) == 1)
  278.         fUNICODE = TRUE;
  279.  
  280.     if( (nCONVENIENT_DEPTH = GetProfileInt( "ABView", "DEPTHFLAG", 0)) == 1)
  281.         fCONVENIENT_DEPTH = TRUE;
  282.         
  283.     if( (nQueryForTable = GetProfileInt( "ABView", "QUERYTABLE", 0)) == 1)
  284.         fQueryForTable = TRUE;
  285.  
  286.     if( (nObjectType = GetProfileInt( "ABView", "OBJECTTYPE", 0)) == 1)
  287.         fObjectType = TRUE;
  288.  
  289.     if(fUNICODE)
  290.         ABH_PropTagArray = (LPSPropTagArray)&ABHW_PropTagArray;
  291.     else
  292.         ABH_PropTagArray = (LPSPropTagArray)&ABHN_PropTagArray;
  293. }
  294.  
  295.  
  296. /*
  297.  -
  298.  -  CMainWindow::
  299.  -  LoadDlls
  300.  -
  301.  *  Purpose:
  302.  *      Loads Extensibility DLLs into Memory.
  303.  *
  304.  */
  305.  
  306. void CMainWindow::LoadDlls()
  307. {
  308.     char *  szTablevu;
  309.     char    szTblLibName[124];
  310.     char    szPrpLibName[124];
  311.     char    szPerLibName[124];
  312.     char    szTstLibName[124];
  313.     char    szMsgBuf[256];
  314.  
  315. //Check for an alternate Tablevu DLL from the win.ini.  If there is one, then
  316. //attempt to load it.  If the DLL can't load, then deactivate access to
  317. //Tablevu
  318. #ifdef WIN16
  319.     szTablevu = "tblvu.dll";
  320. #else
  321.     szTablevu = "tblvu32.dll";
  322. #endif
  323.  
  324.     GetProfileString( "ABView", "TABLEVUDLLNAME", szTablevu, szTblLibName, sizeof(szTblLibName) );
  325.  
  326. #ifdef WIN16
  327.     if ((UINT)(hlibTBLVU = LoadLibrary (szTblLibName)) < 32)
  328. #else
  329.     if (!(hlibTBLVU = LoadLibrary (szTblLibName)))
  330. #endif
  331.     {
  332.         //Since this application can run without any Extensibility DLL
  333.         //being loaded, the following warning box will not be displayed
  334.         //for the Tablevu feature.  Abview defaults to load a DLL named
  335.         //tblvu.dll, even when it has no entry in the Profile.  This
  336.         //warning can become anoying.
  337.  
  338.         hlibTBLVU = (HINSTANCE) NULL;
  339.         goto out;
  340.     }
  341.  
  342.     if (!(lpfnViewMapiTable = (LPFNVIEWMAPITABLE)GetProcAddress (hlibTBLVU, "ViewMapiTable") ))
  343.     {
  344.         MessageBox("Cannot Load ViewMapiTable process address.","Error", MB_ICONSTOP | MB_OK);
  345.         FreeLibrary (hlibTBLVU);
  346.         hlibTBLVU = (HINSTANCE) NULL;
  347.         goto out;
  348.     }
  349.  
  350. out:
  351.  
  352.  
  353.         //Attempt to load a Propvu DLL.  If the DLL can't load, or one is not
  354.         //listed to load, then this function is deactivated.
  355.  
  356.     GetProfileString( "ABView", "PROPVUDLLNAME", "", szPrpLibName, sizeof(szPrpLibName) );
  357.  
  358.     if (*szPrpLibName)
  359.     {
  360. #ifdef WIN16
  361.         if ((UINT)(hlibPROPVU = LoadLibrary (szPrpLibName)) < 32)
  362. #else
  363.         if (!(hlibPROPVU = LoadLibrary (szPrpLibName)))
  364. #endif
  365.         {
  366.             wsprintf(szMsgBuf,"Cannot Load %s.  Propvu Feature will be turned off.", szPrpLibName);
  367.             MessageBox(szMsgBuf,"Error", MB_ICONSTOP | MB_OK);
  368.             hlibPROPVU = (HINSTANCE) NULL;
  369.             goto out2;
  370.         }
  371.  
  372.         if (!(lpfnViewMapiProp = (LPFNVIEWMAPIPROP)GetProcAddress (hlibPROPVU, "ViewMapiProp") ))
  373.         {
  374.             MessageBox("Cannot Load ViewMapiProp process address.","Error", MB_ICONSTOP | MB_OK);
  375.             FreeLibrary (hlibPROPVU);
  376.             hlibPROPVU = (HINSTANCE) NULL;
  377.             goto out2;
  378.         }
  379.     }
  380.  
  381. out2:
  382.  
  383. //Attempt to load a performance DLL.  If the DLL can't load, or one is not
  384. //listed to load, then performance is deactivated.
  385.  
  386.     GetProfileString( "ABView", "PERFDLLNAME", "", szPerLibName, sizeof(szPerLibName) );
  387.  
  388.     if (*szPerLibName)
  389.     {
  390. #ifdef WIN16
  391.         if ((UINT)(hlibPERF = LoadLibrary (szPerLibName)) < 32)
  392. #else
  393.         if (!(hlibPERF = LoadLibrary (szPerLibName)))
  394. #endif
  395.         {
  396.             wsprintf(szMsgBuf,"Cannot Load %s.  Performance Feature will be turned off.", szPerLibName);
  397.             MessageBox(szMsgBuf,"Error", MB_ICONSTOP | MB_OK);
  398.             hlibPERF = (HINSTANCE) NULL;
  399.             goto out3;
  400.         }
  401.  
  402.         if (!(lpfnPerformance  =  (LPFNPERFORMANCE)GetProcAddress (hlibPERF, "ABPerformance") ))
  403.         {
  404.             MessageBox("Cannot Load ABPerformance process address.","Error", MB_ICONSTOP | MB_OK);
  405.             FreeLibrary (hlibPERF);
  406.             hlibPERF = (HINSTANCE) NULL;
  407.             goto out3;
  408.         }
  409.     }
  410.  
  411. out3:
  412.  
  413. //Attempt to load a test DLL.  If the DLL can't load, or one is not
  414. //listed to load, then test is deactivated.
  415.  
  416.     GetProfileString( "ABView", "TESTDLLNAME", "", szTstLibName, sizeof(szTstLibName) );
  417.  
  418.     if (*szTstLibName)
  419.     {
  420. #ifdef WIN16
  421.     if ((UINT)(hlibTEST = LoadLibrary (szTstLibName)) < 32)
  422. #else
  423.     if (!(hlibTEST = LoadLibrary (szTstLibName)))
  424. #endif
  425.     {
  426.         wsprintf(szMsgBuf,"Cannot Load %s.  Test Feature will be turned off.", szTstLibName);
  427.         MessageBox(szMsgBuf,"Error", MB_ICONSTOP | MB_OK);
  428.         hlibTEST = (HINSTANCE) NULL;
  429.         goto out4;
  430.     }
  431.  
  432.     if (!(lpfnTest  =  (LPFNTEST)GetProcAddress (hlibTEST, "ABTest") ))
  433.     {
  434.         MessageBox("Cannot Load ABTest process address.","Error", MB_ICONSTOP | MB_OK);
  435.         FreeLibrary (hlibTEST);
  436.         hlibTEST = (HINSTANCE) NULL;
  437.         goto out4;
  438.     }
  439. }
  440.  
  441. out4: {}
  442.  
  443. }
  444.  
  445.  
  446. /*
  447.  -
  448.  -  CMainWindow::
  449.  -  UnloadDlls
  450.  -
  451.  *  Purpose:
  452.  *      Unloads Extensibility DLLs from Memory.
  453.  *
  454.  */
  455.  
  456. void CMainWindow::UnloadDlls()
  457. {
  458.     if (hlibTBLVU)
  459.     {
  460.         FreeLibrary (hlibTBLVU);
  461.         hlibTBLVU = (HINSTANCE) NULL;
  462.     }
  463.  
  464.     if (hlibPROPVU)
  465.     {
  466.         FreeLibrary (hlibPROPVU);
  467.         hlibPROPVU = (HINSTANCE) NULL;
  468.     }
  469.  
  470.     if (hlibPERF)
  471.     {
  472.         FreeLibrary (hlibPERF);
  473.         hlibPERF = (HINSTANCE) NULL;
  474.     }
  475.  
  476.     if (hlibTEST)
  477.     {
  478.         FreeLibrary (hlibTEST);
  479.         hlibTEST = (HINSTANCE) NULL;
  480.     }
  481. }
  482.  
  483.  
  484. /*
  485.  -  CMainWindow::
  486.  -  OnExit
  487.  -
  488.  *  Purpose:
  489.  *      Asks the application to Close itself.
  490.  *
  491.  */
  492.  
  493. void CMainWindow::OnExit()
  494. {
  495.     SendMessage( WM_CLOSE );
  496. }
  497.  
  498.  
  499. /*
  500.  -  CMainWindow::
  501.  -  OnClose
  502.  *
  503.  *  Purpose:
  504.  *      This displays a dialog querying the user if they would like to
  505.  *      close this application.  If yes, then then a call is made to
  506.  *      ensure that the user has logged off prior to ending the session.
  507.  *
  508.  */
  509.  
  510. void CMainWindow::OnClose()
  511. {
  512.     OnLogoff();
  513.     MAPIUninitialize();
  514.     CMainWindow::UnloadDlls();
  515.     DestroyWindow();
  516. }
  517.  
  518.  
  519. /*
  520.  -  CMainWindow::
  521.  -  PostNcDestroy
  522.  *
  523.  *  Purpose:
  524.  *      Catch the WM_DESTROY window message.
  525.  *
  526.  *      Cleanup of the main window will occur in the OnClose function, with
  527.  *      the DestroyWindow() call.
  528.  *
  529.  *      ExitInstance() will perform the remaining cleanup.
  530.  *
  531.  */
  532.  
  533. void CMainWindow::PostNcDestroy()
  534. {
  535.     //Don't delete this.  This is required for 16Bit MFC to exit gracefully.
  536. }
  537.  
  538.  
  539. /*
  540.  -  CMainWindow::
  541.  -  OnSysColorChange
  542.  *
  543.  *  Purpose:
  544.  *      Handles changing the applications colors when a system
  545.  *      color change is requested.  This message overide is
  546.  *      required when using Ctrl3D to display windows.
  547.  *
  548.  */
  549.  
  550. void CMainWindow::OnSysColorChange()
  551. {
  552. #ifdef CTL3D
  553.     Ctl3dColorChange();
  554. #else
  555.     CMainWindow::OnSysColorChange();
  556. #endif
  557. }
  558.  
  559. /*
  560.  -  CMainWindow::
  561.  -  OnConfig
  562.  *
  563.  *  Purpose:
  564.  *      Allows for easy modification of the abview section of the
  565.  *      win.ini.  This section is used for configuring the test DLLs
  566.  *      to be called when exercising objects and tables.
  567.  *
  568.  */
  569.  
  570. void CMainWindow::OnConfig()
  571. {
  572.     CConfigureDlg dlgConfigure;
  573. }
  574.  
  575. /*
  576.  -  CConfigureDlg::
  577.  -  OnInitDialog
  578.  *
  579.  *  Purpose:
  580.  *
  581.  */
  582.  
  583. BOOL CConfigureDlg::OnInitDialog()
  584. {
  585.     char *  szTablevu;
  586.     char    szTblLibName[124];
  587.     char    szPrpLibName[124];
  588.     char    szPerLibName[124];
  589.     char    szTstLibName[124];
  590.     int     nOpenEntry          = 0;
  591.     int     nSetAsTarget        = 0;
  592.     int     nUseUNICODE         = 0;
  593.     int     nUNICODE            = 0;
  594.     int     nCONVENIENT_DEPTH   = 0;
  595.     int     nQueryForTable      = 0;
  596.     int     nObjectType         = 0;
  597.  
  598. #ifdef WIN16
  599.     szTablevu = "tblvu.dll";
  600. #else
  601.     szTablevu = "tblvu32.dll";
  602. #endif
  603.  
  604.     GetProfileString( "ABView", "TABLEVUDLLNAME", szTablevu, szTblLibName, sizeof(szTblLibName) );
  605.     GetProfileString( "ABView", "PROPVUDLLNAME", "", szPrpLibName, sizeof(szPrpLibName) );
  606.     GetProfileString( "ABView", "PERFDLLNAME", "", szPerLibName, sizeof(szPerLibName) );
  607.     GetProfileString( "ABView", "TESTDLLNAME", "", szTstLibName, sizeof(szTstLibName) );
  608.  
  609.     if( (nOpenEntry = GetProfileInt( "ABView", "OPENENTRY", 0)) == 1)
  610.         fOpenEntry = TRUE;
  611.     else
  612.         fOpenEntry = FALSE;
  613.  
  614.     if( (nSetAsTarget = GetProfileInt( "ABView", "SETASTARGET", 0)) == 1)
  615.         fSetAsTarget = TRUE;
  616.     else
  617.         fSetAsTarget = FALSE;
  618.  
  619.     if( (nUseUNICODE = GetProfileInt( "ABView", "UNICODE", 0)) == 1)
  620.         fUseUNICODE = TRUE;
  621.     else
  622.         fUseUNICODE = FALSE;
  623.  
  624.     if( (nUNICODE = GetProfileInt( "ABView", "UNICODEFLAG", 0)) == 1)
  625.         fUNICODE = TRUE;
  626.     else
  627.         fUNICODE = FALSE;
  628.         
  629.     if( (nCONVENIENT_DEPTH = GetProfileInt( "ABView", "DEPTHFLAG", 0)) == 1)
  630.         fCONVENIENT_DEPTH = TRUE;
  631.     else
  632.         fCONVENIENT_DEPTH = FALSE;
  633.  
  634.     if( (nQueryForTable = GetProfileInt( "ABView", "QUERYTABLE", 0)) == 1)
  635.         fQueryForTable = TRUE;
  636.     else
  637.         fQueryForTable = FALSE;
  638.         
  639.     if( (nObjectType = GetProfileInt( "ABView", "OBJECTTYPE", 0)) == 1)
  640.         fObjectType = TRUE;
  641.     else
  642.         fObjectType = FALSE;
  643.  
  644.     SetDlgItemText(IDC_TABLEVUDLL,    szTblLibName );
  645.     SetDlgItemText(IDC_PROPERTYVUDLL, szPrpLibName );
  646.     SetDlgItemText(IDC_PERFDLL,       szPerLibName );
  647.     SetDlgItemText(IDC_TESTDLL,       szTstLibName );
  648.  
  649.     if(fOpenEntry)
  650.         CheckDlgButton(IDC_OPENENTRYF, 1);
  651.  
  652.     if(fSetAsTarget)
  653.         CheckDlgButton(IDC_SETTARGETCONTF, 1);
  654.  
  655.     if(fUseUNICODE)
  656.         CheckDlgButton(IDC_UNICODEF, 1);
  657.  
  658.     if(fUNICODE)
  659.         CheckDlgButton(IDC_UNICODEFLAG, 1);
  660.         
  661.     if(fCONVENIENT_DEPTH)
  662.         CheckDlgButton(IDC_CONVENIENTDEPTH, 1);
  663.  
  664.     if(fQueryForTable)
  665.         CheckDlgButton(IDC_TABLEREQUEST, 1);
  666.  
  667.     if(fObjectType)
  668.         CheckDlgButton(IDC_OBJECTTYPE, 1);
  669.  
  670.     return TRUE;
  671. }
  672.  
  673. /*
  674.  -  CConfigureDlg::
  675.  -  OnOK
  676.  *
  677.  *  Purpose:
  678.  *
  679.  */
  680.  
  681. void CConfigureDlg::OnOK()
  682. {
  683.     char * szSection   = "ABView";
  684.     char * szKeyTblLib = "TABLEVUDLLNAME";
  685.     char * szKeyPrpLib = "PROPVUDLLNAME";
  686.     char * szKeyPerLib = "PERFDLLNAME";
  687.     char * szKeyTstLib = "TESTDLLNAME";
  688.     char * szKeyOpenEntry = "OPENENTRY";
  689.     char * szKeySetAsTarget = "SETASTARGET";
  690.     char * szKeyUseUNICODE = "UNICODE";
  691.     char * szKeyUNICODEFLAG = "UNICODEFLAG";
  692.     char * szKeyCONVENIENTDEPTH = "DEPTHFLAG";
  693.     char * szKeyQueryForTable = "QUERYTABLE";
  694.     char * szKeyObjectType = "OBJECTTYPE";
  695.  
  696.     char szTblLibName[124];
  697.     char szPrpLibName[124];
  698.     char szPerLibName[124];
  699.     char szTstLibName[124];
  700.  
  701.     GetDlgItemText(IDC_TABLEVUDLL,    szTblLibName, 124);
  702.     GetDlgItemText(IDC_PROPERTYVUDLL, szPrpLibName, 124);
  703.     GetDlgItemText(IDC_PERFDLL,       szPerLibName, 124);
  704.     GetDlgItemText(IDC_TESTDLL,       szTstLibName, 124);
  705.     fOpenEntry = IsDlgButtonChecked( IDC_OPENENTRYF );
  706.     fSetAsTarget = IsDlgButtonChecked( IDC_SETTARGETCONTF );
  707.     fUseUNICODE = IsDlgButtonChecked( IDC_UNICODEF );
  708.     fUNICODE = IsDlgButtonChecked( IDC_UNICODEFLAG );
  709.     fCONVENIENT_DEPTH = IsDlgButtonChecked( IDC_CONVENIENTDEPTH );
  710.     fQueryForTable = IsDlgButtonChecked( IDC_TABLEREQUEST );
  711.     fObjectType = IsDlgButtonChecked( IDC_OBJECTTYPE );
  712.  
  713.     if( *szTblLibName )
  714.         WriteProfileString( szSection, szKeyTblLib, szTblLibName );
  715.     else
  716.         WriteProfileString( szSection, szKeyTblLib, NULL );
  717.  
  718.     if( *szPrpLibName )
  719.         WriteProfileString( szSection, szKeyPrpLib, szPrpLibName );
  720.     else
  721.         WriteProfileString( szSection, szKeyPrpLib, NULL );
  722.  
  723.     if( *szPerLibName )
  724.         WriteProfileString( szSection, szKeyPerLib, szPerLibName );
  725.     else
  726.         WriteProfileString( szSection, szKeyPerLib, NULL );
  727.  
  728.     if( *szTstLibName )
  729.         WriteProfileString( szSection, szKeyTstLib, szTstLibName );
  730.     else
  731.         WriteProfileString( szSection, szKeyTstLib, NULL );
  732.  
  733.     if(fOpenEntry)
  734.         WriteProfileString( szSection, szKeyOpenEntry, "1" );
  735.     else
  736.         WriteProfileString( szSection, szKeyOpenEntry, "0" );
  737.  
  738.     if(fSetAsTarget)
  739.         WriteProfileString( szSection, szKeySetAsTarget, "1" );
  740.     else
  741.         WriteProfileString( szSection, szKeySetAsTarget, "0" );
  742.  
  743.     if(fUseUNICODE)
  744.         WriteProfileString( szSection, szKeyUseUNICODE, "1" );
  745.     else
  746.         WriteProfileString( szSection, szKeyUseUNICODE, "0" );
  747.  
  748.     if(fUNICODE)
  749.         WriteProfileString( szSection, szKeyUNICODEFLAG, "1" );
  750.     else
  751.         WriteProfileString( szSection, szKeyUNICODEFLAG, "0" );
  752.  
  753.     if(fCONVENIENT_DEPTH)
  754.         WriteProfileString( szSection, szKeyCONVENIENTDEPTH, "1" );
  755.     else
  756.         WriteProfileString( szSection, szKeyCONVENIENTDEPTH, "0" );
  757.  
  758.     if(fQueryForTable)
  759.         WriteProfileString( szSection, szKeyQueryForTable, "1" );
  760.     else
  761.         WriteProfileString( szSection, szKeyQueryForTable, "0" );
  762.  
  763.     if(fObjectType)
  764.         WriteProfileString( szSection, szKeyObjectType, "1" );
  765.     else
  766.         WriteProfileString( szSection, szKeyObjectType, "0" );
  767.  
  768.     if(fUNICODE)
  769.         ABH_PropTagArray = (LPSPropTagArray)&ABHW_PropTagArray;
  770.     else
  771.         ABH_PropTagArray = (LPSPropTagArray)&ABHN_PropTagArray;
  772.  
  773.  
  774.     EndDialog(IDOK);
  775. }
  776.  
  777. /*
  778.  -  CConfigureDlg::
  779.  -  OnCancel
  780.  *
  781.  *  Purpose:
  782.  *
  783.  */
  784.  
  785. void CConfigureDlg::OnCancel()
  786. {
  787.     EndDialog(IDCANCEL);
  788. }
  789.  
  790.  
  791.  
  792. /*
  793.  -  CMainWindow::
  794.  -  OnLogon
  795.  *
  796.  *  Purpose:
  797.  *      Logs the user onto the Mail subsystem.  If the logon was
  798.  *      successful, then the Address Book is opened as well.  Menu
  799.  *      enabling is performed depending on the outcome of the calls.
  800.  *
  801.  */
  802.  
  803. void CMainWindow::OnLogon()
  804. {
  805.     CGetError   E;
  806.     CMenu       *menu       = GetMenu();
  807.     HRESULT     hResult     = NULL;
  808.     ULONG       ulUIParam   = (ULONG)(void *)m_hWnd;
  809.     ULONG       ulFlags     = 0;
  810.  
  811.     ulFlags = ulFlags | MAPI_LOGON_UI | MAPI_NO_MAIL | MAPI_EXTENDED;
  812.  
  813.     if(fUNICODE)
  814.     {
  815. #ifdef _WINNT    
  816.         ulFlags = ulFlags | MAPI_UNICODE;
  817.         if( FAILED( hResult = MAPILogonEx(  ulUIParam,
  818.                                     NULL,
  819.                                     NULL,
  820.                                     ulFlags,
  821.                                     (LPMAPISESSION FAR *) &lpSession )))
  822.         {
  823.             MessageBox( E.SzError("MAPILogon", hResult), "Client", MB_OK );
  824.             goto error;
  825.         }
  826. #else
  827.         AfxMessageBox( "UNICODE not supported on this OS.", MB_ICONEXCLAMATION | MB_OK, 0 );
  828. #endif        
  829.     }
  830.     else
  831.     {
  832.         if( FAILED(hResult = MAPILogonEx( ulUIParam,
  833.                                     NULL,
  834.                                     NULL,
  835.                                     ulFlags,
  836.                                     (LPMAPISESSION FAR *) &lpSession )))
  837.         {
  838.             MessageBox( E.SzError("MAPILogon", hResult), "Client", MB_OK );
  839.             goto error;
  840.         }
  841.     }
  842.  
  843.     menu->EnableMenuItem( IDM_LOGON,    MF_GRAYED | MF_DISABLED );
  844.     menu->EnableMenuItem( IDM_LOGOFF,   MF_ENABLED );
  845.  
  846.     if( hResult = lpSession->OpenAddressBook( (ULONG)(void *)m_hWnd,
  847.                                 NULL,
  848.                                 0,
  849.                                 &lpAdrBook ))
  850.     {
  851.         DisplayError( lpSession, hResult, "OpenAddressBook" );
  852.         if( FAILED(hResult))
  853.             goto error;
  854.     }
  855.  
  856.     menu->EnableMenuItem( IDM_ROOTCONTAINER,    MF_ENABLED );
  857.     menu->EnableMenuItem( IDM_ADDRESS0,         MF_ENABLED );
  858.     menu->EnableMenuItem( IDM_ADDRESS1,         MF_ENABLED );
  859.     menu->EnableMenuItem( IDM_ADDRESS2,         MF_ENABLED );
  860.     menu->EnableMenuItem( IDM_ADDRESS3,         MF_ENABLED );
  861.     menu->EnableMenuItem( IDM_RESOLVENAME,      MF_ENABLED );
  862.     menu->EnableMenuItem( IDM_CREATEONEOFF,     MF_ENABLED );
  863.     menu->EnableMenuItem( IDM_NEWENTRY,         MF_ENABLED );
  864.     menu->EnableMenuItem( IDM_PREPARERECIPS,    MF_ENABLED );
  865.  
  866.     return;
  867.  
  868. error:
  869.     OnLogoff();
  870.     menu->EnableMenuItem( IDM_LOGON,            MF_ENABLED );
  871.     menu->EnableMenuItem( IDM_LOGOFF,           MF_GRAYED );
  872. }
  873.  
  874. /*
  875.  -    CMainWindow::
  876.  -    OnLogoff
  877.  *
  878.  *    Purpose:
  879.  *      Logs off the Mail subsystem.  De-enables the menu if success.
  880.  *
  881.  */
  882.  
  883. void CMainWindow::OnLogoff()
  884. {
  885.     CMenu* menu = GetMenu();
  886.     HRESULT hResult = NULL;
  887.  
  888.     if (ulModlessABHwnd)
  889.         ::DestroyWindow((HWND)ulModlessABHwnd);
  890.  
  891.     if(lpAdrBook)
  892.     {
  893.         lpAdrBook->Release();
  894.         lpAdrBook = NULL;
  895.  
  896.         menu->EnableMenuItem( IDM_ROOTCONTAINER,    MF_GRAYED );
  897.         menu->EnableMenuItem( IDM_ADDRESS0,         MF_GRAYED );
  898.         menu->EnableMenuItem( IDM_ADDRESS1,         MF_GRAYED );
  899.         menu->EnableMenuItem( IDM_ADDRESS2,         MF_GRAYED );
  900.         menu->EnableMenuItem( IDM_ADDRESS3,         MF_GRAYED );
  901.         menu->EnableMenuItem( IDM_RESOLVENAME,      MF_GRAYED );
  902.         menu->EnableMenuItem( IDM_CREATEONEOFF,     MF_GRAYED );
  903.         menu->EnableMenuItem( IDM_NEWENTRY,         MF_GRAYED );
  904.         menu->EnableMenuItem( IDM_PREPARERECIPS,    MF_GRAYED );
  905.     }
  906.  
  907.     if( lpSession )
  908.     {
  909.         if( FAILED(hResult = lpSession->Logoff( (ULONG)(void *)m_hWnd,
  910.                                 MAPI_LOGOFF_UI,
  911.                                 0 )))
  912.         {
  913.             DisplayError( lpSession, hResult, "Logoff" );
  914.             goto error;
  915.         }
  916.  
  917.         lpSession->Release();
  918.         lpSession = NULL;
  919.  
  920.         menu->EnableMenuItem( IDM_LOGON,            MF_ENABLED );
  921.         menu->EnableMenuItem( IDM_LOGOFF,           MF_GRAYED );
  922.     }
  923.  
  924. error:    {}
  925.  
  926. }
  927.  
  928.  
  929. /*
  930.  -  CMainWindow::
  931.  -  OnRootContainer
  932.  *
  933.  *  Purpose:
  934.  *      Opens up a dialog with a standard listbox displaying
  935.  *      the hierarchy table of the Address Book.  Any AB providers
  936.  *      that are registered and in the path should be loaded, and
  937.  *      available for display.
  938.  *
  939.  */
  940.  
  941. void CMainWindow::OnRootContainer()
  942. {
  943.     SCODE sc = S_OK;
  944.  
  945.     sc = ScOpenEntry( 0, NULL, DT_NOT_SPECIFIC, fRoot, fCONVENIENT_DEPTH );
  946. }
  947.  
  948.  
  949. /*
  950.  ** Dismissed
  951.  *
  952.  *  DESCRIPTION:
  953.  *      Called when Browse mode of Address Book is dismissed.
  954.  *      Resets the modless bit giving indication the dialog is gone.
  955.  *
  956.  */
  957.  
  958. void STDMETHODCALLTYPE
  959. Dismissed (ULONG ulUIParam, LPVOID lpvContext)
  960. {
  961.     ulModlessABHwnd = 0;
  962. }
  963.  
  964.  
  965. /*
  966.  -  CMainWindow::
  967.  -  OnAddress0
  968.  *
  969.  *  Purpose:
  970.  *      This opens the 0 well case for viewing the
  971.  *      Address Book using the Mapi Dialogs supplied
  972.  *      with the "Address" Call.
  973.  *
  974.  */
  975.  
  976. void CMainWindow::OnAddress0()
  977. {
  978.     ADRPARM     adrparm;
  979.     ULONG       ulUIParam   = (ULONG)(void *)m_hWnd;
  980.     HRESULT     hResult = NULL;
  981.     ULONG       ulFlags = 0;
  982.  
  983.     if (ulModlessABHwnd)
  984.         return;
  985.  
  986.     ulModlessABHwnd = ulUIParam;
  987.  
  988.     if(fUNICODE)
  989.         ulFlags = ulFlags | MAPI_UNICODE;
  990.         
  991.     ulFlags = ulFlags | DIALOG_SDI;     
  992.  
  993.     adrparm.cbABContEntryID     = 0;
  994.     adrparm.lpABContEntryID     = NULL;
  995.     adrparm.ulFlags             = ulFlags;
  996.     adrparm.lpReserved          = NULL;
  997.     adrparm.ulHelpContext       = 0;
  998.     adrparm.lpszHelpFileName    = NULL;
  999.     adrparm.lpfnABSDI           = NULL;
  1000.     adrparm.lpfnDismiss         = Dismissed;
  1001.     adrparm.lpvDismissContext   = NULL;
  1002.     adrparm.lpszCaption         = "MAPI ITP tests Address 0";
  1003.     adrparm.lpszNewEntryTitle   = "For this test dialog";
  1004.     adrparm.lpszDestWellsTitle  = "0 wells here";
  1005.     adrparm.cDestFields         = 0;
  1006.     adrparm.nDestFieldFocus     = 0;
  1007.     adrparm.lppszDestTitles     = NULL;
  1008.     adrparm.lpulDestComps       = NULL;
  1009.     adrparm.lpContRestriction   = NULL;
  1010.     adrparm.lpHierRestriction   = NULL;
  1011.  
  1012.     if( FAILED(hResult = lpAdrBook->Address(&ulModlessABHwnd,
  1013.                                     &adrparm,
  1014.                                     NULL )))
  1015.     {
  1016.         DisplayError( lpAdrBook, hResult, "Address" );
  1017.     }
  1018. }
  1019.  
  1020.  
  1021. /*
  1022.  -  CMainWindow::
  1023.  -  OnAddress1
  1024.  *
  1025.  *  Purpose:
  1026.  *      This calls "Address", requesting the single well
  1027.  *      case for display
  1028.  *
  1029.  */
  1030.  
  1031. void CMainWindow::OnAddress1()
  1032. {
  1033.     LPSTR    rglpszDestTitles[1];
  1034.     ULONG       rgulDestComps[1];
  1035.     ADRPARM     adrparm;
  1036.     LPADRLIST   lpadrlist   = NULL;
  1037.     ULONG       ulUIParam   = (ULONG)(void *)m_hWnd;
  1038.     HRESULT     hResult     = NULL;
  1039.     ULONG       ulFlags     = 0;
  1040.  
  1041.     if(fUNICODE)
  1042.         ulFlags = ulFlags | MAPI_UNICODE;
  1043.         
  1044.     ulFlags = ulFlags | DIALOG_MODAL;     
  1045.  
  1046.     rglpszDestTitles[0]         = "To";
  1047.     rgulDestComps[0]            = MAPI_TO;
  1048.  
  1049.     adrparm.cbABContEntryID     = 0;
  1050.     adrparm.lpABContEntryID     = NULL;
  1051.     adrparm.ulFlags             = ulFlags;
  1052.     adrparm.lpReserved          = NULL;
  1053.     adrparm.ulHelpContext       = 0;
  1054.     adrparm.lpszHelpFileName    = NULL;
  1055.     adrparm.lpfnABSDI           = NULL;
  1056.     adrparm.lpfnDismiss         = NULL;
  1057.     adrparm.lpvDismissContext   = NULL;
  1058.     adrparm.lpszCaption         = "MAPI ITP tests Address 1";
  1059.     adrparm.lpszNewEntryTitle   = "For this test dialog";
  1060.     adrparm.lpszDestWellsTitle  = "1 well here";
  1061.     adrparm.cDestFields         = 1;
  1062.     adrparm.nDestFieldFocus     = 0;
  1063.     adrparm.lppszDestTitles     = rglpszDestTitles;
  1064.     adrparm.lpulDestComps       = rgulDestComps;
  1065.     adrparm.lpContRestriction   = NULL;
  1066.     adrparm.lpHierRestriction   = NULL;
  1067.  
  1068.     if( FAILED(hResult = lpAdrBook->Address( &ulUIParam,
  1069.                             &adrparm,
  1070.                             &lpadrlist )))
  1071.     {
  1072.         DisplayError( lpAdrBook, hResult, "Address" );
  1073.         _FreeRowSet((LPSRowSet) lpadrlist);
  1074.         return;
  1075.     }
  1076.  
  1077.     CAdrListDlg dlgAdrList(lpadrlist);
  1078.     _FreeRowSet((LPSRowSet)lpadrlist);
  1079. }
  1080.  
  1081.  
  1082. /*
  1083.  -  CMainWindow::
  1084.  -  OnAddress2
  1085.  *
  1086.  *  Purpose:
  1087.  *      This calls "Address", requesting the 2 well
  1088.  *      case for display
  1089.  *
  1090.  */
  1091.  
  1092. void CMainWindow::OnAddress2()
  1093. {
  1094.     LPSTR    rglpszDestTitles[2];
  1095.     ULONG       rgulDestComps[2];
  1096.     ADRPARM     adrparm;
  1097.     LPADRLIST   lpadrlist   = NULL;
  1098.     ULONG       ulUIParam   = (ULONG)(void *)m_hWnd;
  1099.     HRESULT     hResult     = NULL;
  1100.     ULONG       ulFlags     = 0;
  1101.  
  1102.     if(fUNICODE)
  1103.         ulFlags = ulFlags | MAPI_UNICODE;
  1104.         
  1105.     ulFlags = ulFlags | DIALOG_MODAL;     
  1106.  
  1107.     rglpszDestTitles[0] = "To";
  1108.     rglpszDestTitles[1] = "Cc";
  1109.  
  1110.     rgulDestComps[0]    = MAPI_TO;
  1111.     rgulDestComps[1]    = MAPI_CC;
  1112.  
  1113.     adrparm.cbABContEntryID     = 0;
  1114.     adrparm.lpABContEntryID     = NULL;
  1115.     adrparm.ulFlags             = ulFlags;
  1116.     adrparm.lpReserved          = NULL;
  1117.     adrparm.ulHelpContext       = 0;
  1118.     adrparm.lpszHelpFileName    = NULL;
  1119.     adrparm.lpfnABSDI           = NULL;
  1120.     adrparm.lpfnDismiss         = NULL;
  1121.     adrparm.lpvDismissContext   = NULL;
  1122.     adrparm.lpszCaption         = "MAPI ITP tests Address 2";
  1123.     adrparm.lpszNewEntryTitle   = "For this test dialog";
  1124.     adrparm.lpszDestWellsTitle  = "2 wells here";
  1125.     adrparm.cDestFields         = 2;
  1126.     adrparm.nDestFieldFocus     = 0;
  1127.     adrparm.lppszDestTitles     = rglpszDestTitles;
  1128.     adrparm.lpulDestComps       = rgulDestComps;
  1129.     adrparm.lpContRestriction   = NULL;
  1130.     adrparm.lpHierRestriction   = NULL;
  1131.  
  1132.     if( FAILED(hResult = lpAdrBook->Address( &ulUIParam,
  1133.                                                 &adrparm,
  1134.                                                 &lpadrlist )))
  1135.     {
  1136.         DisplayError( lpAdrBook, hResult, "Address" );
  1137.         _FreeRowSet((LPSRowSet) lpadrlist);
  1138.         return;
  1139.     }
  1140.  
  1141.     CAdrListDlg dlgAdrList(lpadrlist);
  1142.     _FreeRowSet((LPSRowSet)lpadrlist);
  1143. }
  1144.  
  1145.  
  1146. /*
  1147.  -  CMainWindow::
  1148.  -  OnAddress3
  1149.  *
  1150.  *  Purpose:
  1151.  *      This calls "Address", requesting the 3 well
  1152.  *      case for display
  1153.  *
  1154.  */
  1155.  
  1156. void CMainWindow::OnAddress3()
  1157. {
  1158.     LPSTR    rglpszDestTitles[3];
  1159.     ULONG       rgulDestComps[3];
  1160.     ADRPARM     adrparm;
  1161.     LPADRLIST   lpadrlist   = NULL;
  1162.     ULONG       ulUIParam   = (ULONG)(void *)m_hWnd;
  1163.     HRESULT     hResult     = NULL;
  1164.     ULONG       ulFlags     = 0;
  1165.  
  1166.     if(fUNICODE)
  1167.         ulFlags = ulFlags | MAPI_UNICODE;
  1168.         
  1169.     ulFlags = ulFlags | DIALOG_MODAL;     
  1170.  
  1171.     rglpszDestTitles[0] = "To";
  1172.     rglpszDestTitles[1] = "Cc";
  1173.     rglpszDestTitles[2] = "Bcc";
  1174.  
  1175.     rgulDestComps[0]    = MAPI_TO;
  1176.     rgulDestComps[1]    = MAPI_CC;
  1177.     rgulDestComps[2]    = MAPI_BCC;
  1178.  
  1179.     adrparm.cbABContEntryID     = 0;
  1180.     adrparm.lpABContEntryID     = NULL;
  1181.     adrparm.ulFlags             = ulFlags;
  1182.     adrparm.lpReserved          = NULL;
  1183.     adrparm.ulHelpContext       = 0;
  1184.     adrparm.lpszHelpFileName    = NULL;
  1185.     adrparm.lpfnABSDI           = NULL;
  1186.     adrparm.lpfnDismiss         = NULL;
  1187.     adrparm.lpvDismissContext   = NULL;
  1188.     adrparm.lpszCaption         = "MAPI ITP tests Address 3";
  1189.     adrparm.lpszNewEntryTitle   = "For this test dialog";
  1190.     adrparm.lpszDestWellsTitle  = "3 wells here";
  1191.     adrparm.cDestFields         = 3;
  1192.     adrparm.nDestFieldFocus     = 0;
  1193.     adrparm.lppszDestTitles     = rglpszDestTitles;
  1194.     adrparm.lpulDestComps       = rgulDestComps;
  1195.     adrparm.lpContRestriction   = NULL;
  1196.     adrparm.lpHierRestriction   = NULL;
  1197.  
  1198.     if( FAILED(hResult = lpAdrBook->Address( &ulUIParam,
  1199.                                                 &adrparm,
  1200.                                                 &lpadrlist )))
  1201.     {
  1202.         DisplayError( lpAdrBook, hResult, "Address" );
  1203.         _FreeRowSet((LPSRowSet) lpadrlist);
  1204.         return;
  1205.     }
  1206.  
  1207.     CAdrListDlg dlgAdrList(lpadrlist);
  1208.     _FreeRowSet((LPSRowSet)lpadrlist);
  1209. }
  1210.  
  1211.  
  1212.  
  1213. /*
  1214.  -  CMainWindow::
  1215.  -  OnResolveName
  1216.  *
  1217.  *  Purpose:
  1218.  *      This displays a dialog requesting a szPartialName that can be used
  1219.  *      to call "ResolveName".  The Address List returned will be displayed
  1220.  *      in a standard listbox format.
  1221.  *
  1222.  */
  1223.  
  1224. void CMainWindow::OnResolveName()
  1225. {
  1226.     CResolveNameDlg dlgResolveName;
  1227. }
  1228.  
  1229.  
  1230. /*
  1231.  -  CMainWindow::
  1232.  -  OnCreateOneOff
  1233.  *
  1234.  *  Purpose:
  1235.  *      This displays a dialog requesting a 3 strings that can be used
  1236.  *      to call "CreateOneOff".  The OneOff returned will be displayed
  1237.  *      as an entry, then freed.
  1238.  *
  1239.  */
  1240.  
  1241. void CMainWindow::OnCreateOneOff()
  1242. {
  1243.     COneOffDlg dlgOneOff;
  1244. }
  1245.  
  1246.  
  1247. /*
  1248.  -  CMainWindow::
  1249.  -  OnNewEntry
  1250.  *
  1251.  *  Purpose:
  1252.  *      Calls Session object's NewEntry method.
  1253.  *
  1254.  */
  1255.  
  1256. void CMainWindow::OnNewEntry()
  1257. {
  1258.     ULONG     ulUIParam = (ULONG)(void *)m_hWnd;
  1259.     ULONG     ulFlags = 0;
  1260.     ULONG     cbEIDContainer = 0;
  1261.     LPENTRYID lpEIDContainer = NULL;
  1262.     ULONG     cbEIDNewEntryTpl = 0;
  1263.     LPENTRYID lpEIDNewEntryTpl = NULL;
  1264.     ULONG     cbEIDNewEntry = 0;
  1265.     LPENTRYID EIDNewEntry = NULL;
  1266.  
  1267.     lpAdrBook->NewEntry( ulUIParam,
  1268.                          ulFlags,
  1269.                          cbEIDContainer,
  1270.                          lpEIDContainer,
  1271.                          cbEIDNewEntryTpl,
  1272.                          lpEIDNewEntryTpl,
  1273.                          &cbEIDNewEntry,
  1274.                          &EIDNewEntry );
  1275.     
  1276.     if(EIDNewEntry)
  1277.     {
  1278.         ScOpenEntry( cbEIDNewEntry, EIDNewEntry, DT_NOT_SPECIFIC, fContents, FALSE);
  1279.         MAPIFreeBuffer( EIDNewEntry );
  1280.     }
  1281. }
  1282.  
  1283.  
  1284. /*
  1285.  *  CMAPIPropDlg Methods.
  1286.  */
  1287.  
  1288. /*
  1289.  -  CMAPIPropDlg::
  1290.  -  OnGetPropsThis
  1291.  -
  1292.  *  Purpose:
  1293.  *      Will open a ListBox viewer with a List of Properties
  1294.  *      for "this" Container.  Properties are found by calling
  1295.  *      GetProps on the Container object.
  1296.  *
  1297.  */
  1298.  
  1299. void CMAPIPropDlg::OnGetPropsThis()
  1300. {
  1301.     HRESULT         hResult         = NULL;
  1302.     ULONG           cValues         = 0;
  1303.     LPSPropValue    lpsPropValue    = NULL;
  1304.     LPSPropTagArray lpPropTagArray  = NULL;
  1305.     ULONG           i;
  1306.     ULONG           ulFlags         = 0;
  1307.     
  1308.     if(fUNICODE)
  1309.         ulFlags = ulFlags | MAPI_UNICODE;
  1310.  
  1311.     if ( fUseUNICODE )
  1312.     {
  1313.         if( FAILED(hResult = m_lpEntry->GetPropList( ulFlags, &lpPropTagArray )))
  1314.         {
  1315.             DisplayError( m_lpEntry, hResult, "GetPropList" );
  1316.             return;
  1317.         }
  1318.  
  1319.             for ( i = 0; i < lpPropTagArray->cValues; i++ )
  1320.             {
  1321.                 if ( PROP_TYPE( lpPropTagArray->aulPropTag[i] ) == PT_STRING8 )
  1322.                 {
  1323.                     lpPropTagArray->aulPropTag[i] =
  1324.                     ( lpPropTagArray->aulPropTag[i] & 0xFFFF0000 ) |
  1325.                     PT_UNICODE;
  1326.                 }
  1327.         }
  1328.     }
  1329.  
  1330.     if( FAILED(hResult = m_lpEntry->GetProps(lpPropTagArray, ulFlags,
  1331.                                                 &cValues,
  1332.                                                 &lpsPropValue )))
  1333.     {
  1334.         DisplayError( m_lpEntry, hResult, "GetProps" );
  1335.         MAPIFreeBuffer( lpPropTagArray );
  1336.         return;
  1337.     }
  1338.  
  1339.     if ( cValues == 0 || lpsPropValue == NULL )
  1340.     {
  1341.         MessageBox( "Couldn't get any properties on object.", "Error!", MB_OK );
  1342.         return;
  1343.     }
  1344.  
  1345.     CPropertiesDlg * pdlgProperties = new CPropertiesDlg( cValues,
  1346.                                                 lpsPropValue,
  1347.                                                 "GetProps",
  1348.                                                 fmAProperty );
  1349.  
  1350.     MAPIFreeBuffer( lpsPropValue );
  1351.     MAPIFreeBuffer( lpPropTagArray );
  1352.     }
  1353.  
  1354.  
  1355. /*
  1356.  -  CMAPIPropDlg::
  1357.  -  OnGetPropListThis
  1358.  -
  1359.  *  Purpose:
  1360.  *      Will open a ListBox viewer with a List of Properties
  1361.  *      for "this" Container.  Properties are found by calling
  1362.  *      GetPropList on the Container object.
  1363.  *
  1364.  */
  1365.  
  1366. void CMAPIPropDlg::OnGetPropListThis()
  1367. {
  1368.     HRESULT         hResult         = NULL;
  1369.     ULONG           cValues         = 0;
  1370.     LPSPropTagArray lpPropTagArray  = NULL;
  1371.     LPSPropValue    lpProps         = NULL;
  1372.     ULONG           ulFlags         = 0;
  1373.  
  1374.     if(fUNICODE)
  1375.         ulFlags = ulFlags | MAPI_UNICODE;
  1376.  
  1377.     if( FAILED(hResult = m_lpEntry->GetPropList( ulFlags, &lpPropTagArray )))
  1378.     {
  1379.         DisplayError( m_lpEntry, hResult, "GetPropList" );
  1380.         return;
  1381.     }
  1382.  
  1383.     if ( lpPropTagArray->cValues == 0 )
  1384.     {
  1385.         MessageBox( "Couldn't get a property list on object.", "Error!", MB_OK );
  1386.         return;
  1387.     }
  1388.  
  1389.     MAPIAllocateBuffer( sizeof(SPropValue) * lpPropTagArray->cValues, (LPVOID *) &lpProps );
  1390.     memset( (void *) lpProps, 0, (size_t)(sizeof(SPropValue) * lpPropTagArray->cValues) );
  1391.  
  1392.     for(cValues = 0; cValues < lpPropTagArray->cValues; cValues++)
  1393.     {
  1394.         lpProps[cValues].ulPropTag = lpPropTagArray->aulPropTag[cValues];
  1395.     }
  1396.  
  1397.     CPropertiesDlg * pdlgProperties = new CPropertiesDlg( lpPropTagArray->cValues,
  1398.                                                             lpProps,
  1399.                                                             "GetPropList",
  1400.                                                             fmProperty | fmPropType );
  1401.  
  1402.     MAPIFreeBuffer( lpProps );
  1403.     MAPIFreeBuffer( lpPropTagArray );
  1404.     }
  1405.  
  1406. /*
  1407.  -  CMAPIPropDlg::
  1408.  -  OnPropertyDLL
  1409.  -
  1410.  *  Purpose:
  1411.  *      Opens a dialog to manipulate the current object.
  1412.  *      The dialog is contained in a test DLL and can be
  1413.  *      called on any Table.
  1414.  *
  1415.  */
  1416.  
  1417. void CMAPIPropDlg::OnPropertyDLL()
  1418. {
  1419.     PROPVUViewMapiProp( "LPMAPIPROP",
  1420.                         (LPMAPIPROP FAR *)&m_lpEntry,
  1421.                         lpTargetEntryID ? lpTargetEntryID : (LPVOID) lpAdrBook,
  1422.                         (HWND)this->m_hWnd );
  1423. }
  1424.  
  1425. /*
  1426.  -  CMAPIPropDlg::
  1427.  -  OnAddToPAB
  1428.  -
  1429.  *  Purpose:
  1430.  *      Adds the Entry to the PAB using the CreateEntry method.
  1431.  *
  1432.  */
  1433.  
  1434. void CMAPIPropDlg::OnAddToPAB()
  1435. {
  1436.     HRESULT     hResult   = NULL;
  1437.     ULONG       cbEntryID = 0;
  1438.     LPENTRYID   lpEntryID = NULL;
  1439.     ULONG       ulObjType = 0;
  1440.     LPMAPIPROP  lpEntry   = NULL;
  1441.     LPMAPIPROP  lpMAPIPropEntry = NULL;
  1442.     ULONG       ulFlags   = 0;
  1443.     ULONG       ulTarget  = 0;
  1444.     ULONG           cValues         = 0;
  1445.     LPSPropValue    lpsPropValue    = NULL;
  1446.     ULONG           ulData[2];
  1447.     LPSPropTagArray lpPTArray   = (LPSPropTagArray) &ulData;
  1448.  
  1449.     //Make sure we have an entry we want to add
  1450.     if(!m_lpEntry)
  1451.         return;
  1452.  
  1453.     if ( lpTargetEntryID )
  1454.     {
  1455.         ulTarget = MessageBox(
  1456.                            "Add to the target instead of the PAB?",
  1457.                                "Question", MB_YESNO | MB_ICONQUESTION );
  1458.         switch ( ulTarget )
  1459.         {
  1460.             case IDYES: // A yes responce to question
  1461.                 cbEntryID = cbTargetEntryID;
  1462.                 lpEntryID = lpTargetEntryID;
  1463.                 break;
  1464.  
  1465.             case IDNO: // A no responce to question
  1466.                 //Find the PAB
  1467.                 if( FAILED(hResult = lpAdrBook->GetPAB( &cbEntryID,
  1468.                                                         &lpEntryID )))
  1469.                 {
  1470.                     DisplayError( lpAdrBook, hResult, "GetPAB" );
  1471.                     goto err;
  1472.                 }
  1473.                 break;
  1474.  
  1475.             default:
  1476.                 return;
  1477.         }
  1478.     }
  1479.     else
  1480.     {
  1481.         //Find the PAB
  1482.         if( FAILED(hResult = lpAdrBook->GetPAB( &cbEntryID,
  1483.                                                 &lpEntryID )))
  1484.         {
  1485.             DisplayError( lpAdrBook, hResult, "GetPAB" );
  1486.             goto err;
  1487.         }
  1488.     }
  1489.  
  1490.     if(fOpenEntry)
  1491.         ulFlags = MAPI_MODIFY;
  1492.  
  1493.     if( FAILED(hResult = lpAdrBook->OpenEntry( cbEntryID,
  1494.                                                lpEntryID,
  1495.                                                NULL,
  1496.                                                ulFlags,
  1497.                                                &ulObjType,
  1498.                                                (LPUNKNOWN*)&lpEntry )))
  1499.  
  1500.     {
  1501.         DisplayError( lpAdrBook, hResult, "OpenEntry" );
  1502.         goto err;
  1503.     }
  1504.  
  1505.     //Get the EntryID of the object we want to add
  1506.     //Create a PropTagArray with properties to request
  1507.     lpPTArray->cValues = 1;
  1508.     lpPTArray->aulPropTag[0] = PR_ENTRYID;
  1509.  
  1510.     if( FAILED(hResult = m_lpEntry->GetProps( lpPTArray, 0,
  1511.                                               &cValues,
  1512.                                               &lpsPropValue )))
  1513.     {
  1514.         DisplayError( m_lpEntry, hResult, "GetProps" );
  1515.         goto err;
  1516.     }
  1517.  
  1518.     if( FAILED( hResult =
  1519.            ((LPABCONT)lpEntry)->CreateEntry(
  1520.                                 lpsPropValue[0].Value.bin.cb,
  1521.                                 (LPENTRYID)lpsPropValue[0].Value.bin.lpb,
  1522.                                 CREATE_CHECK_DUP_STRICT,
  1523.                                 &lpMAPIPropEntry )))
  1524.                                 {
  1525.                                     DisplayError( lpEntry, hResult, "CreateEntry" );
  1526.                                     goto err;
  1527.                                 }
  1528.  
  1529.     if( FAILED( hResult = lpMAPIPropEntry->SaveChanges( 0 )))
  1530.     {
  1531.         DisplayError( lpEntry, hResult, "SaveChanges" );
  1532.         goto err;
  1533.     }
  1534.  
  1535. err:
  1536.     MAPIFreeBuffer( lpEntryID );
  1537.  
  1538.     if( lpEntry )
  1539.         lpEntry->Release();
  1540.  
  1541.     MAPIFreeBuffer( lpsPropValue );
  1542.  
  1543.     if( lpMAPIPropEntry )
  1544.         lpMAPIPropEntry->Release();
  1545. }
  1546.  
  1547. /*
  1548.  -  CMAPIPropDlg::
  1549.  -  OnDetails
  1550.  -
  1551.  *  Purpose:
  1552.  *      Calls the AB specific call "Details" on the current object.
  1553.  *      A details dialog box will be displayed.  If the entry is in
  1554.  *      a writable address-book container, the user may be allowed
  1555.  *      to modify the entry.  This is provider specific.
  1556.  *
  1557.  */
  1558.  
  1559. void CMAPIPropDlg::OnDetails()
  1560. {
  1561.     HRESULT         hResult         = NULL;
  1562.     ULONG           cValues         = 0;
  1563.     LPSPropValue    lpsPropValue    = NULL;
  1564.  
  1565.     ULONG           cProps          = 0;
  1566.     ULONG           ulUIParam       = (ULONG)(void *)m_hWnd;
  1567.  
  1568.     if(!m_lpEntry)
  1569.         return;
  1570.  
  1571.     if( FAILED(hResult = m_lpEntry->GetProps(NULL, 0,
  1572.                                     &cValues,
  1573.                                     &lpsPropValue )))
  1574.     {
  1575.         DisplayError( m_lpEntry, hResult, "GetProps" );
  1576.         return;
  1577.     }
  1578.  
  1579.     if ( cValues == 0 || lpsPropValue == NULL )
  1580.     {
  1581.         MessageBox( "Couldn't get any properties on object.", "Error!", MB_OK );
  1582.         return;
  1583.     }
  1584.  
  1585.     for( cProps=0; cProps < cValues; cProps++)
  1586.         if( lpsPropValue[cProps].ulPropTag == PR_ENTRYID )
  1587.         break;
  1588.  
  1589.     if( FAILED(hResult = lpAdrBook->Details(
  1590.                                     &ulUIParam,
  1591.                                     NULL,
  1592.                                     NULL,
  1593.                                     lpsPropValue[cProps].Value.bin.cb,
  1594.                                     (LPENTRYID)lpsPropValue[cProps].Value.bin.lpb,
  1595.                                     NULL,
  1596.                                     NULL,
  1597.                                     NULL,
  1598.                                     DIALOG_MODAL )))
  1599.     {
  1600.         DisplayError( lpAdrBook, hResult, "Details" );
  1601.     }
  1602.  
  1603.     MAPIFreeBuffer( lpsPropValue );
  1604. }
  1605.  
  1606.  
  1607.  
  1608. /*
  1609.  -  CMAPIPropDlg::
  1610.  -  OnGetIDsFromNames
  1611.  -
  1612.  *  Purpose:
  1613.  *      Calls GetIDsFromNames() requesting all IDs.
  1614.  *
  1615.  */
  1616.  
  1617. void CMAPIPropDlg::OnGetIDsFromNames()
  1618. {
  1619.     HRESULT         hResult         = NULL;
  1620.     ULONG           cValues         = 0;
  1621.     LPSPropTagArray lpPropTagArray  = NULL;
  1622.     LPSPropValue    lpPropValue     = NULL;
  1623.     
  1624.     if( FAILED(hResult = m_lpEntry->GetIDsFromNames( 0, NULL, 0, &lpPropTagArray )))
  1625.     {
  1626.         DisplayError( m_lpEntry, hResult, "GetIDsFromNames" );
  1627.         return;
  1628.     }
  1629.  
  1630.     if ( lpPropTagArray->cValues == 0 )
  1631.     {
  1632.        MessageBox( "lpPropTagArray->cValues == 0", "Error!", MB_OK );
  1633.        MAPIFreeBuffer( lpPropTagArray );
  1634.        return;
  1635.     }
  1636.  
  1637.     MAPIAllocateBuffer( sizeof(SPropValue) * lpPropTagArray->cValues, (LPVOID *) &lpPropValue );
  1638.     memset( (void *) lpPropValue, 0, (size_t)(sizeof(SPropValue) * lpPropTagArray->cValues) );
  1639.  
  1640.     for(cValues = 0; cValues < lpPropTagArray->cValues; cValues++)
  1641.     {
  1642.         lpPropValue[cValues].ulPropTag = lpPropTagArray->aulPropTag[cValues];
  1643.     }
  1644.  
  1645.     CPropertiesDlg * pdlgProperties = new CPropertiesDlg( lpPropTagArray->cValues,
  1646.                         lpPropValue,
  1647.                         "GetIDsFromNames",
  1648.                         fmProperty | fmPropType );
  1649.  
  1650.     MAPIFreeBuffer( lpPropValue );
  1651.     MAPIFreeBuffer( lpPropTagArray );
  1652. }
  1653.  
  1654.  
  1655.  
  1656. /*
  1657.  -  CMAPIPropDlg::
  1658.  -  OnGetNamesFromIDs
  1659.  -
  1660.  *  Purpose:
  1661.  *      Calls GetNamesFromIDs() requesting all Names.
  1662.  *
  1663.  */
  1664.  
  1665. void CMAPIPropDlg::OnGetNamesFromIDs()
  1666. {
  1667.     HRESULT             hResult         = NULL;
  1668.     ULONG               cPropNames      = 0;
  1669.     LPMAPINAMEID  FAR * lppPropNames    = NULL;
  1670.     LPGUID              lpPropSetGuid   = NULL;
  1671.     LPSPropTagArray     lpPropTags      = NULL;
  1672.  
  1673.     /* 
  1674.      * CreateMAPIGuid( lpPropSetGuid );
  1675.      -      Set the above to request PS_MAPI
  1676.      */
  1677.  
  1678.     if( FAILED(hResult = m_lpEntry->GetNamesFromIDs( &lpPropTags,
  1679.                                                      lpPropSetGuid,
  1680.                                                      0,
  1681.                                                      &cPropNames,
  1682.                                                      &lppPropNames )))
  1683.     {
  1684.         DisplayError( m_lpEntry, hResult, "GetNamesFromIDs" );
  1685.         return;
  1686.     }
  1687.  
  1688.     if ( cPropNames == 0 )
  1689.     {
  1690.        MessageBox( "cPropNames == 0", "Error!", MB_OK );
  1691.        MAPIFreeBuffer( lppPropNames );
  1692.        return;
  1693.     }
  1694.  
  1695.     CNamedIDsDlg * pdlgNamedIDs = new CNamedIDsDlg( cPropNames,
  1696.                                                     lppPropNames,
  1697.                                                     "GetNamesFromIDs" );
  1698.     MAPIFreeBuffer( lpPropTags );
  1699.     MAPIFreeBuffer( lppPropNames );
  1700.  
  1701. }
  1702.  
  1703.  
  1704.  
  1705. /*
  1706.  -  CMAPIPropDlg::
  1707.  -  OnDetailsTbl
  1708.  -
  1709.  *  Purpose:
  1710.  *      Request the PR_DETAILS_TABLE from the object being viewed.
  1711.  *      This will return a table with display type information.
  1712.  *
  1713.  */
  1714.  
  1715. void CMAPIPropDlg::OnDetailsTbl()
  1716. {
  1717.     HRESULT         hResult         = NULL;
  1718.     LPMAPITABLE     lpTable         = NULL;
  1719.  
  1720.     if(FAILED(hResult = m_lpEntry->OpenProperty( PR_DETAILS_TABLE,
  1721.                                                  (LPIID) &IID_IMAPITable,
  1722.                                                  0,
  1723.                                                  0,
  1724.                                                  (LPUNKNOWN *)&lpTable)))
  1725.     {
  1726.         DisplayError( m_lpEntry, hResult, "OpenProperty" );
  1727.         return;
  1728.     }
  1729.     
  1730.     if(hlibTBLVU)
  1731.         TBLVUViewMapiTable( (LPMAPITABLE FAR *)&lpTable, m_hWnd );
  1732.     else
  1733.         AfxMessageBox( "Table Viewer not available", MB_ICONEXCLAMATION | MB_OK, 0 );
  1734.  
  1735.     if(lpTable)
  1736.         lpTable->Release();
  1737. }
  1738.  
  1739.  
  1740. /*
  1741.  -  CMAPIPropDlg::
  1742.  -  ~CMAPIPropDlg
  1743.  -
  1744.  *  Purpose:
  1745.  *      Destructor for class CMAPIPropDlg.  Will release
  1746.  *      the object being viewed.
  1747.  *
  1748.  */
  1749.  
  1750. CMAPIPropDlg::~CMAPIPropDlg()
  1751. {
  1752.     if(m_lpEntry)
  1753.     {
  1754.         m_lpEntry->Release();
  1755.         m_lpEntry = NULL;
  1756.     }
  1757. }
  1758.  
  1759.  
  1760.  
  1761. /*
  1762.  *  CMAPIContainerDlg Methods.
  1763.  */
  1764.  
  1765. /*
  1766.  -  CMAPIContainerDlg::
  1767.  -  OnInitDialog
  1768.  -
  1769.  *  Purpose:
  1770.  *      Loads the ListBox with rows from the MAPITable prior to
  1771.  *      displaying the dialog.
  1772.  *
  1773.  */
  1774.  
  1775. BOOL CMAPIContainerDlg::OnInitDialog()
  1776. {
  1777.     HRESULT         hResult           = NULL;
  1778.     CWnd *          pBTable           = NULL;
  1779.     CWnd *          pBDT              = NULL;
  1780.     CWnd *          pBOOT             = NULL;
  1781.     CWnd *          pBProp            = NULL;
  1782.     CWnd *          pBPerf            = NULL;
  1783.     CWnd *          pBTestThis        = NULL;
  1784.     CWnd *          pBTestSel         = NULL;
  1785.     CWnd *          pBSetAsTargetThis = NULL;
  1786.     CWnd *          pBSetAsTargetSel  = NULL;
  1787.     int             nQueryUser        = 0;
  1788.     CString         szBuffer;
  1789.     BOOL            fHierarchyTable   = FALSE;
  1790.     ULONG           ulFlags           = 0;
  1791.  
  1792.     if(!m_lpEntry)
  1793.         return FALSE;
  1794.  
  1795.     //Disable Tablevu button if DLL is not present.
  1796.     if(!hlibTBLVU)
  1797.     {
  1798.         pBTable = GetDlgItem(IDC_TABLEDLL);
  1799.         pBTable->EnableWindow( FALSE );
  1800.     }
  1801.  
  1802.     //Disable Display Table button if DLL is not present.
  1803.     if(!hlibTBLVU)
  1804.     {
  1805.         pBDT = GetDlgItem(IDC_PR_DETAILS_TABLE);
  1806.         pBDT->EnableWindow( FALSE );
  1807.     }
  1808.  
  1809.     //Disable One-Off Table button if DLL is not present.
  1810.     if(!hlibTBLVU)
  1811.     {
  1812.         pBOOT = GetDlgItem(IDC_PR_CREATE_TEMPLATES);
  1813.         pBOOT->EnableWindow( FALSE );
  1814.     }
  1815.  
  1816.     //Disable Propvu button if DLL is not present.
  1817.     if(!hlibPROPVU)
  1818.     {
  1819.         pBProp = GetDlgItem(IDC_PROPERTYDLL);
  1820.         pBProp->EnableWindow( FALSE );
  1821.     }
  1822.  
  1823.     //Disable Performance button if DLL is not present.
  1824.     if(!hlibPERF)
  1825.     {
  1826.         pBPerf = GetDlgItem(IDC_PERFORMANCE);
  1827.         pBPerf->EnableWindow( FALSE );
  1828.     }
  1829.  
  1830.     //Disable Test button if DLL is not present.
  1831.     if(!hlibTEST)
  1832.     {
  1833.         pBTestThis = GetDlgItem(IDC_TESTTHISDLL);
  1834.         pBTestThis->EnableWindow( FALSE );
  1835.         pBTestSel = GetDlgItem(IDC_TESTSELDLL);
  1836.         pBTestSel->EnableWindow( FALSE );
  1837.     }
  1838.  
  1839. //Disable SetAsTarget button if option is disabled.
  1840.     if(!fSetAsTarget)
  1841.     {
  1842.         pBSetAsTargetThis = GetDlgItem(IDC_SETASTARGETTHIS);
  1843.         pBSetAsTargetThis->EnableWindow( FALSE );
  1844.         pBSetAsTargetSel = GetDlgItem(IDC_SETASTARGETSEL);
  1845.         pBSetAsTargetSel->EnableWindow( FALSE );
  1846.     }
  1847.  
  1848. //Check to see if this is flaged as the RootContainer.  If it is then
  1849. //get a HierarchyTable, else get a ContentsTable.
  1850.  
  1851.     if(fQueryForTable)
  1852.     {
  1853.         szBuffer += "Do you want a Hierarchy Table?\r\n\r\n";
  1854.         szBuffer += "YES\tHierarchy Table is requested.\r\n";
  1855.         szBuffer += "NO\tContents Table is requested.\r\n\r\n";
  1856.         szBuffer += "Use Config to turn off/on this request dialog.";
  1857.         
  1858.         nQueryUser = AfxMessageBox( szBuffer, MB_ICONQUESTION | MB_YESNO, 0 );
  1859.  
  1860.         switch(nQueryUser)
  1861.         {
  1862.             case IDYES:
  1863.                 fHierarchyTable = TRUE;
  1864.                 break;
  1865.             case IDNO:
  1866.                 fHierarchyTable = FALSE;
  1867.                 break;
  1868.             default:
  1869.                 break;
  1870.         }
  1871.     }
  1872.     else
  1873.     {
  1874.         if(m_ulTableTypeFrom == fRoot)
  1875.             fHierarchyTable = TRUE;    
  1876.     }
  1877.  
  1878.     if(fUNICODE)
  1879.         ulFlags = ulFlags | MAPI_UNICODE;
  1880.  
  1881.     if(m_fCONVENIENT_DEPTH)
  1882.     {
  1883.         CheckDlgButton(IDC_CONVENIENTDEPTH, 1);
  1884.     }
  1885.  
  1886.     if(fHierarchyTable) 
  1887.     {
  1888.         if(m_fCONVENIENT_DEPTH)
  1889.         {
  1890.             ulFlags = ulFlags | CONVENIENT_DEPTH;
  1891.         }
  1892.     
  1893.         if( FAILED(hResult = ((LPABCONT)m_lpEntry)->GetHierarchyTable(
  1894.                                                     ulFlags,
  1895.                                                     &m_lpMAPITable )))
  1896.         {
  1897.             DisplayError( m_lpEntry, hResult, "GetHierarchyTable" );
  1898.         }
  1899.         else
  1900.         {
  1901.             m_ulCurrentTableType = fHierarchy;
  1902.         }
  1903.     }
  1904.     else
  1905.     {
  1906.         if( FAILED(hResult = ((LPABCONT)m_lpEntry)->GetContentsTable(
  1907.                                                     ulFlags,
  1908.                                                     &m_lpMAPITable )))
  1909.         {
  1910.             DisplayError( m_lpEntry, hResult, "GetContentsTable" );
  1911.         }
  1912.         else
  1913.         {
  1914.             m_ulCurrentTableType = fContents;
  1915.         }
  1916.     }
  1917.  
  1918.     m_lpTblList = new CTblList( IDC_CONTAINERLIST,
  1919.                                 m_lpMAPITable,
  1920.                                 m_ulCurrentTableType );
  1921.  
  1922.     VERIFY(m_lpTblList->SubclassDlgItem(IDC_CONTAINERLIST, this));
  1923.  
  1924.     m_lpTblList->InitListBox();
  1925.  
  1926.  
  1927.     //Change caption for appropriate object type
  1928.     switch ( m_ulObjType )
  1929.     {
  1930.         case MAPI_ABCONT:
  1931.             m_Caption += "Container - ";
  1932.             break;
  1933.         case MAPI_DISTLIST:
  1934.             m_Caption += "Distlist - ";
  1935.             break;
  1936.         default:
  1937.             m_Caption += "Unknown Obj Type - ";    
  1938.     }
  1939.  
  1940.  
  1941.     switch ( m_ulCurrentTableType )
  1942.     {
  1943.         case fRoot:
  1944.             m_Caption += "Root";
  1945.             break;
  1946.         case fHierarchy:
  1947.             m_Caption += "Hierarchy";
  1948.             break;
  1949.         case fContents:
  1950.             m_Caption += "Contents";
  1951.             break;
  1952.         default:
  1953.             m_Caption += "Unknown Table";    
  1954.     }
  1955.  
  1956.     SetWindowText(m_Caption);
  1957.  
  1958.     return TRUE;
  1959. }
  1960.  
  1961.  
  1962. /*
  1963.  -  CMAPIContainerDlg::
  1964.  -  OnOK
  1965.  -
  1966.  *  Purpose:
  1967.  *      Finds the Entry Selected and performs an OpenEntry on it.  If
  1968.  *      the object opened is a Container, then a Table viewer is
  1969.  *      created with the information.
  1970.  *
  1971.  */
  1972.  
  1973. void CMAPIContainerDlg::OnOK()
  1974. {
  1975.     SCODE        sc      = S_OK;
  1976.     LPSPropValue lpProps = NULL;
  1977.     BOOL         fDEPTH  = FALSE;
  1978.  
  1979.     int nIndex = m_lpTblList->GetCurSel();
  1980.     if( nIndex == -1 )
  1981.     {
  1982.         MessageBox("Please Select an Entry");
  1983.         m_lpTblList->SetFocus();
  1984.         return;
  1985.     }
  1986.  
  1987.     fDEPTH = IsDlgButtonChecked( IDC_CONVENIENTDEPTH );
  1988.     
  1989.     lpProps = (LPSPropValue)m_lpTblList->GetItemData(nIndex);
  1990.  
  1991.     sc = ScOpenEntry( lpProps[1].Value.bin.cb,
  1992.     (LPENTRYID)lpProps[1].Value.bin.lpb,
  1993.     lpProps[3].Value.ul,
  1994.     m_ulCurrentTableType,
  1995.     fDEPTH );
  1996.  
  1997. }
  1998.  
  1999.  
  2000. /*
  2001.  -  CMAPIContainerDlg::
  2002.  -  OnCancel
  2003.  -
  2004.  *  Purpose:
  2005.  *      Cancels the Table viewer dialog.
  2006.  *
  2007.  */
  2008.  
  2009. void CMAPIContainerDlg::OnCancel()
  2010. {
  2011.     while(m_lpTblList->DeleteString( 0 )) {}
  2012.     delete m_lpTblList;
  2013.  
  2014.     EndDialog(IDCANCEL);
  2015. }
  2016.  
  2017.  
  2018. /*
  2019.  -  CMAPIContainerDlg::
  2020.  -  OnProperties
  2021.  -
  2022.  *  Purpose:
  2023.  *      Will open a ListBox viewer with a List of Properties
  2024.  *      from the Table for the currently selected entry in
  2025.  *      the Table viewer.
  2026.  *
  2027.  */
  2028.  
  2029. void CMAPIContainerDlg::OnProperties()
  2030. {
  2031.     LPSPropValue    lpProps   = NULL;
  2032.     LPSPropTagArray lpPTArray = NULL;
  2033.  
  2034.     int nIndex = m_lpTblList->GetCurSel();
  2035.     if( nIndex == -1 )
  2036.     {
  2037.         MessageBox("Please Select an Entry");
  2038.         m_lpTblList->SetFocus();
  2039.         return;
  2040.     }
  2041.  
  2042.     lpProps   = (LPSPropValue)m_lpTblList->GetItemData(nIndex);
  2043.  
  2044.     lpPTArray = (LPSPropTagArray)ABH_PropTagArray;
  2045.  
  2046.     CPropertiesDlg * pdlgProperties = new CPropertiesDlg(
  2047.                                         lpPTArray->cValues,
  2048.                                         lpProps,
  2049.                                         "Table Properties, Current Selection",
  2050.                                         fmAProperty );
  2051. }
  2052.  
  2053.  
  2054. /*
  2055.  -  CMAPIContainerDlg::
  2056.  -  OnGetProps
  2057.  -
  2058.  *  Purpose:
  2059.  *      Will open a ListBox viewer with a List of Properties
  2060.  *      for the currently selected entry in the Table viewer.
  2061.  *      This entry will be opened into an object.  GetProps
  2062.  *      is then performed on the object.
  2063.  *
  2064.  */
  2065.  
  2066. void CMAPIContainerDlg::OnGetProps()
  2067. {
  2068.     HRESULT         hResult         = NULL;
  2069.     ULONG           cValues         = 0;
  2070.     ULONG           ulFlags         = 0;
  2071.     ULONG           ulObjType       = 0;
  2072.     LPMAPIPROP      lpEntry         = NULL;
  2073.     LPSPropValue    lpsPropValue    = NULL;
  2074.     LPSPropValue    lpProps         = NULL;
  2075.     LPSPropTagArray lpPropTagArray  = NULL;
  2076.     ULONG           i;
  2077.  
  2078.     int nIndex = m_lpTblList->GetCurSel();
  2079.     if( nIndex == -1 )
  2080.     {
  2081.         MessageBox("Please Select an Entry");
  2082.         m_lpTblList->SetFocus();
  2083.         return;
  2084.     }
  2085.  
  2086.     lpProps   = (LPSPropValue)m_lpTblList->GetItemData(nIndex);
  2087.  
  2088.     if(fOpenEntry)
  2089.         ulFlags = MAPI_MODIFY;
  2090.  
  2091.     if( FAILED(hResult = lpAdrBook->OpenEntry( lpProps[1].Value.bin.cb,
  2092.                                                (LPENTRYID)lpProps[1].Value.bin.lpb,
  2093.                                                NULL,
  2094.                                                ulFlags,
  2095.                                                &ulObjType,
  2096.                                                (LPUNKNOWN*)&lpEntry )))
  2097.     {
  2098.         DisplayError( lpAdrBook, hResult, "OpenEntry" );
  2099.         return;
  2100.     }
  2101.  
  2102.     if(fUNICODE)
  2103.         ulFlags = MAPI_UNICODE;
  2104.     else
  2105.         ulFlags = 0;
  2106.  
  2107.     if ( fUseUNICODE )
  2108.     {
  2109.         if( FAILED(hResult = lpEntry->GetPropList( ulFlags, &lpPropTagArray )))
  2110.         {
  2111.             DisplayError( lpEntry, hResult, "GetPropList" );
  2112.             return;
  2113.         }
  2114.         for ( i = 0; i < lpPropTagArray->cValues; i++ )
  2115.         {
  2116.             if ( PROP_TYPE( lpPropTagArray->aulPropTag[i] ) == PT_STRING8 )
  2117.             {
  2118.                 lpPropTagArray->aulPropTag[i] =
  2119.                      ( lpPropTagArray->aulPropTag[i] & 0xFFFF0000 ) |
  2120.                      PT_UNICODE;
  2121.             }
  2122.         }
  2123.     }
  2124.  
  2125.     if( FAILED(hResult = lpEntry->GetProps( lpPropTagArray,
  2126.                                             ulFlags,
  2127.                                             &cValues,
  2128.                                             &lpsPropValue )))
  2129.     {
  2130.         DisplayError( lpEntry, hResult, "GetProps" );
  2131.         lpEntry->Release();
  2132.         return;
  2133.     }
  2134.  
  2135.     if ( cValues == 0 || lpsPropValue == NULL )
  2136.     {
  2137.        MessageBox( "Couldn't get any properties on object.", "Error!", MB_OK );
  2138.        return;
  2139.     }
  2140.  
  2141.     CPropertiesDlg * pdlgProperties = new CPropertiesDlg( cValues,
  2142.                 lpsPropValue,
  2143.                 "GetProps",
  2144.                 fmAProperty );
  2145.  
  2146.     MAPIFreeBuffer( lpsPropValue );
  2147.     lpEntry->Release();
  2148. }
  2149.  
  2150.  
  2151. /*
  2152.  -  CMAPIContainerDlg::
  2153.  -  OnGetPropList
  2154.  -
  2155.  *  Purpose:
  2156.  *      Will open a ListBox viewer with a List of Properties
  2157.  *      for the currently selected entry in the Table viewer.
  2158.  *      This entry will be opened into an object.  GetPropList
  2159.  *      is then performed on the object.
  2160.  *
  2161.  */
  2162.  
  2163. void CMAPIContainerDlg::OnGetPropList()
  2164. {
  2165.     HRESULT         hResult         = NULL;
  2166.     ULONG           cValues         = 0;
  2167.     ULONG           ulFlags         = 0;
  2168.     ULONG           ulObjType       = 0;
  2169.     LPMAPIPROP      lpEntry         = NULL;
  2170.     LPSPropValue    lpsPropValue    = NULL;
  2171.     LPSPropValue    lpProps         = NULL;
  2172.     LPSPropTagArray lpPropTagArray  = NULL;
  2173.  
  2174.     int nIndex = m_lpTblList->GetCurSel();
  2175.     if( nIndex == -1 )
  2176.     {
  2177.         MessageBox("Please Select an Entry");
  2178.         m_lpTblList->SetFocus();
  2179.         return;
  2180.     }
  2181.  
  2182.     lpProps   = (LPSPropValue)m_lpTblList->GetItemData(nIndex);
  2183.  
  2184.     if(fOpenEntry)
  2185.         ulFlags = MAPI_MODIFY;
  2186.  
  2187.     if( FAILED(hResult = lpAdrBook->OpenEntry( lpProps[1].Value.bin.cb,
  2188.                                                (LPENTRYID)lpProps[1].Value.bin.lpb,
  2189.                                                NULL,
  2190.                                                ulFlags,
  2191.                                                &ulObjType,
  2192.                                                (LPUNKNOWN*)&lpEntry )))
  2193.     {
  2194.         DisplayError( lpAdrBook, hResult, "OpenEntry" );
  2195.         return;
  2196.     }
  2197.  
  2198.     if(fUNICODE)
  2199.         ulFlags = MAPI_UNICODE;
  2200.     else
  2201.         ulFlags = 0;
  2202.  
  2203.     if( FAILED(hResult = lpEntry->GetPropList( ulFlags, &lpPropTagArray )))
  2204.     {
  2205.         DisplayError( lpEntry, hResult, "GetPropList" );
  2206.         lpEntry->Release();
  2207.         return;
  2208.     }
  2209.  
  2210.     if ( lpPropTagArray->cValues == 0 )
  2211.     {
  2212.        MessageBox( "Couldn't get a property list on object.", "Error!", MB_OK );
  2213.        MAPIFreeBuffer( lpPropTagArray );
  2214.        lpEntry->Release();
  2215.        return;
  2216.     }
  2217.  
  2218.     MAPIAllocateBuffer( sizeof(SPropValue) * lpPropTagArray->cValues, (LPVOID *) &lpsPropValue );
  2219.     memset( (void *) lpsPropValue, 0, (size_t)(sizeof(SPropValue) * lpPropTagArray->cValues) );
  2220.  
  2221.     for(cValues = 0; cValues < lpPropTagArray->cValues; cValues++)
  2222.     {
  2223.         lpsPropValue[cValues].ulPropTag = lpPropTagArray->aulPropTag[cValues];
  2224.     }
  2225.  
  2226.     CPropertiesDlg * pdlgProperties = new CPropertiesDlg( lpPropTagArray->cValues,
  2227.                         lpsPropValue,
  2228.                         "GetPropList",
  2229.                         fmProperty | fmPropType );
  2230.  
  2231.     MAPIFreeBuffer( lpsPropValue );
  2232.     MAPIFreeBuffer( lpPropTagArray );
  2233.  
  2234.     lpEntry->Release();
  2235. }
  2236.  
  2237.  
  2238. /*
  2239.  -  CMAPIContainerDlg::
  2240.  -  OnTableDLL
  2241.  -
  2242.  *  Purpose:
  2243.  *      Opens a dialog to manipulate the current Table.
  2244.  *      The dialog is contained in a test DLL and can be
  2245.  *      called on any Table.
  2246.  *
  2247.  */
  2248.  
  2249. void CMAPIContainerDlg::OnTableDLL()
  2250. {
  2251.     HRESULT         hResult         = NULL;
  2252.     LPMAPITABLE     lpMAPITable     = NULL;
  2253.     ULONG           ulFlags         = 0;
  2254.  
  2255.     if (!hlibTBLVU)
  2256.         return;
  2257.  
  2258.     if(fUNICODE)
  2259.         ulFlags = ulFlags | MAPI_UNICODE;
  2260.  
  2261. //Check to see the type of the current table and open another that is the same type.
  2262.  
  2263.     if(m_ulCurrentTableType == fHierarchy)
  2264.     {
  2265.         if(fCONVENIENT_DEPTH)
  2266.             ulFlags = ulFlags | CONVENIENT_DEPTH;
  2267.     
  2268.         if( FAILED(hResult = ((LPABCONT)m_lpEntry)->GetHierarchyTable( ulFlags,
  2269.                                     &lpMAPITable )))
  2270.         {
  2271.             DisplayError( m_lpEntry, hResult, "GetHierarchyTable" );
  2272.             return;
  2273.         }
  2274.     }
  2275.     else
  2276.     {
  2277.     if( FAILED(hResult = ((LPABCONT)m_lpEntry)->GetContentsTable( ulFlags,
  2278.                                     &lpMAPITable )))
  2279.     {
  2280.         DisplayError( m_lpEntry, hResult, "GetContentsTable" );
  2281.         return;
  2282.     }
  2283. }
  2284.  
  2285. //Create Table Test dialog
  2286. TBLVUViewMapiTable( (LPMAPITABLE FAR *)&lpMAPITable, (HWND)this->m_hWnd );
  2287.  
  2288. lpMAPITable->Release();
  2289. }
  2290.  
  2291.  
  2292. /*
  2293.  -  CMAPIContainerDlg::
  2294.  -  OnPerformance
  2295.  -
  2296.  *  Purpose:
  2297.  *      Opens a dialog to perform performance testing of
  2298.  *      Address Book Service providers.
  2299.  *
  2300.  */
  2301.  
  2302. void CMAPIContainerDlg::OnPerformance()
  2303. {
  2304.     HRESULT         hResult         = NULL;
  2305.     LPMAPITABLE     lpMAPITable     = NULL;
  2306.     ULONG           ulFlags         = 0;
  2307.  
  2308.     if (!hlibPERF)
  2309.         return;
  2310.  
  2311.     if(fUNICODE)
  2312.         ulFlags = ulFlags | MAPI_UNICODE;
  2313.  
  2314.     if(m_ulCurrentTableType == fHierarchy)
  2315.     {
  2316.         if(fCONVENIENT_DEPTH)
  2317.             ulFlags = ulFlags | CONVENIENT_DEPTH;
  2318.     
  2319.         if( FAILED(hResult = ((LPABCONT)m_lpEntry)->GetHierarchyTable( ulFlags,
  2320.                                                 &lpMAPITable )))
  2321.         {
  2322.             DisplayError( m_lpEntry, hResult, "GetHierarchyTable" );
  2323.             return;
  2324.         }
  2325.     }
  2326.     else
  2327.     {
  2328.         if( FAILED(hResult = ((LPABCONT)m_lpEntry)->GetContentsTable( ulFlags,
  2329.                                                     &lpMAPITable )))
  2330.         {
  2331.             DisplayError( m_lpEntry, hResult, "GetContentsTable" );
  2332.             return;
  2333.         }
  2334.     }
  2335.  
  2336.     ABPERFormance(  (LPADRBOOK FAR *)&lpAdrBook,
  2337.     (LPMAPITABLE FAR *)&lpMAPITable,
  2338.     (HWND)this->m_hWnd );
  2339.  
  2340.     lpMAPITable->Release();
  2341. }
  2342.  
  2343. /*
  2344.  -  CMAPIContainerDlg::
  2345.  -  OnDetailsSel
  2346.  -
  2347.  *  Purpose:
  2348.  *      Calls Details with the EntryID of the Selection.
  2349.  *
  2350.  */
  2351.  
  2352. void CMAPIContainerDlg::OnDetailsSel()
  2353. {
  2354.     HRESULT       hResult     = NULL;
  2355.     LPSPropValue  lpProps     = NULL;
  2356.     ULONG         ulUIParam   = (ULONG)(void *)m_hWnd;
  2357.  
  2358.     int nIndex = m_lpTblList->GetCurSel();
  2359.     if( nIndex == -1 )
  2360.     {
  2361.         MessageBox("Please Select an Entry");
  2362.         m_lpTblList->SetFocus();
  2363.         return;
  2364.     }
  2365.  
  2366.     lpProps = (LPSPropValue)m_lpTblList->GetItemData(nIndex);
  2367.  
  2368.     if( FAILED(hResult = lpAdrBook->Details(
  2369.                                 &ulUIParam,
  2370.                                 NULL,
  2371.                                 NULL,
  2372.                                 lpProps[1].Value.bin.cb,
  2373.                                 (LPENTRYID)lpProps[1].Value.bin.lpb,
  2374.                                 NULL,
  2375.                                 NULL,
  2376.                                 NULL,
  2377.                                 DIALOG_MODAL )))
  2378.     {
  2379.         DisplayError( lpAdrBook, hResult, "Details" );
  2380.     }
  2381.  
  2382. }
  2383.  
  2384.  
  2385. /*
  2386.  -  CMAPIContainerDlg::
  2387.  -  OnTestSel
  2388.  -
  2389.  *  Purpose:
  2390.  *      Calls Test DLL with the EntryID and Type of the selection.
  2391.  *
  2392.  */
  2393.  
  2394. void CMAPIContainerDlg::OnTestSel()
  2395. {
  2396.     HRESULT         hResult         = NULL;
  2397.     ULONG           cValues         = 0;
  2398.     ULONG           ulFlags         = 0;
  2399.     ULONG           ulObjType       = 0;
  2400.     LPMAPIPROP      lpEntry         = NULL;
  2401.     LPSPropValue    lpsPropValue    = NULL;
  2402.     LPSPropValue    lpProps         = NULL;
  2403.     LPSPropTagArray lpPropTagArray  = NULL;
  2404.  
  2405.     if (!hlibTEST)
  2406.         return;
  2407.  
  2408.     int nIndex = m_lpTblList->GetCurSel();
  2409.     if( nIndex == -1 )
  2410.     {
  2411.         MessageBox("Please Select an Entry");
  2412.         m_lpTblList->SetFocus();
  2413.         return;
  2414.     }
  2415.  
  2416.     lpProps = (LPSPropValue)m_lpTblList->GetItemData(nIndex);
  2417.  
  2418.     if(fOpenEntry)
  2419.         ulFlags = MAPI_MODIFY;
  2420.  
  2421.     if( FAILED(hResult = lpAdrBook->OpenEntry( lpProps[1].Value.bin.cb,
  2422.                                                (LPENTRYID)lpProps[1].Value.bin.lpb,
  2423.                                                NULL,
  2424.                                                ulFlags,
  2425.                                                &ulObjType,
  2426.                                                (LPUNKNOWN*)&lpEntry )))
  2427.     {
  2428.         DisplayError( lpAdrBook, hResult, "OpenEntry" );
  2429.         return;
  2430.     }
  2431.  
  2432.     ABTest( (LPADRBOOK FAR *)&lpAdrBook,
  2433.             ulObjType,
  2434.             &lpEntry,
  2435.             (HWND)this->m_hWnd );
  2436. }
  2437.  
  2438.  
  2439. /*
  2440.  -  CMAPIContainerDlg::
  2441.  -  OnTestThis
  2442.  -
  2443.  *  Purpose:
  2444.  *      Calls Test DLL with the Type of the container.
  2445.  *
  2446.  */
  2447.  
  2448. void CMAPIContainerDlg::OnTestThis()
  2449. {
  2450.     HRESULT         hResult         = NULL;
  2451.     LPMAPITABLE     lpMAPITable     = NULL;
  2452.  
  2453.     if (!hlibTEST)
  2454.         return;
  2455.  
  2456.     ABTest( (LPADRBOOK FAR *)&lpAdrBook,
  2457.             m_ulObjType,
  2458.             &m_lpEntry,
  2459.             (HWND)this->m_hWnd );
  2460. }
  2461.  
  2462.  
  2463. /*
  2464.  -  CMAPIContainerDlg::
  2465.  -  OnAddToPABSel
  2466.  -
  2467.  *  Purpose:
  2468.  *      Adds selected EntryID to the PAB or target container.
  2469.  *
  2470.  */
  2471.  
  2472. void CMAPIContainerDlg::OnAddToPABSel()
  2473. {
  2474.     HRESULT         hResult         = NULL;
  2475.     ULONG           cbEntryID       = 0;
  2476.     LPENTRYID       lpEntryID       = NULL;
  2477.     ULONG           ulObjType       = 0;
  2478.     LPMAPIPROP      lpEntry         = NULL;
  2479.     LPMAPIPROP      lpMAPIPropEntry = NULL;
  2480.     ULONG           ulFlags         = 0;
  2481.     ULONG           ulTarget        = 0;
  2482.     ULONG           cValues         = 0;
  2483.     LPSPropValue    lpProps         = NULL;
  2484.     ULONG           ulData[2];
  2485.     LPSPropTagArray lpPTArray       = (LPSPropTagArray) &ulData;
  2486.  
  2487.     //Get the EntryID of the object we want to add
  2488.     int nIndex = m_lpTblList->GetCurSel();
  2489.     if( nIndex == -1 )
  2490.     {
  2491.         MessageBox("Please Select an Entry");
  2492.         m_lpTblList->SetFocus();
  2493.         return;
  2494.     }
  2495.  
  2496.     lpProps = (LPSPropValue)m_lpTblList->GetItemData(nIndex);
  2497.  
  2498.     if ( lpTargetEntryID )
  2499.     {
  2500.         ulTarget = MessageBox(
  2501.                            "Add to the target instead of the PAB?",
  2502.                                "Question", MB_YESNO | MB_ICONQUESTION );
  2503.         switch ( ulTarget )
  2504.         {
  2505.             case IDYES:
  2506.                 cbEntryID = cbTargetEntryID;
  2507.                 lpEntryID = lpTargetEntryID;
  2508.                 break;
  2509.  
  2510.             case IDNO:
  2511.                 //Find the PAB
  2512.                 if( FAILED(hResult = lpAdrBook->GetPAB( &cbEntryID,
  2513.                                                         &lpEntryID )))
  2514.                 {
  2515.                     DisplayError( lpAdrBook, hResult, "GetPAB" );
  2516.                     goto err;
  2517.                 }
  2518.                 break;
  2519.  
  2520.             default:
  2521.                 return;
  2522.         }
  2523.     }
  2524.     else
  2525.     {
  2526.         //Find the PAB
  2527.         if( FAILED(hResult = lpAdrBook->GetPAB( &cbEntryID,
  2528.                                                 &lpEntryID )))
  2529.         {
  2530.             DisplayError( lpAdrBook, hResult, "GetPAB" );
  2531.             goto err;
  2532.         }
  2533.     }
  2534.  
  2535.     if(fOpenEntry)
  2536.         ulFlags = MAPI_MODIFY;
  2537.  
  2538.     if( FAILED(hResult = lpAdrBook->OpenEntry( cbEntryID,
  2539.                                                lpEntryID,
  2540.                                                NULL,
  2541.                                                ulFlags,
  2542.                                                &ulObjType,
  2543.                                                (LPUNKNOWN*)&lpEntry )))
  2544.  
  2545.     {
  2546.         DisplayError( lpAdrBook, hResult, "OpenEntry" );
  2547.         goto err;
  2548.     }
  2549.  
  2550.     if( FAILED( hResult =
  2551.            ((LPABCONT)lpEntry)->CreateEntry(
  2552.                                 lpProps[1].Value.bin.cb,
  2553.                                 (LPENTRYID)lpProps[1].Value.bin.lpb,
  2554.                                 CREATE_CHECK_DUP_STRICT,
  2555.                                 &lpMAPIPropEntry )))
  2556.                                 {
  2557.                                     DisplayError( lpEntry, hResult, "CreateEntry" );
  2558.                                     goto err;
  2559.                                 }
  2560.  
  2561.     if( FAILED( hResult = lpMAPIPropEntry->SaveChanges( 0 )))
  2562.     {
  2563.         DisplayError( lpEntry, hResult, "SaveChanges" );
  2564.         goto err;
  2565.     }
  2566.  
  2567. err:
  2568.     MAPIFreeBuffer( lpEntryID );
  2569.  
  2570.     if( lpEntry )
  2571.         lpEntry->Release();
  2572.  
  2573.     if( lpMAPIPropEntry )
  2574.         lpMAPIPropEntry->Release();
  2575. }
  2576.  
  2577.  
  2578. /*
  2579.  -  CMAPIContainerDlg::
  2580.  -  OnSetAsTargetSel
  2581.  -
  2582.  *  Purpose:
  2583.  *      Makes selected EntryID the target container.
  2584.  *
  2585.  */
  2586.  
  2587. void CMAPIContainerDlg::OnSetAsTargetSel()
  2588. {
  2589.     LPSPropValue  lpProps     = NULL;
  2590.  
  2591.     int nIndex = m_lpTblList->GetCurSel();
  2592.     if( nIndex == -1 )
  2593.     {
  2594.         MessageBox("Please Select an Entry");
  2595.         m_lpTblList->SetFocus();
  2596.         return;
  2597.     }
  2598.  
  2599.     lpProps = (LPSPropValue)m_lpTblList->GetItemData(nIndex);
  2600.  
  2601.     cbTargetEntryID = lpProps[1].Value.bin.cb;
  2602.     lpTargetEntryID = (LPENTRYID)lpProps[1].Value.bin.lpb;
  2603. }
  2604.  
  2605.  
  2606. /*
  2607.  -  CMAPIContainerDlg::
  2608.  -  OnSetAsTargetThis
  2609.  -
  2610.  *  Purpose:
  2611.  *      Makes EntryID of the 'this' container the target container.
  2612.  *
  2613.  */
  2614.  
  2615. void CMAPIContainerDlg::OnSetAsTargetThis()
  2616. {
  2617.     HRESULT         hResult   = NULL;
  2618.     ULONG           ulData[2];
  2619.     LPSPropTagArray lpPTArray   = (LPSPropTagArray) &ulData;
  2620.     ULONG           cValues         = 0;
  2621.     LPSPropValue    lpsPropValue    = NULL;
  2622.  
  2623.     //Get the EntryID of the object we want to add
  2624.     //Create a PropTagArray with properties to request
  2625.     lpPTArray->cValues = 1;
  2626.     lpPTArray->aulPropTag[0] = PR_ENTRYID;
  2627.  
  2628.     if( FAILED(hResult = m_lpEntry->GetProps( lpPTArray, 0,
  2629.                                               &cValues,
  2630.                                               &lpsPropValue )))
  2631.     {
  2632.         DisplayError( m_lpEntry, hResult, "GetProps" );
  2633.         cbTargetEntryID = 0;
  2634.         lpTargetEntryID = NULL;
  2635.         return;
  2636.     }
  2637.  
  2638.     cbTargetEntryID = lpsPropValue[0].Value.bin.cb;
  2639.     lpTargetEntryID = (LPENTRYID)lpsPropValue[0].Value.bin.lpb;
  2640. }
  2641.  
  2642. /*
  2643.  -  CMAPIContainerDlg::
  2644.  -  OnResolveNames
  2645.  -
  2646.  *  Purpose:
  2647.  *      Calls the ResolveNames() method of the Container.
  2648.  *
  2649.  */
  2650.  
  2651. void CMAPIContainerDlg::OnResolveNames()
  2652. {
  2653.     CResolveNameDlg dlgResolveName((LPABCONT)m_lpEntry);
  2654. }
  2655.  
  2656.  
  2657. /*
  2658.  -  CMAPIContainerDlg::
  2659.  -  OnOneOffTbl
  2660.  -
  2661.  *  Purpose:
  2662.  *      Calls the Container and request the One-Off Table.
  2663.  *
  2664.  */
  2665.  
  2666. void CMAPIContainerDlg::OnOneOffTbl()
  2667. {
  2668.     HRESULT         hResult         = NULL;
  2669.     LPMAPITABLE     lpTable         = NULL;
  2670.  
  2671.     if(FAILED(hResult = m_lpEntry->OpenProperty( PR_CREATE_TEMPLATES,
  2672.                                                  (LPIID) &IID_IMAPITable,
  2673.                                                  0,
  2674.                                                  0,
  2675.                                                  (LPUNKNOWN *)&lpTable)))
  2676.     {
  2677.         DisplayError( m_lpEntry, hResult, "OpenProperty" );
  2678.         return;
  2679.     }
  2680.     
  2681.     if(hlibTBLVU)
  2682.         TBLVUViewMapiTable( (LPMAPITABLE FAR *)&lpTable, m_hWnd );
  2683.     else
  2684.         AfxMessageBox( "Table Viewer not available", MB_ICONEXCLAMATION | MB_OK, 0 );
  2685.  
  2686.     if(lpTable)
  2687.         lpTable->Release();
  2688. }
  2689.  
  2690.  
  2691. /*
  2692.  -  CMAPIContainerDlg::
  2693.  -  ~CMAPIContainerDlg
  2694.  -
  2695.  *  Purpose:
  2696.  *      Destructor for class CMAPIContainerDlg.  Will release
  2697.  *      the Table being viewed.
  2698.  *
  2699.  */
  2700.  
  2701. CMAPIContainerDlg::~CMAPIContainerDlg()
  2702. {
  2703.     if(m_lpMAPITable)
  2704.     {
  2705.         m_lpMAPITable->Release();
  2706.         m_lpMAPITable = NULL;
  2707.     }
  2708. }
  2709.  
  2710.  
  2711.  
  2712. /*
  2713.  *  CABMailUserDlg Methods.
  2714.  */
  2715.  
  2716. /*
  2717.  -  CABMailUserDlg::
  2718.  -  OnInitDialog
  2719.  -
  2720.  *  Purpose:
  2721.  *      Displays a MailUser.
  2722.  *
  2723.  */
  2724.  
  2725. BOOL CABMailUserDlg::OnInitDialog()
  2726. {
  2727.     HRESULT         hResult         = NULL;
  2728.     ULONG           cValues         = 0;
  2729.     LPSPropValue    lpsPropValue    = NULL;
  2730.     ULONG           cProps          = 0;
  2731.     CWnd *          pBProp          = NULL;
  2732.     CWnd *          pBTest          = NULL;
  2733.     CWnd *          pBSetAsTarget   = NULL;
  2734.     CWnd *          pBDT            = NULL;
  2735.  
  2736.     ULONG ulData[4];
  2737.     LPSPropTagArray lpPTArray = (LPSPropTagArray) &ulData;
  2738.  
  2739.     if(!m_lpEntry)
  2740.         return FALSE;
  2741.  
  2742. //Disable Propvu button if DLL is not present.
  2743.     if(!hlibPROPVU)
  2744.     {
  2745.         pBProp = GetDlgItem(IDC_PROPERTYDLL);
  2746.         pBProp->EnableWindow( FALSE );
  2747.     }
  2748.  
  2749. //Disable Test button if DLL is not present.
  2750.     if(!hlibTEST)
  2751.     {
  2752.         pBTest = GetDlgItem(IDC_TESTTHISDLL);
  2753.         pBTest->EnableWindow( FALSE );
  2754.     }
  2755.  
  2756. //Disable Display Table button if DLL is not present.
  2757.     if(!hlibTBLVU)
  2758.     {
  2759.         pBDT = GetDlgItem(IDC_PR_DETAILS_TABLE);
  2760.         pBDT->EnableWindow( FALSE );
  2761.     }
  2762.  
  2763. //Disable SetAsTarget button if option is disabled.
  2764.     if(!fSetAsTarget)
  2765.     {
  2766.         pBSetAsTarget = GetDlgItem(IDC_SETASTARGETTHIS);
  2767.         pBSetAsTarget->EnableWindow( FALSE );
  2768.     }
  2769.  
  2770. //Create a PropTagArray with properties to request
  2771.     lpPTArray->cValues = 3;
  2772.     lpPTArray->aulPropTag[0] = PR_DISPLAY_NAME;
  2773.     lpPTArray->aulPropTag[1] = PR_EMAIL_ADDRESS;
  2774.     lpPTArray->aulPropTag[2] = PR_ADDRTYPE;
  2775.  
  2776.     if( FAILED(hResult = m_lpEntry->GetProps( lpPTArray, 0,
  2777.                                                 &cValues,
  2778.                                                 &lpsPropValue )))
  2779.     {
  2780.         DisplayError( m_lpEntry, hResult, "GetProps" );
  2781.         return FALSE;
  2782.     }
  2783.  
  2784.     SetDlgItemText(IDC_DISPLAYNAME,  lpsPropValue[0].Value.lpszA );
  2785.     SetDlgItemText(IDC_EMAILADDRESS, lpsPropValue[1].Value.lpszA );
  2786.     SetDlgItemText(IDC_EMAILTYPE,    lpsPropValue[2].Value.lpszA );
  2787.  
  2788.     MAPIFreeBuffer( lpsPropValue );
  2789.  
  2790.     return TRUE;
  2791. }
  2792.  
  2793.  
  2794. /*
  2795.  -  CABMailUserDlg::
  2796.  -  OnOK
  2797.  -
  2798.  *  Purpose:
  2799.  *      Closes the dialog
  2800.  *
  2801.  */
  2802.  
  2803. void CABMailUserDlg::OnOK()
  2804. {
  2805.     EndDialog(IDOK);
  2806. }
  2807.  
  2808.  
  2809. /*
  2810.  -  CABMailUserDlg::
  2811.  -  OnTestThis
  2812.  -
  2813.  *  Purpose:
  2814.  *      Calls Test DLL with the Type of the container.
  2815.  *
  2816.  */
  2817.  
  2818. void CABMailUserDlg::OnTestThis()
  2819. {
  2820.     HRESULT         hResult         = NULL;
  2821.     LPMAPITABLE     lpMAPITable     = NULL;
  2822.  
  2823.     if (!hlibTEST)
  2824.         return;
  2825.  
  2826.     ABTest( (LPADRBOOK FAR *)&lpAdrBook,
  2827.             MAPI_MAILUSER,
  2828.             &m_lpEntry,
  2829.             (HWND)this->m_hWnd );
  2830. }
  2831.  
  2832.  
  2833. /*
  2834.  -  CABMailUserDlg::
  2835.  -  OnSetAsTargetThis
  2836.  -
  2837.  *  Purpose:
  2838.  *      Makes EntryID of the MU the target container.
  2839.  *
  2840.  */
  2841.  
  2842. void CABMailUserDlg::OnSetAsTargetThis()
  2843. {
  2844.     HRESULT         hResult   = NULL;
  2845.     ULONG           ulData[2];
  2846.     LPSPropTagArray lpPTArray   = (LPSPropTagArray) &ulData;
  2847.     ULONG           cValues         = 0;
  2848.     LPSPropValue    lpsPropValue    = NULL;
  2849.  
  2850.     //Get the EntryID of the object we want to add
  2851.     //Create a PropTagArray with properties to request
  2852.     lpPTArray->cValues = 1;
  2853.     lpPTArray->aulPropTag[0] = PR_ENTRYID;
  2854.  
  2855.     if( FAILED(hResult = m_lpEntry->GetProps( lpPTArray, 0,
  2856.                                               &cValues,
  2857.                                               &lpsPropValue )))
  2858.     {
  2859.         DisplayError( m_lpEntry, hResult, "GetProps" );
  2860.         cbTargetEntryID = 0;
  2861.         lpTargetEntryID = NULL;
  2862.         return;
  2863.     }
  2864.  
  2865.     cbTargetEntryID = lpsPropValue[0].Value.bin.cb;
  2866.     lpTargetEntryID = (LPENTRYID)lpsPropValue[0].Value.bin.lpb;
  2867. }
  2868.  
  2869.  
  2870. /*
  2871.  -  CABMailUserDlg::
  2872.  -  OnGetPropListThis
  2873.  -
  2874.  *  Purpose:
  2875.  *      Calls the base class method GetPropList.
  2876.  *
  2877.  */
  2878.  
  2879. void CABMailUserDlg::OnGetPropListThis()
  2880. {
  2881.     CMAPIPropDlg::OnGetPropListThis();
  2882. }
  2883.  
  2884.  
  2885. /*
  2886.  -  CABMailUserDlg::
  2887.  -  OnCancel
  2888.  -
  2889.  *  Purpose:
  2890.  *      Cancels the Mail User viewer dialog.
  2891.  *
  2892.  */
  2893.  
  2894. void CABMailUserDlg::OnCancel()
  2895. {
  2896.     EndDialog(IDCANCEL);
  2897. }
  2898.  
  2899.  
  2900. /*
  2901.  *  COneOffDlg Methods.
  2902.  */
  2903.  
  2904. /*
  2905.  -  COneOffDlg::
  2906.  -  OnInitDialog
  2907.  -
  2908.  *  Purpose:
  2909.  *      Displays Controls to Create a MailUser.
  2910.  *
  2911.  */
  2912.  
  2913. BOOL COneOffDlg::OnInitDialog()
  2914. {
  2915.     SetDlgItemText(IDC_DISPLAYNAME,  "foo" );
  2916.     SetDlgItemText(IDC_EMAILADDRESS, "\\\\foo\\inbound" );
  2917.     SetDlgItemText(IDC_EMAILTYPE,    "MSPEER" );
  2918.  
  2919.     return TRUE;
  2920. }
  2921.  
  2922.  
  2923. /*
  2924.  -  COneOffDlg::
  2925.  -  OnOK
  2926.  -
  2927.  *  Purpose:
  2928.  *      Closes the dialog
  2929.  *
  2930.  */
  2931.  
  2932. void COneOffDlg::OnOK()
  2933. {
  2934.     HRESULT     hResult = NULL;
  2935.     SCODE       sc  = S_OK;
  2936.     ULONG       cbEntryID = 0;
  2937.     LPENTRYID   lpEntryID = NULL;
  2938.  
  2939.     char szDisplayName[256];
  2940.     char szInboxPath[256];
  2941.     char szEmailType[15];
  2942.  
  2943.     GetDlgItemText(IDC_DISPLAYNAME,  szDisplayName, 256);
  2944.     GetDlgItemText(IDC_EMAILADDRESS, szInboxPath,   256);
  2945.     GetDlgItemText(IDC_EMAILTYPE,    szEmailType,    15);
  2946.  
  2947.     if( FAILED(hResult = lpAdrBook->CreateOneOff( szDisplayName,
  2948.                                         szEmailType,
  2949.                                         szInboxPath,
  2950.                                         0,
  2951.                                         &cbEntryID,
  2952.                                         &lpEntryID )))
  2953.     {
  2954.         DisplayError( lpAdrBook, hResult, "CreateOneOff" );
  2955.         return;
  2956.     }
  2957.  
  2958.     sc = ScOpenEntry( cbEntryID, lpEntryID, DT_MAILUSER, fContents, FALSE );
  2959.     MAPIFreeBuffer( lpEntryID );
  2960. }
  2961.  
  2962.  
  2963.  
  2964. /*
  2965.  -  COneOffDlg::
  2966.  -  OnCancel
  2967.  -
  2968.  *  Purpose:
  2969.  *      Cancels the CreateOneOff dialog.
  2970.  *
  2971.  */
  2972.  
  2973. void COneOffDlg::OnCancel()
  2974. {
  2975.     EndDialog(IDCANCEL);
  2976. }
  2977.  
  2978.  
  2979.  
  2980. /*
  2981.  *  CResolveNameDlg Methods.
  2982.  */
  2983.  
  2984. /*
  2985.  -  CResolveNameDlg::
  2986.  -  OnInitDialog
  2987.  -
  2988.  *  Purpose:
  2989.  *      Initializes the ResolveName Dialog
  2990.  *
  2991.  */
  2992.  
  2993. BOOL CResolveNameDlg::OnInitDialog()
  2994. {
  2995.     wsprintf(m_szPartialName, "foo; bar" );
  2996.  
  2997.     SetDlgItemText(IDC_RESOLVENAME, m_szPartialName);
  2998.     SendDlgItemMessage(IDC_RESOLVENAME, EM_SETSEL);
  2999.  
  3000.     return TRUE;
  3001. }
  3002.  
  3003. /*
  3004.  -  CResolveNameDlg::
  3005.  -  OnOK
  3006.  -
  3007.  *  Purpose:
  3008.  *      Calls ResolveName with the string passed in.
  3009.  *
  3010.  */
  3011.  
  3012. void CResolveNameDlg::OnOK()
  3013. {
  3014.     HRESULT         hResult     = NULL;
  3015.     ULONG           ulUIParam   = (ULONG)(void *)m_hWnd;
  3016.     LPADRLIST       lpAdrList   = NULL;
  3017.     char            seps[]      = "\n;";
  3018.     LPSTR           lpsztoken   = NULL;
  3019.     ULONG           ulCount     = 0;
  3020.     ULONG           ulEntry     = 0;
  3021.     char            szBuffer[256];
  3022.     LPFlagList      lpFlagsResolveNames;
  3023.     
  3024.     GetDlgItemText( IDC_RESOLVENAME, m_szPartialName, 256 );
  3025.     GetDlgItemText( IDC_RESOLVENAME, szBuffer, 256 );
  3026.  
  3027.     lpsztoken = strtok( szBuffer, seps );
  3028.  
  3029.     while (lpsztoken != NULL)
  3030.     {
  3031.         ulCount++;
  3032.         lpsztoken = strtok( NULL, seps );
  3033.     }
  3034.  
  3035.     MAPIAllocateBuffer( (sizeof(ADRLIST)*ulCount) + (sizeof(ADRENTRY)*ulCount), (LPVOID *) &lpAdrList );
  3036.  
  3037.     if(m_fCallResolveNames)
  3038.     {
  3039.         MAPIAllocateBuffer( sizeof(FlagList) + (sizeof(ULONG)*ulCount), (LPVOID *) &lpFlagsResolveNames );
  3040.         lpFlagsResolveNames->cFlags = ulCount;
  3041.     }
  3042.  
  3043.     lpsztoken = strtok( m_szPartialName, seps );
  3044.     lpAdrList->cEntries = ulCount;
  3045.  
  3046.     while (lpsztoken != NULL)
  3047.     {
  3048.         MAPIAllocateBuffer( sizeof(SPropValue), (LPVOID *) &lpAdrList->aEntries[ulEntry].rgPropVals );
  3049.         lpAdrList->aEntries[ulEntry].cValues = 1;
  3050.         lpAdrList->aEntries[ulEntry].rgPropVals->ulPropTag = PR_DISPLAY_NAME;
  3051.         lpAdrList->aEntries[ulEntry].rgPropVals->Value.lpszA = lpsztoken;
  3052.  
  3053.         if(m_fCallResolveNames)
  3054.         {
  3055.             lpFlagsResolveNames->ulFlag[ulEntry] = MAPI_UNRESOLVED;
  3056.         }
  3057.  
  3058.         ulEntry++;
  3059.         lpsztoken = strtok( NULL, seps );
  3060.     }
  3061.  
  3062.     if(m_fCallResolveNames)
  3063.     {
  3064.         if( FAILED(hResult = m_lpABContainer->ResolveNames(
  3065.                                 NULL,
  3066.                                 0,
  3067.                                 lpAdrList,
  3068.                                 lpFlagsResolveNames )))
  3069.         {
  3070.             DisplayError( m_lpABContainer, hResult, "ResolveNames" );
  3071.             _FreeRowSet((LPSRowSet) lpAdrList);
  3072.             return;
  3073.         }
  3074.  
  3075.         MAPIFreeBuffer(lpFlagsResolveNames);
  3076.     }
  3077.     else
  3078.     {
  3079.         if( FAILED(hResult = lpAdrBook->ResolveName( ulUIParam,
  3080.                                 MAPI_DIALOG,
  3081.                                 "Add:",
  3082.                                 lpAdrList )))
  3083.         {
  3084.             DisplayError( lpAdrBook, hResult, "ResolveName" );
  3085.             _FreeRowSet((LPSRowSet) lpAdrList);
  3086.             return;
  3087.         }
  3088.     }
  3089.  
  3090.     CAdrListDlg dlgAdrList(lpAdrList);
  3091.     _FreeRowSet((LPSRowSet)lpAdrList);
  3092. }
  3093.  
  3094. /*
  3095.  -  CResolveNameDlg::
  3096.  -  OnCancel
  3097.  -
  3098.  *  Purpose:
  3099.  *      Closes the ResolveName dialog
  3100.  *
  3101.  */
  3102.  
  3103. void CResolveNameDlg::OnCancel()
  3104. {
  3105.     EndDialog(IDCANCEL);
  3106. }
  3107.  
  3108.  
  3109. /*
  3110.  -  CAdrListDlg::
  3111.  -  OnInitDialog
  3112.  -
  3113.  *  Purpose:
  3114.  *      InitDialog function for Adr Properties List.  Fills the
  3115.  *      ListBox with property information from the Address List.
  3116.  *
  3117.  */
  3118.  
  3119. BOOL CAdrListDlg::OnInitDialog()
  3120. {
  3121.     ULONG cEntries  = 0;
  3122.     ULONG cProp     = 0;
  3123.  
  3124.     VERIFY(m_AdrListBox.SubclassDlgItem(IDC_ADRLIST, this));
  3125.  
  3126.     if(!m_lpAdrList)
  3127.         return FALSE;
  3128.  
  3129.     for(cEntries=0; cEntries<m_lpAdrList->cEntries; cEntries++)
  3130.     {
  3131.         for(cProp=0; cProp<m_lpAdrList->aEntries[cEntries].cValues; cProp++)
  3132.         {
  3133.             if( m_lpAdrList->aEntries[cEntries].rgPropVals[cProp].ulPropTag == PR_DISPLAY_NAME )
  3134.             m_AdrListBox.AddString( m_lpAdrList->aEntries[cEntries].rgPropVals[cProp].Value.lpszA );
  3135.         }
  3136.     }
  3137.  
  3138.     SetWindowText(m_Caption);
  3139.     m_AdrListBox.SetCurSel( 0 );
  3140.     return TRUE;
  3141.  
  3142. }
  3143.  
  3144.  
  3145. /*
  3146.  -  CAdrListDlg::
  3147.  -  OnOK
  3148.  -
  3149.  *  Purpose:
  3150.  *      Will open a dialog with information about the Adr List
  3151.  *
  3152.  */
  3153.  
  3154. void CAdrListDlg::OnOK()
  3155. {
  3156.     int nIndex = m_AdrListBox.GetCurSel();
  3157.     if (nIndex == -1)
  3158.     {
  3159.         MessageBox("Please Select an Entry");
  3160.         m_AdrListBox.SetFocus();
  3161.         return;
  3162.     }
  3163.  
  3164.     CPropertiesDlg * pdlgProperties = new CPropertiesDlg(
  3165.     m_lpAdrList->aEntries[nIndex].cValues,
  3166.     m_lpAdrList->aEntries[nIndex].rgPropVals,
  3167.     "AdrEntry",
  3168.     fmAProperty );
  3169. }
  3170.  
  3171.  
  3172. /*
  3173.  -  CAdrListDlg::
  3174.  -  OnCancel
  3175.  -
  3176.  *  Purpose:
  3177.  *      Cancels the Adr Property ListBox viewer
  3178.  *
  3179.  */
  3180.  
  3181. void CAdrListDlg::OnCancel()
  3182. {
  3183.     EndDialog(IDCANCEL);
  3184. }
  3185.  
  3186.  
  3187. /*
  3188.  -  CAdrListDlg::
  3189.  -  OnRecipOptions
  3190.  -
  3191.  *  Purpose:
  3192.  *      Displays a modal per-recipient options dialog box on
  3193.  *      a particular recipient entry.  The function returns
  3194.  *      a new ADRENTRY with the appropriate per-recipient options.
  3195.  *
  3196.  */
  3197.  
  3198. void CAdrListDlg::OnRecipOptions()
  3199. {
  3200.     HRESULT         hResult     = NULL;
  3201.     ULONG           ulUIParam   = (ULONG)(void *)m_hWnd;
  3202.     LPADRENTRY      lpRecip     = NULL;
  3203.  
  3204.     int nIndex = m_AdrListBox.GetCurSel();
  3205.     if (nIndex == -1)
  3206.     {
  3207.         MessageBox("Please Select an Entry");
  3208.         m_AdrListBox.SetFocus();
  3209.         return;
  3210.     }
  3211.  
  3212.     if(!m_lpAdrList)
  3213.         return;
  3214.  
  3215.     lpRecip = &m_lpAdrList->aEntries[nIndex];
  3216.  
  3217.     if( hResult = lpAdrBook->RecipOptions( ulUIParam,
  3218.                                            0,
  3219.                                            lpRecip ))
  3220.     {
  3221.         DisplayError( lpAdrBook, hResult, "RecipOptions" );
  3222.     }
  3223. }
  3224.  
  3225.  
  3226. /*
  3227.  -  CAdrListDlg::
  3228.  -  OnOpenEntry
  3229.  -
  3230.  *  Purpose:
  3231.  *      Finds the ENTRYID from the currently selected
  3232.  *      recipient, and open entries it.
  3233.  */
  3234.  
  3235. void CAdrListDlg::OnOpenEntry()
  3236. {
  3237.     SCODE   sc      = S_OK;
  3238.     ULONG   cProp   = 0;
  3239.     ULONG   ulDisplayType = 0;
  3240.  
  3241.     int nIndex = m_AdrListBox.GetCurSel();
  3242.     if (nIndex == -1)
  3243.     {
  3244.         MessageBox("Please Select an Entry");
  3245.         m_AdrListBox.SetFocus();
  3246.         return;
  3247.     }
  3248.  
  3249.     if(!m_lpAdrList)
  3250.         return;
  3251.  
  3252.     for(cProp=0; cProp<m_lpAdrList->aEntries[nIndex].cValues; cProp++)
  3253.     {
  3254.         if( m_lpAdrList->aEntries[nIndex].rgPropVals[cProp].ulPropTag == PR_DISPLAY_TYPE )
  3255.         {
  3256.             ulDisplayType = m_lpAdrList->aEntries[nIndex].rgPropVals[cProp].Value.ul;
  3257.         }
  3258.     }
  3259.  
  3260.  
  3261.     for(cProp=0; cProp<m_lpAdrList->aEntries[nIndex].cValues; cProp++)
  3262.     {
  3263.         if( m_lpAdrList->aEntries[nIndex].rgPropVals[cProp].ulPropTag == PR_ENTRYID )
  3264.         {
  3265.             sc = ScOpenEntry( m_lpAdrList->aEntries[nIndex].rgPropVals[cProp].Value.bin.cb,
  3266.             (LPENTRYID)m_lpAdrList->aEntries[nIndex].rgPropVals[cProp].Value.bin.lpb,
  3267.             ulDisplayType,
  3268.             fContents,
  3269.             FALSE );
  3270.             break;
  3271.         }
  3272.     }
  3273. }
  3274.  
  3275.  
  3276. /*
  3277.  -  CAdrListDlg::
  3278.  -  OnPrepareRecips
  3279.  -
  3280.  *  Purpose:
  3281.  *      Calls PrepareRecips against the current Address List.
  3282.  */
  3283.  
  3284. void CAdrListDlg::OnPrepareRecips()
  3285. {
  3286.     HRESULT         hResult   = NULL;
  3287.     ULONG           ulFlags   = 0;
  3288.     ULONG           ulData[6];
  3289.     LPSPropTagArray lpPTArray = (LPSPropTagArray) &ulData;
  3290.     CString         szBuffer;
  3291.  
  3292.     lpPTArray->cValues = 3;
  3293.     lpPTArray->aulPropTag[0] = PR_DISPLAY_NAME;
  3294.     lpPTArray->aulPropTag[1] = PR_SURNAME;
  3295.     lpPTArray->aulPropTag[2] = PR_COMMENT;
  3296.  
  3297.     if ( FAILED ( hResult = lpAdrBook->PrepareRecips( ulFlags,
  3298.                                                       lpPTArray,
  3299.                                                       m_lpAdrList )))
  3300.     {
  3301.         DisplayError( lpAdrBook, hResult, "PrepareRecips" );
  3302.         return;
  3303.     }
  3304.  
  3305.     szBuffer += "PrepareRecips() successfully called against Address List.";
  3306.     szBuffer += "\r\nThe following properties have been requested:\r\n";
  3307.     szBuffer += "\r\nPR_DISPLAY_NAME";
  3308.     szBuffer += "\r\nPR_SURNAME";
  3309.     szBuffer += "\r\nPR_COMMENT";
  3310.     szBuffer += "\r\n\r\nUse Recip Props to view internals of modified List.";
  3311.     AfxMessageBox( szBuffer, MB_OK, 0 );
  3312. }
  3313.  
  3314.  
  3315. /*
  3316.  -  CAdrListDlg::
  3317.  -  ~CAdrListDlg
  3318.  -
  3319.  *  Purpose:
  3320.  *      Destructor for CAdrListDlg Class
  3321.  *
  3322.  */
  3323.  
  3324. CAdrListDlg::~CAdrListDlg()
  3325. {
  3326. }
  3327.  
  3328.  
  3329. /*
  3330.  -  CPropertiesDlg::
  3331.  -  RenderProperties
  3332.  -
  3333.  *  Purpose:
  3334.  *      Fills the CListBox with Textized Property information.
  3335.  *
  3336.  */
  3337.  
  3338. void CPropertiesDlg::RenderProperties( ULONG cValues, LPSPropValue lpProps, ULONG fmDisplay )
  3339. {
  3340.     ULONG   idx;
  3341.     int     rgTabStops[2];
  3342.     char    szBuffer[1024];
  3343.     char    szID[50];
  3344.     char    szData[512];
  3345.     char    szType[32];
  3346.  
  3347.     /* Clear the ListBox, Set its size, and set its TabStops */
  3348.  
  3349.     SendDlgItemMessage(IDC_PROPLIST, LB_RESETCONTENT, 0, 0);
  3350.  
  3351.     SendDlgItemMessage(IDC_PROPLIST, LB_SETHORIZONTALEXTENT,
  3352.                 (WPARAM)VALUES_LB_HOR_SIZE, 0);
  3353.  
  3354.     rgTabStops[0] = VALUES_LB_TAB1;
  3355.     rgTabStops[1] = VALUES_LB_TAB2;
  3356.  
  3357.     SendDlgItemMessage(IDC_PROPLIST, LB_SETTABSTOPS,
  3358.                 (WPARAM)2, (LPARAM)rgTabStops);
  3359.  
  3360.     /* Populate the ListBox with the data for this row */
  3361.  
  3362.     for(idx = 0; idx < cValues; idx++)
  3363.     {
  3364.         szID[0]     = '\0';
  3365.         szData[0]   = '\0';
  3366.         szType[0]   = '\0';
  3367.         szBuffer[0] = '\0';
  3368.  
  3369.         if( fmProperty & fmDisplay )
  3370.         {
  3371.             if(GetString("PropIDs", PROP_ID(lpProps[idx].ulPropTag), szID))
  3372.             {
  3373.                 lstrcat(szBuffer, szID );
  3374.                 lstrcat(szBuffer, "\t");
  3375.             }
  3376.             else
  3377.             {
  3378.                 wsprintf(szBuffer,"%#04X\t", PROP_ID(lpProps[idx].ulPropTag));
  3379.             }
  3380.         }
  3381.  
  3382.  
  3383.         if( fmPropType & fmDisplay )
  3384.         {
  3385.             if(GetString("PropType", PROP_TYPE(lpProps[idx].ulPropTag), szType))
  3386.             {
  3387.                 lstrcat(szBuffer, szType);
  3388.                 lstrcat(szBuffer, "\t");
  3389.             }
  3390.             else
  3391.             {
  3392.                 wsprintf(szType, "%#04X\t", PROP_TYPE(lpProps[idx].ulPropTag));
  3393.                 lstrcat(szBuffer, szType);
  3394.             }
  3395.         }
  3396.  
  3397.  
  3398.         if( fmPropValue & fmDisplay )
  3399.         {
  3400.             SzGetPropValue(szData, (LPSPropValue)&lpProps[idx]);
  3401.             lstrcat(szBuffer, szData);
  3402.         }
  3403.  
  3404.     SendDlgItemMessage(IDC_PROPLIST, LB_ADDSTRING, 0, (LPARAM)szBuffer);
  3405.     }
  3406. }
  3407.  
  3408.  
  3409.  
  3410. /*
  3411.  -  CPropertiesDlg::
  3412.  -  OnInitDialog
  3413.  -
  3414.  *  Purpose:
  3415.  *      InitDialog function for CPropertiesDlg.  Fills the CListBox
  3416.  *      with Textized Property information.
  3417.  *
  3418.  */
  3419.  
  3420. BOOL CPropertiesDlg::OnInitDialog()
  3421. {
  3422.     GetSystemMenu(FALSE)->EnableMenuItem(SC_CLOSE, MF_GRAYED);
  3423.  
  3424.     VERIFY(m_ListBox.SubclassDlgItem(IDC_PROPLIST, this));
  3425.  
  3426.     if(!m_lpProps)
  3427.         return FALSE;
  3428.  
  3429.     RenderProperties( m_cValues, m_lpProps, m_fmDisplay );
  3430.  
  3431.     SetWindowText(m_Caption);
  3432.     m_ListBox.SetCurSel( 0 );
  3433.     return TRUE;
  3434. }
  3435.  
  3436.  
  3437. /*
  3438.  -  CPropertiesDlg::
  3439.  -  OnCancel
  3440.  -
  3441.  *  Purpose:
  3442.  *      Cancels the CPropertiesDlg dialog
  3443.  *
  3444.  */
  3445.  
  3446. void CPropertiesDlg::OnCancel()
  3447. {
  3448.     delete this;
  3449. }
  3450.  
  3451.  
  3452.  
  3453. /*
  3454.  -  CNamedIDsDlg::
  3455.  -  RenderNamedIDs
  3456.  -
  3457.  *  Purpose:
  3458.  *      Fills the CListBox with Named IDs Information.
  3459.  *
  3460.  */
  3461.  
  3462. void CNamedIDsDlg::RenderNamedIDs( ULONG cPropNames, LPMAPINAMEID FAR * lppPropNames )
  3463. {
  3464.     char szBuffer[256];
  3465.     int i = 0;
  3466. #ifdef WIN16
  3467.     WCHAR *pwsz;
  3468.     ULONG   cch;
  3469. #endif
  3470.  
  3471.     /* Clear the ListBox, Set its size, and set its TabStops */
  3472.  
  3473.     SendDlgItemMessage(IDC_PROPLIST, LB_RESETCONTENT, 0, 0);
  3474.  
  3475.     SendDlgItemMessage(IDC_PROPLIST, LB_SETHORIZONTALEXTENT,
  3476.                 (WPARAM)VALUES_LB_HOR_SIZE, 0);
  3477.  
  3478.     if( !lppPropNames )
  3479.     {
  3480.         return;
  3481.     }
  3482.     
  3483.     while( i < cPropNames )
  3484.     {
  3485.         if( !lppPropNames[i] )
  3486.         {
  3487.             i++;
  3488.             continue;
  3489.         }
  3490.         
  3491.         switch( (*lppPropNames[i]).ulKind )
  3492.         {
  3493.             case MNID_ID:
  3494.             {
  3495.                  wsprintf( szBuffer, "(*lppPropNames[%d]).Kind.lID = %ld", i, (*lppPropNames[i]).Kind.lID );
  3496.             }
  3497.             break;
  3498.             
  3499.             case MNID_STRING:
  3500.             {
  3501. #ifdef WIN16
  3502.                 pwsz = (*lppPropNames[i]).Kind.lpwstrName;
  3503.     
  3504.                 cch = 0;
  3505.                 while (*pwsz++ != 0)
  3506.                 {
  3507.                     szBuffer[cch]=(char)*pwsz;
  3508.                     cch += 1;
  3509.                 }
  3510.         
  3511. #else
  3512.                 if( (*lppPropNames[i]).Kind.lpwstrName )
  3513.                 {
  3514.                      wsprintf( szBuffer, "(*lppPropNames[%d]).Kind.lpwstrName = %ws", i, (*lppPropNames[i]).Kind.lpwstrName );
  3515.                 }
  3516.                 else
  3517.                 {
  3518.                     wsprintf( szBuffer, "(*lppPropNames[%d]) = NULL", i );
  3519.                 }
  3520. #endif
  3521.             }
  3522.             break;
  3523.             
  3524.             default:
  3525.             {
  3526.                 wsprintf( szBuffer, "(*lppPropNames[i]).ulKind = %lu  Invalid ID type in MAPINAMEID", (*lppPropNames[i]).ulKind );  
  3527.                 SendDlgItemMessage(IDC_PROPLIST, LB_ADDSTRING, 0, (LPARAM)szBuffer);
  3528.                 return;
  3529.             }
  3530.  
  3531.         }//switch
  3532.         SendDlgItemMessage(IDC_PROPLIST, LB_ADDSTRING, 0, (LPARAM)szBuffer);
  3533.         i++;
  3534.     }
  3535.  
  3536. }
  3537.  
  3538. /*
  3539.  -  CNamedIDsDlg::
  3540.  -  OnInitDialog
  3541.  -
  3542.  *  Purpose:
  3543.  *      InitDialog function for CNamedIDsDlg.  Fills the CListBox
  3544.  *      with Named IDs.
  3545.  *
  3546.  */
  3547.  
  3548. BOOL CNamedIDsDlg::OnInitDialog()
  3549. {
  3550.     GetSystemMenu(FALSE)->EnableMenuItem(SC_CLOSE, MF_GRAYED);
  3551.  
  3552.     VERIFY(m_ListBox.SubclassDlgItem(IDC_PROPLIST, this));
  3553.  
  3554.     if(!m_lppPropNames)
  3555.         return FALSE;
  3556.  
  3557.     RenderNamedIDs( m_cPropNames, m_lppPropNames );
  3558.  
  3559.     SetWindowText(m_Caption);
  3560.     m_ListBox.SetCurSel( 0 );
  3561.     return TRUE;
  3562. }
  3563.  
  3564.  
  3565. /*
  3566.  -  CNamedIDsDlg::
  3567.  -  OnCancel
  3568.  -
  3569.  *  Purpose:
  3570.  *      Cancels the CNamedIDsDlg dialog
  3571.  *
  3572.  */
  3573.  
  3574. void CNamedIDsDlg::OnCancel()
  3575. {
  3576.     delete this;
  3577. }
  3578.  
  3579.  
  3580. /*
  3581.  -  CGetError::
  3582.  -  SzError
  3583.  -
  3584.  *  Purpose:
  3585.  *      For printable Error String.  Uses the stringtable
  3586.  *      to textize the scode.
  3587.  *
  3588.  *  Parameters:
  3589.  *      szMsg       - Message Text
  3590.  *      sc          - SCODE
  3591.  *
  3592.  *  Returns:
  3593.  *      szError     - Textized information
  3594.  *
  3595.  */
  3596.  
  3597. LPSTR CGetError::SzError( LPSTR szMsg, SCODE sc )
  3598. {
  3599.  
  3600.     wsprintf( m_szMessage, "%s: ", szMsg );
  3601.  
  3602.     if(!GetString( "MAPIErrors", sc, m_szResult ))
  3603.     {
  3604.         lstrcpy( m_szResult, "??" );
  3605.         wsprintf( m_szBuffer, " 0x%04x", sc );
  3606.         strcat( m_szResult, m_szBuffer );
  3607.     }
  3608.  
  3609.     strcat( m_szMessage, m_szResult );
  3610.  
  3611.     return m_szMessage;
  3612. }
  3613.  
  3614. #ifdef WIN16
  3615. LPSTR CGetError::SzError( LPSTR szMsg, HRESULT hResult )
  3616. {
  3617.     SzError( szMsg, GetScode(hResult));
  3618.     return m_szMessage;
  3619. }
  3620. #endif
  3621.  
  3622.  
  3623. /*
  3624.  -  _FreeRowSet
  3625.  -
  3626.  *  Purpose:
  3627.  *      Given an RowSet, will free it.  Note that AdrLists
  3628.  *      have the same structure and can be freed by this
  3629.  *      call as well.
  3630.  *
  3631.  *  Parameters:
  3632.  *      LPSRowSet - Pointer to RowSet to free.
  3633.  *
  3634.  */
  3635.  
  3636. void _FreeRowSet( LPSRowSet lpRows )
  3637. {
  3638.     ULONG cRows;
  3639.  
  3640.     if( !lpRows )
  3641.         return;
  3642.  
  3643.     for( cRows = 0; cRows < lpRows->cRows; ++cRows )
  3644.     {
  3645.         MAPIFreeBuffer( lpRows->aRow[cRows].lpProps );
  3646.     }
  3647.  
  3648.     MAPIFreeBuffer( lpRows );
  3649. }
  3650.  
  3651.  
  3652. /*
  3653.  -  SCDisplayError
  3654.  -
  3655.  *  Purpose:
  3656.  *      Displays a MessageBox with Scode Textized.
  3657.  *
  3658.  *  Parameters:
  3659.  *      LPUNKNOWN - Pointer to the Object
  3660.  *      HRESULT   - Error code returned on the last call on this object.
  3661.  *      LPSTR     - Pointer to string to for value added information.
  3662.  */
  3663.  
  3664. void DisplayError( LPUNKNOWN lpUnkObj, HRESULT hResult, LPSTR szFunction )
  3665. {
  3666.     CString     szBuffer;
  3667.     CGetError   E;
  3668.     char        szLowLevelError[20];
  3669.     char        szContext[20];
  3670.     ULONG       ulLowLevelError = 0;
  3671.     LPMAPIERROR lpMAPIError = NULL;
  3672.  
  3673. //Check to see if user pressed Cancel on a dialog.  Since
  3674. //this is an return value that will occur naturally, don't
  3675. //process further.
  3676.  
  3677.     if( GetScode( hResult ) == MAPI_E_USER_CANCEL )
  3678.         return;
  3679.  
  3680. //Cast the LPUNKNOWN object to one that contains GetLastError.
  3681. //Since this call is guaranteed to be in the same location on
  3682. //all objects, this is a safe assumption.
  3683.  
  3684.     ((LPMAPIPROP)lpUnkObj)->GetLastError( hResult, 0, &lpMAPIError );
  3685.  
  3686. //Always start with the textized error code
  3687.  
  3688.     szBuffer = E.SzError(szFunction, hResult);
  3689.  
  3690. //If GetLastError returns a Message then append it
  3691.     if ( lpMAPIError )
  3692.     {
  3693.         if( lpMAPIError->lpszError )
  3694.         {
  3695.             szBuffer += "\r\n\r\n";
  3696.             szBuffer += lpMAPIError->lpszError;
  3697.         }
  3698.  
  3699. //If GetLastError had a LowLevelError to report then append it
  3700.  
  3701.     if( lpMAPIError->ulLowLevelError )
  3702.     {
  3703.         szBuffer += "\r\nGetLastError( lpMAPIError->ulLowLevelError ): ";
  3704.         wsprintf( szLowLevelError, "0x%04x", lpMAPIError->ulLowLevelError );
  3705.         szBuffer += szLowLevelError;
  3706.     }
  3707.  
  3708. //If GetLastError returns a Component then append it
  3709.  
  3710.     if( lpMAPIError->lpszComponent )
  3711.     {
  3712.         szBuffer += "\r\nlpMAPIError->Component: ";
  3713.         szBuffer += lpMAPIError->lpszComponent;
  3714.     }
  3715.  
  3716. //If GetLastError had a Context to report then append it
  3717.  
  3718.     if( lpMAPIError->ulContext )
  3719.     {
  3720.         szBuffer += "\r\nGetLastError( lpMAPIError->ulContext ): ";
  3721.         wsprintf( szContext, "0x%04x", lpMAPIError->ulContext );
  3722.         szBuffer += szContext;
  3723.     }
  3724. }
  3725. //Display the Error
  3726.  
  3727.     AfxMessageBox( szBuffer, MB_ICONEXCLAMATION | MB_OK, 0 );
  3728.     MAPIFreeBuffer( lpMAPIError );
  3729. }
  3730.  
  3731.  
  3732. /*
  3733.  -  ScGetRow
  3734.  -
  3735.  *  Purpose:
  3736.  *      Given a MAPITable and an index, find the RowSet.
  3737.  *      Tables tend to be dynamic.  In a static table,
  3738.  *      this function works well.  In tables that update
  3739.  *      constantly or have difficulty maining a static
  3740.  *      RowSet, this function is less than perfect.
  3741.  *
  3742.  *  Parameters:
  3743.  *      LPMAPITABLE - Pointer of Table to traverse
  3744.  *      int         - Index of RowSet to find
  3745.  *      * LPSRowSet - Address of RowSet to return.
  3746.  *
  3747.  */
  3748.  
  3749. SCODE ScGetRow( LPMAPITABLE lpMAPITable, int nIndex, LPSRowSet *lppRows )
  3750. {
  3751.     HRESULT hResult = NULL;
  3752.  
  3753.     if( !lpMAPITable )
  3754.     {
  3755.         return E_INVALIDARG;
  3756.     }
  3757.  
  3758.     if( FAILED(hResult = lpMAPITable->SeekRow(BOOKMARK_BEGINNING,
  3759.                                             nIndex,
  3760.                                             NULL )))
  3761.     {
  3762.         DisplayError( lpMAPITable, hResult, "SeekRow" );
  3763.         goto error;
  3764.     }
  3765.  
  3766.     if( FAILED(hResult = lpMAPITable->QueryRows( 1,
  3767.                                             0,
  3768.                                             lppRows )))
  3769.     {
  3770.         DisplayError( lpMAPITable, hResult, "QueryRows" );
  3771.         goto error;
  3772.     }
  3773.  
  3774.     error:
  3775.     return GetScode(hResult);
  3776. }
  3777.  
  3778.  
  3779. /*
  3780.  *
  3781.  -  ScOpenEntry
  3782.  -
  3783.  *  Purpose:
  3784.  *      Performs OpenEntry on the EntryID, finds out the object type,
  3785.  *      then creates an appropriate dialog to display the object in.
  3786.  *
  3787.  *  Parameters:
  3788.  *      ULONG       - Count of bytes in lpEntryID.
  3789.  *      LPENTRYID   - Pointer to the EntryID.
  3790.  *
  3791.  */
  3792.  
  3793. SCODE ScOpenEntry( ULONG cbEntryID, LPENTRYID lpEntryID, ULONG ulDisplayType, ULONG ulTableTypeFrom, BOOL fCONVENIENT_DEPTH)
  3794. {
  3795.     HRESULT     hResult         = NULL;
  3796.     ULONG       ulObjType       = 0;
  3797.     LPMAPIPROP  lpEntry         = NULL;
  3798.     BOOL        fRootContainer  = FALSE;
  3799.     ULONG       ulFlags         = 0;
  3800.     ULONG       ulSwitchType    = 0;
  3801.  
  3802.     if(fOpenEntry)
  3803.         ulFlags = ulFlags | MAPI_MODIFY;
  3804.         
  3805.     if( FAILED(hResult = lpAdrBook->OpenEntry(cbEntryID,
  3806.                                         lpEntryID,
  3807.                                         NULL,
  3808.                                         ulFlags,
  3809.                                         &ulObjType,
  3810.                                         (LPUNKNOWN*)&lpEntry)))
  3811.     {
  3812.         DisplayError( lpAdrBook, hResult, "OpenEntry" );
  3813.         return GetScode( hResult );
  3814.     }
  3815.  
  3816.     if(!lpEntryID)
  3817.         fRootContainer = TRUE;
  3818.  
  3819.     //DT_MAILUSER and DT_NOT_SPECIFIC are both defined as ((ULONG) 0x00000000),
  3820.     // so we need a way to determine whether or not we are looking at a
  3821.     // contents table (PR_DISPLAY_TYPE) or a a hierarchy table (PR_OBJECT_TYPE)
  3822.  
  3823.     if((ulTableTypeFrom == fRoot) || (ulTableTypeFrom == fHierarchy))
  3824.     {
  3825.         switch(ulDisplayType)
  3826.         {
  3827.             case DT_NOT_SPECIFIC:
  3828.                 ulSwitchType = ulObjType;
  3829.                 break;
  3830.  
  3831.             case DT_MODIFIABLE:
  3832.             case DT_GLOBAL:
  3833.             case DT_LOCAL:
  3834.             case DT_WAN:
  3835.                 ulSwitchType = MAPI_DISTLIST;
  3836.                 break;
  3837.                 
  3838.             default:
  3839.                 ulSwitchType = ulObjType;
  3840.         }
  3841.     }
  3842.     else
  3843.     {
  3844.         switch(ulDisplayType)
  3845.         {
  3846.             case DT_MAILUSER:
  3847.             case DT_REMOTE_MAILUSER:
  3848.                 ulSwitchType = MAPI_MAILUSER;
  3849.                 break;
  3850.  
  3851.             case DT_DISTLIST:
  3852.             case DT_PRIVATE_DISTLIST:
  3853.                 ulSwitchType = MAPI_DISTLIST;
  3854.                 break;
  3855.                 
  3856.             default:
  3857.                 ulSwitchType = ulObjType;
  3858.         } 
  3859.     }
  3860.  
  3861.     switch(ulSwitchType)
  3862.     {
  3863.         case MAPI_MAILUSER:
  3864.              CABMailUserDlg( (LPMAILUSER)lpEntry );
  3865.              break;
  3866.  
  3867.         case MAPI_ABCONT:
  3868.         case MAPI_DISTLIST:
  3869.              CMAPIContainerDlg( (LPABCONT)lpEntry, ulObjType, ulTableTypeFrom, fCONVENIENT_DEPTH );
  3870.              break;
  3871.  
  3872.         default:
  3873.             //Unknown Type
  3874.             lpEntry->Release();
  3875.             break;
  3876.     }
  3877.  
  3878.     return GetScode( hResult );
  3879. }
  3880.  
  3881.  
  3882. /*
  3883.  -  CMainWindow::
  3884.  -  CreateDisplayFonts
  3885.  -
  3886.  *  Purpose:
  3887.  *      Create Fonts for the ownerdraw listbox
  3888.  *
  3889.  */
  3890.  
  3891. void CMainWindow::CreateDisplayFonts()
  3892. {
  3893.     if (pBoldFont)
  3894.         return;
  3895.  
  3896.     pBoldFont  = new CFont;
  3897.     pNormFont  = new CFont;
  3898.     pLightFont = new CFont;
  3899.  
  3900.     LOGFONT lf;
  3901.     CClientDC DC ( this );
  3902.  
  3903.     memset(&lf, 0, sizeof(LOGFONT));
  3904.     lf.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS;
  3905.     char static BASED_CODE szFaceName[] = "MS Sans Serif";
  3906.     lstrcpy(lf.lfFaceName, szFaceName);
  3907.     lf.lfQuality = PROOF_QUALITY;
  3908.     lf.lfOutPrecision = OUT_CHARACTER_PRECIS;
  3909.  
  3910.     // Create Dark font
  3911.     // 10 point height Sans Serif font
  3912.     lf.lfHeight = -MulDiv(8,
  3913.                           DC.GetDeviceCaps( LOGPIXELSY),
  3914.                           72);
  3915.     lf.lfWeight = FW_BOLD;
  3916.     if ((pBoldFont->CreateFontIndirect(&lf)) == FALSE)
  3917.     {
  3918.         TRACE0("Warning: Using system font for List box font\n");
  3919.         pBoldFont->CreateStockObject(SYSTEM_FONT);
  3920.  
  3921.     }
  3922.  
  3923.     // Create Normal font
  3924.     // 9 point height Sans Serif font
  3925.     lf.lfHeight = -MulDiv(8,
  3926.                           DC.GetDeviceCaps( LOGPIXELSY),
  3927.                           72);
  3928.     lf.lfWeight = FW_SEMIBOLD;
  3929.     if ((pNormFont->CreateFontIndirect(&lf)) == FALSE)
  3930.     {
  3931.         TRACE0("Warning: Using system font for List box font\n");
  3932.         pNormFont->CreateStockObject(SYSTEM_FONT);
  3933.  
  3934.     }
  3935.  
  3936.     // Create light font
  3937.     // 8 point height Sans Serif font
  3938.     lf.lfHeight = -MulDiv(8,
  3939.                           DC.GetDeviceCaps( LOGPIXELSY),
  3940.                           72);
  3941.  
  3942.     lf.lfWeight = FW_MEDIUM;
  3943.     if ((pLightFont->CreateFontIndirect(&lf)) == FALSE)
  3944.     {
  3945.         TRACE0("Warning: Using system font for List box font\n");
  3946.         pLightFont->CreateStockObject(SYSTEM_FONT);
  3947.  
  3948.     }
  3949. }
  3950.  
  3951.  
  3952. /*
  3953.  -  CMainWindow::
  3954.  -  DeleteDisplayFonts
  3955.  -
  3956.  *  Purpose:
  3957.  *      Deletes the Fonts for the ownerdraw listbox
  3958.  *
  3959.  */
  3960.  
  3961. void CMainWindow::DeleteDisplayFonts()
  3962. {
  3963.     delete pBoldFont;
  3964.     delete pNormFont;
  3965.     delete pLightFont;
  3966.  
  3967.     pBoldFont  = NULL;
  3968.     pNormFont  = NULL;
  3969.     pLightFont = NULL;
  3970. }
  3971.  
  3972.  
  3973. /*
  3974.  -  CreateMAPIGuid
  3975.  -
  3976.  *  Purpose:
  3977.  *      Create a Guid.  Call MakeGuid helper function.
  3978.  *      In case the values changes, we only have to change it once.      
  3979.  *      The values are from PS_MAPI.
  3980.  */
  3981.  
  3982. void CreateMAPIGuid( LPGUID lpPropSetGuid )
  3983. {
  3984.     MakeGuid( lpPropSetGuid,
  3985.               0x3B7893D4,
  3986.               0x094C,
  3987.               0x101B,
  3988.               0x8D,
  3989.               0x98,
  3990.               0x00,
  3991.               0xAA,
  3992.               0x00,
  3993.               0x3C,
  3994.               0xD2,
  3995.               0x07 );
  3996. }
  3997.