Article ID: 194976 - Last Review: August 25, 2005 - Revision: 2.5
How To Create an Organizational Forms Library Programmatically This article was previously published under Q194976
When deploying forms for Microsoft Exchange in a worldwide organization, it
may be necessary to create several Organizational Forms Libraries in
different languages much like the administrator program does. This is done
using the MAPI function CreateFolder(). However, it is necessary to have
very special privileges to get it to work. These special privileges can
only be obtained by opening the store with an EntryId created using
CreateStoreEntryID().
The sample code in this article does the following:
Opens the message store with a standard pointer.
Makes a call to CreateStoreEntryID() requesting special permissions.
Closes the message store.
Reopens the message store with the special EntryID obtained in #2 above.
Once you have the pointer with the correct permissions, you can use it for
standard calls such as CreateFolder(), SetProps(), and SaveChanges().
The additional libraries required to compile and link this Win32
application sample are as follows:
msvcrt.lib edkguid.lib addrlkup.lib version.lib edkutils.lib edkdebug.lib edkmapi.lib mapi32.lib ACLCLS.LIB
You will need to modify the code marked by "TO DO" to reference the
appropriate Exchange Organization, Site and Server Name. You will also need
to be logged into the Windows NT machine under a domain account that has
permissions on the Exchange Server's Organization, Site and Configuration
objects:
#include <edk.h>
LPMAPISESSION lpMapiSession = NULL;
LPMDB lpPubStore = NULL;
LPMAPIFOLDER lpPublicFolder1 = NULL,
lpFormFolder = NULL;
LPMAPITABLE lpContentTable = NULL;
LPSRowSet lpRows = NULL;
ULONG rCount = 0, i = 0;
HRESULT hr;
MAPIINIT_0 MapiInit;
char lngName[100];
static SizedSPropTagArray( 2L, PropFolderName) =
{ 2L, {PR_DISPLAY_NAME,0x3fe90003}};
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE,
LPSTR pszCmd, int nCmdShow)
{
MapiInit.ulVersion = 0;
MapiInit.ulFlags = MAPI_NT_SERVICE;
hr = MAPIInitialize( &MapiInit);
if (!HR_SUCCEEDED(hr))
{
MessageBox(0l,"MAPIInitialize error","Error",MB_OK);
return -1;
}
hr = MAPILogonEx( 0, (LPTSTR)NULL, (LPTSTR)"",
MAPI_NEW_SESSION | MAPI_EXTENDED | MAPI_LOGON_UI,
&lpMapiSession);
if (!HR_SUCCEEDED(hr))
{
MessageBox(0l,"MAPILogonEx error","Error",MB_OK);
return -1;
}
hr = HrOpenExchangePublicStore( lpMapiSession, &lpPubStore);
if (!HR_SUCCEEDED(hr))
{
MessageBox(0l,"HrOpenExchangePublicStore error","Error",MB_OK);
return -1;
}
LPEXCHANGEMANAGESTORE pManageStore = NULL;
ULONG cbeid;
LPENTRYID lpeid = NULL;
char szServerDN[500];
ULONG ulFlags;
ulFlags = LOGOFF_PURGE;
hr = lpPubStore->QueryInterface(IID_IExchangeManageStore,
(LPVOID *) &pManageStore);
if (hr != SUCCESS_SUCCESS)
{
lpPubStore->StoreLogoff(&ulFlags);
MessageBox(0,"QueryInterface error","Error",MB_OK);
return -1;
}
// TO DO: Create Server DN
sprintf(szServerDN, "/o=%s", "MyOrganization");
sprintf(szServerDN, "%s/ou=%s",szServerDN, "MySite");
sprintf(szServerDN, "%s/cn=Configuration/cn=Servers/cn=%s",
szServerDN, "MyServer");
sprintf(szServerDN, "%s/cn=Microsoft Public MDB",szServerDN);
if (FAILED(hr = pManageStore->CreateStoreEntryID(szServerDN, NULL,
OPENSTORE_USE_ADMIN_PRIVILEGE | OPENSTORE_PUBLIC |
OPENSTORE_TAKE_OWNERSHIP | OPENSTORE_HOME_LOGON,
&cbeid, &lpeid)))
{
MessageBox(0l,"CreateStoreEntyrID error","Error",MB_OK);
return - 1;
}
ulFlags = LOGOFF_PURGE;
hr = lpPubStore->StoreLogoff(&ulFlags);
if (hr != SUCCESS_SUCCESS)
{
MessageBox(0l,"StoreLogoff error","Error",MB_OK);
return -1;
}
if (FAILED(hr = lpMapiSession->OpenMsgStore(0L, cbeid, lpeid,
NULL, MAPI_DEFERRED_ERRORS | MDB_WRITE,
&lpPubStore)))
{
MessageBox(0l,"OpenMsgStore error","Error",MB_OK);
return -1;
}
// Property value: "Registries" subtree EID
SPropValue *pvalFR_EID = NULL;
ULONG ul;
SPropTagArray tagaFR_EID = { 1,
{ PR_EFORMS_REGISTRY_ENTRYID } };
hr = lpPubStore -> GetProps (&tagaFR_EID, fMapiUnicode,
&ul, &pvalFR_EID);
if (! HR_SUCCEEDED (hr))
{
printf("GetProps error \n");
return -1;
}
// Open the Registries subtree. The registry folder should be
// created under this subtree.
hr = lpPubStore -> OpenEntry (pvalFR_EID -> Value.bin.cb,
(LPENTRYID) pvalFR_EID -> Value.bin.lpb,
NULL, MAPI_MODIFY, & ul,
(LPUNKNOWN *) & lpPublicFolder1);
if (! HR_SUCCEEDED (hr))
{
printf("OpenEntry error \n");
return -1;
}
hr = lpPublicFolder1->CreateFolder(FOLDER_GENERIC,
"TestFormLibrary", NULL, NULL,
OPEN_IF_EXISTS | MAPI_DEFERRED_ERRORS,
&lpFormFolder);
if (!HR_SUCCEEDED(hr))
{
MessageBox(0l,"CreateFolder error","Error",MB_OK);
return -1;
}
SPropValue lpPropValueArray2[3];
lpPropValueArray2[0].ulPropTag = PR_EFORMS_LOCALE_ID;
lpPropValueArray2[0].Value.ul =
MAKELCID (MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_EIRE),
SORT_DEFAULT);
lpPropValueArray2[1].ulPropTag = PR_DISPLAY_NAME;
lpPropValueArray2[1].Value.LPSZ = "Forms Library (English-Irish)";
lpPropValueArray2[2].ulPropTag = PR_PUBLISH_IN_ADDRESS_BOOK;
lpPropValueArray2[2].Value.b = FALSE;
if (FAILED(hr = lpFormFolder->SetProps(3,lpPropValueArray2,NULL)))
{
MessageBox(0l,"Setprops error","Error",MB_OK);
return -1;
}
if (FAILED(hr = lpFormFolder->SaveChanges(KEEP_OPEN_READWRITE)))
{
MessageBox(0l,"SaveChanges error","Error",MB_OK);
return -1;
}
if (lpMapiSession)
{
lpMapiSession->Logoff(0, 0, 0);
ULRELEASE(lpMapiSession);
}
MAPIUninitialize();
return 0 ;
}
APPLIES TO Microsoft Office Outlook 2007 Microsoft Messaging Application Programming Interface Microsoft Exchange Server 2003 Software Development Kit Microsoft Exchange Development Kit 5.5
Provide feedback on this information
Did this information solve your problem?
Was this information relevant?
What can we do to improve this information?
To protect your privacy, do not include contact information in your feedback.
Thank you! Your feedback is used to help us improve our support content. For more assistance options, please visit the
Help and Support Home Page .