Microsoft KB Archive/196424

= How To Enumerate the Organizational Forms Library =

Article ID: 196424

Article Last Modified on 8/25/2005

-

APPLIES TO


 * Microsoft Exchange Development Kit 5.5
 * Microsoft Exchange Server 2003 Software Development Kit
 * Microsoft Messaging Application Programming Interface

-



This article was previously published under Q196424



SUMMARY
This article demonstrates how to access the forms data in the Organizational Forms Library of a Microsoft Exchange Server.



MORE INFORMATION
The main puprose of this code is to extract the form data of the Organizational Forms Library into an SRowSet structure. Once the data exists in an SRowSet structure, you can use a for or while loop to iterate through each row and/or each column of each row to extract the data you are interested in.

In order for this code to compile and build successfully, the following libraries must be statically linked: mapi32.lib. #include    #include     #include     #include     #include     #include     #include 

HRESULT GetFormNames {      HRESULT hRes; LPMAPISESSION   lpSession          = 0; LPMAPITABLE     lpMsgStoresTable   = 0; LPMAPITABLE     lpEformRegTable    = 0; SPropValue      RestrictProp       = {0}; SRestriction    Restrict           = {0}; LPSRowSet       lpRows             = NULL; LPMDB           lpPubFolder        = 0; LPSPropValue    lpspvEFormsRegEID  = {0}; char            sPubFold[]         = "Public Folders"; char            sOrgFormLib[]      = "Organization Forms"; ULONG           ulFlags            = 0L; //Initialize MAPI hRes = MAPIInitialize(NULL);

ulFlags = MAPI_NEW_SESSION | MAPI_EXTENDED | MAPI_EXPLICIT_PROFILE | MAPI_LOGON_UI;

//Log on to MAPI hRes = MAPILogonEx(0,                        NULL,                         NULL,                         ulFlags,                         &lpSession);

hRes = lpSession->GetMsgStoresTable( NULL, &lpMsgStoresTable );

//Specify which columns I want to see SizedSPropTagArray(2, Columns) = {         2,  // number of properties {           PR_ENTRYID, PR_DISPLAY_NAME }      };       //Set them up       hRes = lpMsgStoresTable->SetColumns((LPSPropTagArray)&Columns,                                           NULL);

//Limit the view of the table to rows //which have a display name in them RestrictProp.ulPropTag            =  PR_DISPLAY_NAME; RestrictProp.Value.lpszA          =  sPubFold; Restrict.rt                       =  RES_PROPERTY; Restrict.res.resProperty.relop    =  RELOP_EQ; Restrict.res.resProperty.ulPropTag = PR_DISPLAY_NAME; Restrict.res.resProperty.lpProp   =  &RestrictProp;

// Apply the restiction hRes = lpMsgStoresTable->Restrict(&Restrict,TBL_ASYNC); // Set to beginning of table hRes = lpMsgStoresTable->SeekRow(BOOKMARK_BEGINNING,0,NULL); // Get the first row hRes = lpMsgStoresTable->QueryRows(1, 0, &lpRows); //Use the ENTRYID from the row to open the public folder store. hRes = lpSession->OpenMsgStore( NULL,                         lpRows->aRow[0].lpProps->Value.bin.cb,                          (LPENTRYID)lpRows->aRow[0].lpProps->Value.bin.lpb,                         NULL,                         NULL,                         &lpPubFolder); //Use the PubFolder interface to get the Eforms Registry ENTRYID LPSPropValue  lpspvFinderEID = NULL; hRes = HrGetOneProp(lpPubFolder,                          PR_EFORMS_REGISTRY_ENTRYID,                           &lpspvEFormsRegEID);

// Open the EFORMS Registry Folder LPMAPIFOLDER  lpEformsFolder = NULL; ULONG         ulType   = 0;

hRes = lpPubFolder->OpenEntry(lpspvEFormsRegEID->Value.bin.cb,                             (LPENTRYID)lpspvEFormsRegEID->Value.bin.lpb,                              NULL,                              MAPI_BEST_ACCESS,                              &ulType,                              (LPUNKNOWN*)&lpEformsFolder); //Get the folder hierarchy, because we are interested in      //a subfolder hRes = lpEformsFolder->GetHierarchyTable( NULL, &lpEformRegTable ); //Use the same column settings on the hierarchy table hRes = lpEformRegTable->SetColumns((LPSPropTagArray)&Columns,                                          NULL ); //And the same restriction. RestrictProp.ulPropTag            =  PR_DISPLAY_NAME; RestrictProp.Value.lpszA          =  sOrgFormLib; Restrict.rt                       =  RES_PROPERTY; Restrict.res.resProperty.relop    =  RELOP_EQ; Restrict.res.resProperty.ulPropTag = PR_DISPLAY_NAME; Restrict.res.resProperty.lpProp   =  &RestrictProp;

// Apply the restiction hRes = lpEformRegTable->Restrict(&Restrict,TBL_ASYNC);

// Set to beginning of the hierarchy table hRes = lpEformRegTable->SeekRow(BOOKMARK_BEGINNING,0,NULL); // Get the first row hRes = lpEformRegTable->QueryRows(1, 0, &lpRows); //Declare a folder interface variable to accept //the Org Forms pointer LPMAPIFOLDER  lpOrgFormsFolder = NULL; //Open the Org Forms Library hRes = lpEformsFolder->OpenEntry(                   lpRows->aRow[0].lpProps->Value.bin.cb,                    (LPENTRYID)lpRows->aRow[0].lpProps->Value.bin.lpb,                    NULL,                    MAPI_BEST_ACCESS,                    &ulType,                    (LPUNKNOWN*)&lpOrgFormsFolder); //Declare a table interface variable to accept the //Org Forms contents table pointer LPMAPITABLE lpOrgFormsContentsTable = NULL;

//Get the Contents Table hRes = lpOrgFormsFolder->GetContentsTable( MAPI_ASSOCIATED,                                                &lpOrgFormsContentsTable ); //Set the desired columns on the Org Forms Contents Table hRes =lpOrgFormsContentsTable->SetColumns((LPSPropTagArray)&Columns,                                                  NULL ); // Get all of the rows in the contents table hRes = HrQueryAllRows(lpOrgFormsContentsTable,                           (LPSPropTagArray)&Columns,                            NULL,                            NULL,                            0,                            &lpRows);

// TODO: Add code to work with the rows in the contents table to       // suit. // TODO: Add code to free and release all memory allocated by MAPI.

return hRes; }

Additional query words: kbMAPI kbMAPI100 kbMsg kbEDK500 kbEDK550

Keywords: kbhowto kbcode KB196424

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.