CREATEPR.C
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:7k
源码类别:

Windows编程

开发平台:

Visual C++

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