PrepareForm Access Violation

  • Thread starter Thread starter DenisSSSS
  • Start date Start date
D

DenisSSSS

Hello.

We found that PrepareForm generates access violation in Office 2003 SP3.
It will generate access violation if you try to call it from external
process. In our case we have to call PrepareForm from uninstallation. It
requires to republish custom forms.
Everything worked properly till Office 2003 SP3 was released.
Please, see code below that generates access violation if you execute it
from external process(test application in our case).
The same code works properly if you run from COM Add-in.

void external_publish_access_violation()
{
MAPIInitialize(NULL);


Outlook::_ApplicationPtr ol_app =
Outlook::_ApplicationPtr(L"Outlook.Application");
Outlook::MAPIFolderPtr type_root =
ol_app->Session->GetDefaultFolder(Outlook::olFolderTasks);
_variant_t fd_v;
Outlook::FormDescriptionPtr fd;
Outlook::_TaskItemPtr task = ol_app->CreateItem(Outlook::olTaskItem);
fd = task->FormDescription;
_variant_t vt = fd->Name;
fd->Name = str2bstr(L"new_task_item");
fd->PublishForm(Outlook::olPersonalRegistry);

IMAPIFormMgrPtr form_manager;
IMAPIFormInfoPtr fi;

::MAPIOpenFormMgr((IMAPISessionPtr)ol_app->Session->MAPIOBJECT,
&form_manager);

// message class is resolved succesfully
HRESULT hr=
form_manager->ResolveMessageClass("IPM.Task.new_task_item",
MAPIFORM_EXACTMATCH, 0, &fi);

// ACCESS VIOLATION
hr = form_manager->PrepareForm(0, 0, fi);
}
 
In your case IMAPISession gets marshalled form the Outlook.exe process
address space, and MAPI has a few issues with marshalling, forms nad profile
sections among them.
Instead of using Namespace.MAPIOBJECT, call MAPILogonEx.

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