home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / dbmsg / mapi / profile.cli / createpr.c next >
Encoding:
C/C++ Source or Header  |  1996-04-11  |  7.1 KB  |  254 lines

  1. /*
  2.  *  CREATEPR.C
  3.  *
  4.  *      Very simple console app creating a profile with hardcoded values.
  5.  *
  6.  *   Copyright (c) 1995, Microsoft Corporation. All Rights Reserved.
  7.  *
  8.  */
  9.  
  10. #include <mapiutil.h>
  11. #include <mapiwin.h>
  12. #include <mapidbg.h>
  13. #include <stdio.h>
  14. #include <smpms.h>
  15. #include <smpxp.h>
  16. #include <smpab.h>
  17.  
  18. #ifdef DEBUG
  19. #define TraceFnResult(f, hr)    \
  20. { (hr) ?   \
  21. printf(#f " returns 0x%08lX %s\n", GetScode(hr), SzDecodeScode(GetScode(hr))) : 0;\
  22. }
  23. #else
  24. #define TraceFnResult(f, hr)
  25. #endif  /*/DEBUG*/
  26.  
  27.  
  28. HRESULT HrCreateProfile(void);
  29.  
  30.  
  31. int main (void)
  32. {
  33.     HRESULT hr = 0;
  34.  
  35.     hr = HrCreateProfile();
  36.  
  37.     return (int) hr;
  38. }
  39.  
  40.  
  41.  
  42.  
  43. HRESULT HrCreateProfile(void)
  44. {
  45.     LPPROFADMIN         ppa = NULL;
  46.     LPSERVICEADMIN      psa = NULL;
  47.     LPMAPISESSION       pses = NULL;
  48.     LPMAPITABLE         ptblSvc = NULL;
  49.     HRESULT             hr;
  50.     
  51.     LPSRowSet           prows = NULL;
  52.     LPSRow              prow = NULL;
  53.  
  54.     enum {iSvcName, iSvcUID, cptaSvc};
  55.     SizedSPropTagArray (cptaSvc, ptaSvc) = { cptaSvc, 
  56.                                             {   PR_SERVICE_NAME,
  57.                                                 PR_SERVICE_UID } };
  58.     LPSTR               szProfile = "User XXX";
  59.     #define cProviders  3
  60.     #define nMAXProps   6
  61.     SPropValue          rgval[nMAXProps];
  62.  
  63.  
  64.     hr = MAPIInitialize(NULL);
  65.     if (HR_FAILED(hr))
  66.     {
  67.         TraceFnResult(MAPIInitialize, hr);
  68.         return hr;
  69.     }
  70.  
  71.     hr = MAPIAdminProfiles(0, &ppa);
  72.     if (HR_FAILED(hr))
  73.     {
  74.         TraceFnResult(MAPIAdminProfiles, hr);
  75.         goto ret;
  76.     }
  77.  
  78.     (void) ppa->lpVtbl->DeleteProfile(ppa, szProfile, 0);
  79.  
  80.     printf("Creating profile \"%s\"\n", szProfile);
  81.     hr = ppa->lpVtbl->CreateProfile(ppa, szProfile, NULL, 0, 0);
  82.     if (HR_FAILED(hr))
  83.     {
  84.         TraceFnResult(CreateProfile, hr);
  85.         goto ret;
  86.     }
  87.  
  88.     hr = MAPILogonEx(0, szProfile, NULL, MAPI_NO_MAIL | MAPI_NEW_SESSION,
  89.                                &pses);
  90.     if (HR_FAILED(hr))
  91.     {
  92.         TraceFnResult(MAPILogonEx, hr);
  93.         goto ret;
  94.     }
  95.  
  96.     hr = pses->lpVtbl->AdminServices(pses, 0, &psa);
  97.     if (HR_FAILED(hr))
  98.         goto ret;
  99.     
  100.     printf("Creating Sample Message Store\n");
  101.     hr = psa->lpVtbl->CreateMsgService(psa, "SMPMS", "MAPI Sample Msg Store", 0, 0);
  102.     if (HR_FAILED(hr))
  103.     {
  104.         TraceFnResult(CreateMsgService, hr);
  105.         goto ret;
  106.     }
  107.  
  108.     printf("Creating Sample Transport\n");
  109.     hr = psa->lpVtbl->CreateMsgService(psa, "SMPXP", 
  110.                                         "Sample Peer To Peer Transport", 0, 0);
  111.     if (HR_FAILED(hr))
  112.     {
  113.         TraceFnResult(CreateMsgService, hr);
  114.         goto ret;
  115.     }
  116.  
  117.     printf("Creating Sample Address Book\n");
  118.     hr = psa->lpVtbl->CreateMsgService(psa, "SMPAB", 
  119.                                         "Sample Addres Book", 0, 0);
  120.     if (HR_FAILED(hr))
  121.     {
  122.         TraceFnResult(CreateMsgService, hr);
  123.         goto ret;
  124.     }
  125.  
  126.  
  127.     hr = psa->lpVtbl->GetMsgServiceTable(psa, 0, &ptblSvc);
  128.     if (HR_FAILED(hr))
  129.     {
  130.         TraceFnResult(GetMsgServiceTable, hr);
  131.         goto ret;
  132.     }
  133.  
  134.     hr = HrQueryAllRows(ptblSvc, (LPSPropTagArray)&ptaSvc, NULL, NULL, 0, &prows);
  135.     if (HR_FAILED(hr))
  136.     {
  137.         TraceFnResult(HrQueryAllRows, hr);
  138.         goto ret;
  139.     }
  140.  
  141.     Assert(prows->cRows == cProviders);
  142.     
  143.     for(prow = prows->aRow; prow < prows->aRow + cProviders; ++prow)
  144.     {
  145.         Assert(prow->cValues == cptaSvc);
  146.         Assert(prow->lpProps[iSvcName].ulPropTag == PR_SERVICE_NAME);
  147.         Assert(prow->lpProps[iSvcUID].ulPropTag == PR_SERVICE_UID);
  148.         Assert(prow->lpProps[iSvcUID].Value.bin.cb == sizeof(MAPIUID));
  149.  
  150.         if(!lstrcmp(prow->lpProps[iSvcName].Value.lpszA, "SMPMS"))
  151.         {
  152.             printf("Configuring Sample Message Store...");
  153.         
  154.             rgval[0].ulPropTag      = PR_SMS_PATH;
  155.             rgval[0].Value.lpszA    = "d:\\sms";
  156.             
  157.             rgval[1].ulPropTag      = PR_SMS_PASSWORD;
  158.             rgval[1].Value.lpszA    = "PASSWORD";
  159.             
  160.             rgval[2].ulPropTag      = PR_SMS_REMEMBER_PW;
  161.             rgval[2].Value.b        = TRUE;
  162.             
  163.             rgval[3].ulPropTag      = PR_SMS_CREATE;
  164.             rgval[3].Value.b        = TRUE;
  165.             
  166.             hr = psa->lpVtbl->ConfigureMsgService(psa, 
  167.                                 (LPMAPIUID) prow->lpProps[iSvcUID].Value.bin.lpb,
  168.                                             0, 0, 4, rgval);
  169.             if (HR_FAILED(hr))
  170.             {
  171.                 printf("failed\n");
  172.                 TraceFnResult(ConfigureMsgService, hr);
  173.                 //goto ret;
  174.             }
  175.             else
  176.             {
  177.                 printf("OK\n");
  178.             }
  179.         }
  180.         else if(!lstrcmp(prow->lpProps[iSvcName].Value.lpszA, "SMPXP"))
  181.         {
  182.             printf("Configuring Sample Transport...");
  183.         
  184.             rgval[0].ulPropTag  = PR_SAMPLE_DISPLAY_NAME;
  185.             rgval[0].Value.LPSZ = "USER XXX";
  186.             
  187.             rgval[1].ulPropTag  = PR_SAMPLE_EMAIL_ADDR_TYPE;
  188.             rgval[1].Value.LPSZ = "MSPEER";
  189.             
  190.             rgval[2].ulPropTag  = PR_SAMPLE_EMAIL_ADDRESS;
  191.             rgval[2].Value.LPSZ = "\\\\aleksank\\d\\test\\inbound";
  192.             
  193.             rgval[3].ulPropTag  = PR_SAMPLE_INBOUND_DIR;
  194.             rgval[3].Value.LPSZ = "d:\\test\\inbound";
  195.  
  196.             rgval[4].ulPropTag  = PR_SAMPLE_OUTBOUND_DIR;
  197.             rgval[4].Value.LPSZ = "d:\\test\\outbound";
  198.  
  199.             rgval[5].ulPropTag  = PR_SAMPLE_FLAGS;
  200.             rgval[5].Value.l    = 9;
  201.  
  202.             hr = psa->lpVtbl->ConfigureMsgService(psa, 
  203.                                 (LPMAPIUID) prow->lpProps[iSvcUID].Value.bin.lpb,
  204.                                             0, 0, 6, rgval);
  205.             if (HR_FAILED(hr))
  206.             {
  207.                 printf("failed\n");
  208.                 TraceFnResult(ConfigureMsgService, hr);
  209.                 //goto ret;
  210.             }
  211.             else
  212.             {
  213.                 printf("OK\n");
  214.             }
  215.         }
  216.         else if(!lstrcmp(prow->lpProps[iSvcName].Value.lpszA, "SMPAB"))
  217.         {
  218.             printf("Configuring Sample Address Book...");
  219.         
  220.             rgval[0].ulPropTag  = PR_SAB_FILE;
  221.             rgval[0].Value.LPSZ = "d:\\sampab.sab";
  222.             
  223.             hr = psa->lpVtbl->ConfigureMsgService(psa, 
  224.                                 (LPMAPIUID) prow->lpProps[iSvcUID].Value.bin.lpb,
  225.                                             0, 0, 1, rgval);
  226.             if (HR_FAILED(hr))
  227.             {
  228.                 printf("failed\n");
  229.                 TraceFnResult(ConfigureMsgService, hr);
  230.                 //goto ret;
  231.             }
  232.             else
  233.             {
  234.                 printf("OK\n");
  235.             }
  236.         }
  237.         else
  238.         {
  239.             Assert(FALSE);
  240.         }
  241.     }
  242.             
  243. ret:
  244.     
  245.     UlRelease(ptblSvc);
  246.     UlRelease(psa);
  247.     UlRelease(pses);
  248.     UlRelease(ppa);
  249.     FreeProws(prows);
  250.     MAPIUninitialize();
  251.     return hr;
  252. }
  253.  
  254.