Microsoft KB Archive/200180

= How To Remove a Published Form from a Folder Using Visual C++ =

Article ID: 200180

Article Last Modified on 8/25/2005

-

APPLIES TO


 * Microsoft Messaging Application Programming Interface
 * Microsoft Exchange Development Kit 5.5
 * Microsoft Exchange Server 2003 Software Development Kit
 * Microsoft Visual C++ 5.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 5.0 Professional Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition

-



This article was previously published under Q200180



SUMMARY
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.



MORE INFORMATION
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
 * 1) include 

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; }

