HOWTO: Remove a Published Form from a Folder Using Visual C++ID: Q200180
|
Forms that have been added to folders that are no longer being used may need to be removed from the folder. Since form descriptions are messages of type "IPM.Microsoft.FolderDesign.FormsDescription," this can be done using the DeleteMessages() function. The following Microsoft Visual C++ code demonstrates how to remove a published form from the Inbox.
This code should be compiled as a Windows application using the "Ignore all default libraries option" and linked with the listed libraries.
//Link with: kernel32.lib user32.lib advapi32.lib msvcrt.lib edkdebug.lib mapi32.lib version.lib edkmapi.lib edkutils.lib addrlkup.lib rulecls.lib edkguid.lib
#include <edk.h>
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE,
LPSTR pszCmd, int nCmdShow)
{
LPMAPISESSION lpSession = NULL;
LPMDB lpStore = NULL;
LPMAPIFOLDER lpFolder = NULL;
ULONG cbEIDFolder = 0;
LPENTRYID lpEIDFolder = NULL;
HRESULT hr = NULL;
LPMAPITABLE lpTable = NULL;
CHAR szFolder[MAX_PATH + 1] = {0};
ULONG ulUIParam = 0;
LPCIID lpInterface = NULL;
ULONG ulFlags = MAPI_BEST_ACCESS;
LPSRestriction lpRes = NULL;
ULONG lpulCount = NULL;
LPSRowSet lpRows = NULL;
LPMAPIPROP lpMAPIProp = NULL;
ENTRYLIST eidMsg;
char szDisplayName[50];
char szMess[100];
SizedSPropTagArray(2, Columns) =
{
2, // number of properties
{
PR_ENTRYID,
PR_DISPLAY_NAME
}
};
// TO DO: Change Form Name
sprintf(szDisplayName,"FormName");
hr = MAPIInitialize(NULL);
if (FAILED(hr))
{
return 1;
}
hr = MAPILogonEx(0, "", NULL,
MAPI_LOGON_UI | MAPI_NEW_SESSION | MAPI_EXPLICIT_PROFILE ,
&lpSession);
if (FAILED(hr))
{
MessageBox(NULL,"MAPI Logon failed",NULL,MB_OK);
goto cleanup;
}
hr = HrOpenExchangePrivateStore(lpSession,&lpStore);
if (FAILED(hr))
{
MessageBox(NULL,"Message Store Not Opened",NULL,MB_OK);
goto cleanup;
}
strcpy(szFolder, "Top of Information Store\\Inbox");
hr = HrMAPIFindFolderEx(lpStore,
'\\',
szFolder,
&cbEIDFolder,
&lpEIDFolder);
if (FAILED(hr))
{
MessageBox(NULL,"Inbox Not Found",NULL,MB_OK);
goto cleanup;
}
hr = HrMAPIOpenFolderEx (lpStore,'\\',szFolder,&lpFolder);
if (FAILED(hr))
{
MessageBox(NULL,"Inbox Could Not Be Opened",NULL,MB_OK);
goto cleanup;
}
if (FAILED(hr = lpFolder->GetContentsTable(MAPI_ASSOCIATED,&lpTable)))
{
MessageBox(NULL,"GetContentsTable Failed",NULL,MB_OK);
goto cleanup;
}
if (FAILED(hr = lpTable->SetColumns( (LPSPropTagArray)&Columns,NULL )))
{
MessageBox(NULL,"SetColumns Failed",NULL,MB_OK);
goto cleanup;
}
if (FAILED(hr = HrStringToRestriction(
"PR_MESSAGE_CLASS = \"IPM.Microsoft.FolderDesign.FormsDescription\"",
NULL,&lpRes)))
{
MessageBox(NULL,"HrStringToRestriction Failed",NULL,MB_OK);
goto cleanup;
}
if (FAILED(hr = lpTable->Restrict(lpRes,0L)))
{
MessageBox(NULL,"Restrict Failed",NULL,MB_OK);
goto cleanup;
}
if (FAILED(hr = lpTable->GetRowCount(0,&lpulCount)))
{
MessageBox(NULL,"GetRowCount Failed",NULL,MB_OK);
goto cleanup;
}
if (lpulCount > 0)
{
if (FAILED(hr = lpTable->QueryRows(lpulCount,TBL_NOADVANCE,
&lpRows)))
{
MessageBox(NULL,"QueryRows Failed",NULL,MB_OK);
goto cleanup;
}
for (ULONG i=0; i < lpulCount; i++)
{
if (0 == strcmp(szDisplayName,lpRows->aRow[i].lpProps[1].Value.lpszA))
{
eidMsg.cValues = 1;
eidMsg.lpbin = &lpRows->aRow[i].lpProps[0].Value.bin;
if (FAILED(hr = lpFolder->DeleteMessages(&eidMsg, 0L, NULL,
MESSAGE_DIALOG)))
{
sprintf(szMess, "DeleteMessages Failed error %x",hr);
MessageBox(0L,szMess,"Error",MB_OK);
goto cleanup;
}
else
{
sprintf(szMess, "DeleteMessages Completed with hr = %x",hr);
MessageBox(0L,szMess,"Information",MB_OK);
}
}
}
}
else
{
sprintf(szMess, "No forms Found");
MessageBox(0L,szMess,"Error",MB_OK);
}
cleanup:
if (lpFolder)
{
lpFolder->Release();
lpFolder = NULL;
}
if (lpTable)
{
lpTable->Release();
lpTable = NULL;
}
if (lpStore)
{
lpStore->Release();
lpStore = NULL;
}
if (lpRows)
FREEPROWS(lpRows);
if (lpSession)
{
lpSession->Logoff(0, 0, 0);
ULRELEASE(lpSession);
}
MAPIUninitialize();
return 0;
}
For information on how to achieve the same functionality using Collaboration Data Objects (CDO) Library, please see the following article in the Microsoft Knowledge Base:
Q200176 HOWTO: Remove Published Forms from a Folder Using CDO
Additional query words: kbMapi kbMsg kbEDK kbVC600
Keywords : kbMAPI kbMsg kbVC500 kbVC600 kbEDK500 kbEDK550 kbMAPI100
Version : WINDOWS:1.0,5.0,5.5; winnt:5.0,6.0
Platform : WINDOWS winnt
Issue type : kbhowto
Last Reviewed: April 7, 1999