Opening WinForm in Outlook 2003 VSTO Addin with Wordmail enabled

Not open for further replies.


I have been banging my head with this issues for sometime now. Can someone

PLEASE help??? When I create a commandbar on a new inspector window that uses

word mail, the form that opens doesn't fully load. I have done a lot of

research on this and I believe it is a threading issue because I create my

command bar in word which is subclassed into Outlook. When wordmail isn't

enabled the apartment state of the executing thread is STA and when wordmail

is enabled it is MTA. I have tried to use a delegate to instantiate the form

instead with no success. Below are a couple of relevant posts I have found.

mentions in one of these that he used several API calls to make

this work. Can someone please provide a working sample. If you need a sample

to reproduce I can provide one. I used the code sample to load wordmail

toolbars on the inspector_activate event. I added another windows project and

then tried to instantiate the form from my class. It never fully loads. Below

are some links I have found helpful.
Andrew's post is more relevant to what you're talking about in cases of

managed code, what I was posting about relates mostly to working with VB6


For managed code you have to do thread context synchronization callbacks.

What you do is on NewExplorer() and NewInspector() event handlers you call

Windows.Forms.Application.DoEvents() to prime the message pump and then you

get the current thread context, which in that case is the context of the

main Outlook addin thread. You store that context so it's always available.

Then when you want to open a form you set up a callback to a procedure that

will run in the main thread context and pass your form name along to that


// In a class context where it will stay alive:

private static System.Threading.SynchronizationContext _syncContext = null;

In the main thread event handlers code something like this:

if (_syncContext == null)



if (System.Threading.SynchronizationContext.Current != null)


_syncContext = System.Threading.SynchronizationContext.Current;



Then when you want to show the form:

// whatever arguments you want to pass to the callback are added here

object[] args = { };

System.Threading.SendOrPostCallback callback =



if (callback != null)


System.Threading.SynchronizationContext context = Globals.SyncContext;

if (context != null)


context.Send(callback, args);


In this case Globals.SyncContext accesses the stored context.

callbackClass is where the callback function lives and it's named

callbackProcedure. That procedure is what displays the form and populates

any controls from the arguments passed to it. In that callback the argumens

are passed as (Object state) and are decoded there as follows:

object[] arguments = (object[])state;

Then that array has all the arguments passed to the callback.

Note that this is not necessary for Outlook 2007, only for WordMail in

earlier versions of Outlook.
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
A Opening a link from an email automatically Outlook VBA and Custom Forms 0
A Opening a link from a specific sender automatically Outlook VBA and Custom Forms 4
L Opening People Outlook 2021 Using Outlook 2
U When opening shared Calendar "The set of folders cannot be opened" Using Outlook 0
KurtLass Opening Graphics Attachments in Outlook 2021 Using Outlook 0
Witzker Place cursor at opening, a user defined OL contact form Outlook VBA and Custom Forms 3
A OutLook For Mac 16.46 Comes Up In Small Window When Opening Using Outlook 4
U Disable "Always ask before opening" Dialog Using Outlook 3
Wayne Outlook locks up when opening "Manage Rules & Alerts" Using Outlook 7
B Outlook 2010 Opening Mail Attachment Using Outlook 2
A Warning When Opening attachment Using Outlook 7
D Prevent popup of "Do you want to save changes?" when closing after opening an appointment to view Outlook VBA and Custom Forms 2
H Upon opening Outlook, make my popmail inbox open instead of inbox Using Outlook 1
J Outlook 2010 Changing events in Outlook calendar via opening file, importing CSV Using Outlook 0
L What are the risks of opening an Outlook 2016 .pst file in Outlook 2010? Using Outlook 4
D Outlook 2007 crashes when opening an email Using Outlook 2
A Outlook 2016- unable to have all subfolders expanded when opening outlook Using Outlook 11
GregS Immediate crash on opening Using Outlook 3
Diane Poremsky Error Opening Outlook and Control Panel's Mail Applet Using Outlook 0
S my vbscript button1_click code works on appointment created but not on opening an existing apntmn Outlook VBA and Custom Forms 16
J Opening Attachments - in People Using Outlook 2
Mistyfied Outlook 2016 not opening Using Outlook 2
M Update field codes when opening Outlook Template Outlook VBA and Custom Forms 2
R Outlook PST not opening Using Outlook 1
U .pst file error at opening outlook Using Outlook 1
A Problems Opening Excel from Outlook Outlook VBA and Custom Forms 3
Diane Poremsky Disable the Unsafe Hyperlink Warning when Opening Attachments Using Outlook 0
S macro for opening attachments and printing Using Outlook 1
Z how to make OL (2007) to use custom contact form when importing / opening .VCF? Using Outlook 1
T Opening email causes "Contacting ..." message Using Outlook 1
K Outlook 2013 stuck "processing" when opening. Using Outlook 3
S Opening Outlook Windows Using Outlook 1
S PoP up reminder while opening the outlook? Outlook VBA and Custom Forms 1
J Opening/Archiving/Import/Export PST files Using Outlook 4
Y (Shared Folder) Using the preview pane to open and close a fax, without opening the email itself Using Outlook 1
E OL2007 on Exchange: opening OL on different computers Using Outlook 1
Z outlook 2007 - opening a contact from the search results doesn't use the custom form Using Outlook 10
T Error opening mail with pictures - "The linked image cannot be displayed" Using Outlook 3
P I'm getting an error when opening Outlook "Mobile me stopped working Using Outlook 1
D opening Word Document in a business contact? BCM (Business Contact Manager) 3
B Contact changes from Personal to Shared when opening custom form Using Outlook 0
C How to stop iCloud calendars opening by default Using Outlook 8
U outlook 2010 freezes/crashes when opening encrypted e-mails Using Outlook 0
G OLMAPI32.dII error prevents Outlook 2010 from opening Using Outlook 2
D Custom Tool Bar and/or Commands do not remain when re-opening Outlook 2007 Using Outlook 3
G opening Outlook again after closing closing? Using Outlook 0
B Outlook 2010: how to mark messages without opening? Eg for deletion Using Outlook 2
M I cannot start Microsoft Outlook 2013 directly opening a .eml message Using Outlook 1
M Opening Word Doc's in Adobe Acrobat Pro Using Outlook 9
L Opening up Contact from an Email - Outlook 2007 Using Outlook 15

Similar threads