Become a Columnist Microsoft Exchange Site Microsoft Support SiteMSDN Exchange Site

       How did you like this article? Please vote and let us know.          

Subscribe to OutlookExchange
Anderson Patricio
Ann Mc Donough
Bob Spurzem
Brian Veal
Catherine Creary
Cherry Beado
Colin Janssen
Collins Timothy Mutesaria
Drew Nicholson
Fred Volking
Glen Scales
Goran Husman
Guy Thomas
Henrik Walther
Jason Sherry
Jayme Bowers
John Young
Joyce Tang
Justin Braun
Konstantin Zheludev
Kristina Waters
Kuang Zhang
Mahmoud Magdy
Martin Tuip
Michael Dong
Michele Deo
Mitch Tulloch
Nicolas Blank
Pavel Nagaev
Ragnar Harper
Ricardo Silva
Richard Wakeman
Russ Iuliano
Santhosh Hanumanthappa
Shannal L. Thomas
Steve Bryant
Steve Craig
Todd Walker
Tracey J. Rosenblath

 

 
  How to create MS Exchange profiles in MS Outlook with MAPI

How to create MS Exchange profiles in MS Outlook with MAPI

Part III

This time we’ll learn how to create, delete, find standard and user defined Services.

 

Creating a Service that is described in MAPISVC.inf is very easy:

char *pszProfileName; //Name of profile

char *pszMsgService; //Name of Service

LPSERVICEADMIN pMsgSvcAdmin = NULL;

LPPROFADMIN       pProfAdmin = NULL;

// Initialize MAPI.

hr = MAPIInitialize(NULL);

if (!FAILED(hr))

{

                //get IProfAdmin interface

                hr = MAPIAdminProfiles(0, &pProfAdmin);

                if (!FAILED(hr))

{

                                               // Get IMsgServiceAdmin interface.

                                               hr = pProfAdmin->AdminServices(

                                                               pszProfileName,

                                                               NULL,

                                                               NULL,

                                                               0,

                                                               &pMsgSvcAdmin);

if(!FAILED(hr))

{

                                                               // Add messaging service to the profile.

hr = pMsgSvcAdmin->CreateMsgService(pszMsgService,

NULL,

NULL,

NULL);

}

}

}

 

Where pszMsgService is the name of a Service, something like “MSEMS” (Microsoft Exchange Server). Now find the MAPISVC.inf file. You probably have two of them, but the right one that is used by MAPI is stored at C:\Program Files\Common Files\System\Mapi\1049\... The complete path depends on MS Outlook version you use. Open the file and under [Services] section you’ll see the list of Services MAPI can create with just a name. While creating the Service, MAPI will add all the parameters described at MAPISVC.inf for the Service.

Ok. But you may want to create your own Service. You’ll have to add it to the MAPISVC.inf file. Use any standard Service as an example. After creating it you’ll be able to add Providers to any Service.

 

Now let’s see how to find a Service in our Profile.

                SizedSPropTagArray(1, Columns) ={2, {PR_DISPLAY_NAME, PR_SERVICE_UID}};    

hr = pProfAdmin->AdminServices(

                               pszProfileName,

                               NULL,

                               NULL,

                               0,

                               &pMsgSvcAdmin);

                if (!FAILED(hr))

                {

                                // Get the message service table

                               hr = pMsgSvcAdmin->GetMsgServiceTable(

                                               0,

                                               &pMsgSvcTable);

                               if (!FAILED(hr))

                               {

                                               // Get the row from the message service table that represents Service.

                                               sres.rt = RES_CONTENT;

                                               sres.res.resContent.ulFuzzyLevel = FL_FULLSTRING;

                                               sres.res.resContent.ulPropTag = PR_SERVICE_NAME;

                                               sres.res.resContent.lpProp = &spv;

                                               spv.ulPropTag = PR_SERVICE_NAME;

                                               spv.Value.lpszA = pszMsgService;

                                               hr = HrQueryAllRows(pMsgSvcTable,

                                                               (LPSPropTagArray) &Columns,

                                                               &sres,

                                                               NULL,

                                                               0,

                                                               &pRows);

                                               if (!FAILED(hr) && pRows->cRows>0)

                                               {

                                                               found=true;

                                                               cout<<"Found!"<<endl;

                                               }

                               }

                }

PR_SERVICE_NAME has the name of a Service from MAPISVC.inf file (e.g. “MSEMS”) and PR_DISPLAY_NAME will have value from MAPISVC.inf corresponding to Service Name (e.g. MSEMS=Microsoft Exchange Server). We made something like this in the first lesson when we were looking for a Profile. You may also find a detailed description of the restrictions there.

 

Deleting a Service is not too complicated.

hr=pMsgSvcAdmin->DeleteMsgService((LPMAPIUID) pPropUID->Value.bin.lpb);

Where pPropUID->Value.bin.lpb is a unique identifier for the Service we want to delete and we got it from pRows structure when service was found:

                pRow = &pRows->aRow[ulCount];

                pProp = &pRow->lpProps[0];

                pPropUID=&pRow->lpProps[iSvcUID];

Where

                LPSRow                pRow  = NULL;

                LPSPropValue      pProp = NULL, pPropUID=NULL;

                ULONG                 ulCount;

                int                           iSvcUID;

ulCount is equal to 1 in our case as we found just one Service. Using different restrictions you may get a list of Services. iSvcUID is equal to 2 because second column we have above is PR_SERVICE_UID. That’s why we added it to the Columns array, to be able to work with found Service later.

 

That’s all for now. Next time we’ll learn how to work with Providers.

 

 

 


Disclaimer: Your use of the information contained in these pages is at your sole risk. All information on these pages is provided "as is", without any warranty, whether express or implied, of its accuracy, completeness, fitness for a particular purpose, title or non-infringement, and none of the third-party products or information mentioned in the work are authored, recommended, supported or guaranteed by Pro Exchange. OutlookExchange.Com and Pro Exchange shall not be liable for any damages you may sustain by using this information, whether direct, indirect, special, incidental or consequential, even if it has been advised of the possibility of such damages.

© Copyright Pro Exchange, Inc., 2006