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 IV

How to create MS Exchange profiles in MS Outlook with MAPI

Part IV

 

 

This time we’ll look at how to create providers and their properties.

 

Let’s start by searching for a specific property. You may find a provider in the same way as we have done with services. As you are already well prepared for this I won’t give many comments on it.

 

                bool                                        found=false;

                HRESULT                              hr;

                ULONG                                  ulCount = 0,ulPropCnt=0;

                ULONG                                  ulRowCount = 0;

                LPSRowSet                             pRows = NULL,pProvRows=NULL;       // Table

                LPSRow                                  pRow  = NULL;       // 1 row from table

                LPSPropValue                         pProp = NULL,pProps = NULL;  // 1 Prop (column) from row

                LPSERVICEADMIN                               pMsgSvcAdmin = NULL;

                LPMAPITABLE                    pMsgSvcTable = NULL,

                                                               pProviderTable=NULL;

                LPPROVIDERADMIN           pProviderAdmin = NULL;

                LPPROFSECT                        pProfSect=NULL;

                SRestriction                            sres;

                SPropValue                             spv;

SizedSPropTagArray(1, pLogonTags) ={1, {<Property we are looking for>}}; //Offline folder

static SizedSPropTagArray(3, sptProvider) ={3, {  PR_INSTANCE_KEY,

                               PR_DISPLAY_NAME,

                                                                                                              PR_SERVICE_UID}};

                enum {iSvcName, iSvcUID, iSvcEUID, cptaSvc};

                SizedSPropTagArray(cptaSvc, sptCols) =

                {

                               cptaSvc,

                               PR_SERVICE_NAME,

                               PR_SERVICE_UID,

                               PR_SERVICE_EXTRA_UIDS

                };

 

                // Get IMsgServiceAdmin interface.

                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 all of the rows.

                                               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 = szServName; //Service name

                                               hr = HrQueryAllRows(pMsgSvcTable,

                                                               (LPSPropTagArray) &sptCols,

                                                               &sres,

                                                               NULL,

                                                               0,

                                                               &pRows);

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

                                               {

                                                               hr = pMsgSvcAdmin->AdminProviders(

                                                                              (LPMAPIUID)pRows->aRow->lpProps[iSvcUID].Value.bin.lpb,

                                                                              0,

                                                                              &pProviderAdmin);

                                                               if (!FAILED(hr))

                                                               {

                                                                              // Get the provider table where the settings are stored

                                                                              hr= pProviderAdmin -> GetProviderTable(

                                                                                              0,

                                                                                              &pProviderTable);

                                                                              if (!FAILED(hr))

                                                                              {

                                                                                              hr = pProviderTable->SetColumns(

                                                                                                              (LPSPropTagArray)&sptProvider,

                                                                                                              NULL);

                                                                                              if (!FAILED(hr))

                                                                                              {

                                                                                                              // Get count of rows (# of Providers)

                                                                                                              hr = pProviderTable->GetRowCount(

                                                                                                                             NULL,

                                                                                                                             &ulRowCount);

                                                                                                              if (!FAILED(hr))

                                                                                                              {

                                                                                                                             // Get the rows of the Provider Table. 

                                                                                                                             hr = pProviderTable->QueryRows(

                                                                                                                                             ulRowCount,

                                                                                                                                             0,

                                                                                                                                             &pProvRows);       

                                                                                                                             if (!FAILED(hr))

                                                                                                                             {

                                                                                                                             //Makes MAPI think we are a service and not a client.

                                                                                                                             //MAPI grants us Service Access.  This makes it all possible....

                                                                                                                             // Use at your own risk! NOT SUPPORTED!

                                                                                                                                             *(((BYTE*)pProviderAdmin) + 0x60) = 0x2;

                                                                                                                             // Loop through all Providers and look fro Offline Folder property

                                                                                                                                             for (ulCount = 0; ulCount < ulRowCount; ulCount++)

                                                                                                                                             {

                                                                                                                                                             pRow = &pProvRows->aRow[ulCount];

                                                                                                                                                             pProp = &pRow->lpProps[0];

                                                                                                                                                             // Open the profile Section (should it exist)

                                                                                                                                             hr = pProviderAdmin->OpenProfileSection(

                                                                                                                                             (LPMAPIUID)pRow->lpProps[0].Value.bin.lpb,

                                                                                                                                                             NULL,

                                                                                                                                                             NULL,

                                                                                                                                                             &pProfSect);

                                                                                                                                                             if (!FAILED(hr))

                                                                                                                                                             {

                                                                                                                                                                            hr = pProfSect -> GetProps(

                                                                                                                                                                            (LPSPropTagArray)&pLogonTags,

                                                                                                                                                                                            0,

                                                                                                                                                                                            &ulPropCnt,

                                                                                                                                                                                            &pProps);

                                                                                                              if (!FAILED(hr) && pProps->ulPropTag == <Property we are looking for>)

                                                                                                                                                                                            found=true;

                                                                                                                                                             }

                                                                                                                                             }

                                                                                                                             }

                                                                                                              }

                                                                                              }

                                                                              }

                                                               }

                                               }

                               }

                }

 

Ok. As we discussed last time standard providers are created with their services by specifying them in the MAPISVC.inf. In order to create user defined providers fill in an array with providers’ properties and then call CreateProvider().

                SpropValue           propT[2]; //look at the first lesson for the structure of SpropValue

                MAPIUID             m_ServiceUID;

                char                        szSection[] = "Name of a Provider";

propT[k].ulPropTag = PR_PROFILE_TYPE;

                propT[k++].Value.ul = PROFILE_PRIMARY_USER;

                propT[k].ulPropTag = PR_DISPLAY_NAME;

                propT[k++].Value.lpszA = "Name of a Property";

                hr = pProviderAdmin->CreateProvider(

                (LPTSTR)szSection,

                               k,

                               propT,

                               0,

                               0,

                               &m_ServiceUID);

 

            Adding properties to an existing provider is almost the same. Fill in array with properties, find the provider with HrQueryAllRows() and call the SetProps() function.

 

                //Makes MAPI think we are a service and not a client.

                //MAPI grants us Service Access.  This makes it all possible....

// Use at your own risk! NOT SUPPORTED!

                *(((BYTE*)pProviderAdmin) + 0x60) = 0x2;

// Open the profile Section (should it exist) Outlook Address Book

hr = pProviderAdmin->OpenProfileSection(

                               (LPMAPIUID)pRows->aRow->lpProps[0].Value.bin.lpb,  //MAPIUID we’ve got from HrQueryAllRows()

                               NULL,

                               MAPI_MODIFY,

                               &pProfSect);

                if (!FAILED(hr))

                hr = pProfSect -> SetProps(

                                               k,

                                               propT,

                                               NULL);

 

Remember: if you create a Provider, don’t try to find it with HrQueryAllRows(). Release all pointers to the Provider, Service and their tables, then create them again and then search for the Provider.

 

That’s all concerning programming Profiles with MAPI. The rest of the information can be found at the MSDN.

 


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