HrMAPIOpenFolderEx failed under Outlook 2003

J

Jiang Hong

Hi,

My program works under Outlook 2000/XP, but failed under Outlook 2003. I
found it is HrMAPIOpenFolderEx causes the 'access violation'. Is there
anything special to handle for O2003?

#include <Windows.h>
#include <edk.h>
#include <stdio.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR pszCmd,
int nCmdShow)
{
ULONG cbEIDStore = 0;
LPENTRYID lpEIDStore = NULL;
ULONG cbEIDFolder = 0;
LPENTRYID lpEIDFolder = NULL;
LPMAPISESSION lpSession = NULL;
LPMDB lpStore = NULL;
LPMAPIFOLDER lpFolder = NULL;
LPMAPIFOLDER lpNewFolder = NULL;
LPMAPIFOLDER lpDestFolder = NULL;
HRESULT hr = NULL;
ULONG ulUIParam = 0;
SPropValue spvMsg;
LPCIID lpInterface = NULL;
ULONG ulFlags = MAPI_BEST_ACCESS;
ULONG ulObjType = 0;
hr = MAPIInitialize(NULL);
if (FAILED(hr))
{
MessageBox(NULL,"MAPIInitialize failed",NULL,MB_OK);
return 1;
}
hr = MAPILogonEx(0, NULL, NULL,
MAPI_USE_DEFAULT | MAPI_NEW_SESSION | MAPI_EXTENDED,
&lpSession);
if (FAILED(hr))
{
MessageBox(NULL,"MAPI Logon failed",NULL,MB_OK);
goto cleanup;
}
hr = HrMAPIFindDefaultMsgStore(lpSession, &cbEIDStore, &lpEIDStore);
if (FAILED(hr))
{
MessageBox(NULL,"Message Store Not Found",NULL,MB_OK);
goto cleanup;
}
hr = lpSession->OpenMsgStore(ulUIParam, cbEIDStore,
lpEIDStore, lpInterface,
ulFlags, &lpStore);
if (FAILED(hr))
{
MessageBox(NULL,"Message Store Not Opened",NULL,MB_OK);
goto cleanup;
}
// works till here
hr = HrMAPIOpenFolderEx(lpStore, '\\',
"\\Top of Information Store\\Inbox",
&lpFolder);
// never go here
if (FAILED(hr))
{
MessageBox(NULL,"Folder Not Opened",NULL,MB_OK);
goto cleanup;
}
// Creates new folder under the Inbox.
hr = lpFolder->CreateFolder(FOLDER_GENERIC, "Created Folder",
"Folder Comment", NULL,
OPEN_IF_EXISTS,
&lpNewFolder);
if (FAILED(hr))
{
MessageBox(NULL,"Folder Not Created",NULL,MB_OK);
goto cleanup;
}
// Moves the folder to the main folder tree.
hr = HrMAPIOpenFolderEx(lpStore, '\\',
"\\Top of Information Store",
&lpDestFolder);
if (FAILED(hr))
{
MessageBox(NULL,
"Top of Information Store Not Opened",NULL,MB_OK);
goto cleanup;
}
hr = HrMAPIFindFolderEx(lpStore, '\\',
"\\Top of Information Store\\Inbox\\Created Folder",
&cbEIDFolder,
&lpEIDFolder);
if (FAILED(hr))
{
MessageBox(NULL,"Folder Not Found",NULL,MB_OK);
goto cleanup;
}
hr = lpFolder->CopyFolder( cbEIDFolder, lpEIDFolder, NULL,
lpDestFolder, NULL,
NULL,
NULL,
FOLDER_MOVE | COPY_SUBFOLDERS);
// Finds folder so that it can be opened and renamed.
hr = HrMAPIFindFolderEx(lpStore, '\\',
"\\Top of Information Store\\Created Folder",
&cbEIDFolder, &lpEIDFolder);
if (FAILED(hr))
{
MessageBox(NULL,"Folder Not Found",NULL,MB_OK);
goto cleanup;
}
hr = lpStore->OpenEntry(cbEIDFolder, lpEIDFolder,
NULL, MAPI_BEST_ACCESS,
&ulObjType,
(LPUNKNOWN FAR *)&lpFolder);
if (FAILED(hr))
{
MessageBox(NULL,"Folder Could Not Be Opened",NULL,MB_OK);
goto cleanup;
}
spvMsg.ulPropTag = PR_DISPLAY_NAME;
spvMsg.Value.lpszA = "Renamed Folder";

hr = HrSetOneProp(lpFolder, &spvMsg);

if (FAILED(hr))
{
MessageBox(NULL,"Folder Could Not Be Renamed",NULL,MB_OK);
goto cleanup;
}

cleanup:

if (lpSession)
{
lpSession->Logoff(0, 0, 0);
ULRELEASE(lpSession);
}
MAPIUninitialize();
return 0;
}
 
D

Dmitry Streblechenko

HrMAPIOpenFolderEx source code is in the Platform SDK, see where the error
really happens.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top