Article ID: 194976
Article Last Modified on 8/25/2005
#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 ;
}
Keywords: kbhowto kbmsg KB194976