Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Outlook and VBA (http://www.outlookbanter.com/outlook-vba/)
-   -   PrepareForm Access Violation (http://www.outlookbanter.com/outlook-vba/77042-prepareform-access-violation.html)

DenisSSSS August 15th 08 02:46 PM

PrepareForm Access Violation
 
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);
}


Dmitry Streblechenko August 15th 08 11:48 PM

PrepareForm Access Violation
 
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
-
"DenisSSSS" wrote in message
...
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);
}





All times are GMT +1. The time now is 04:09 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com