A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

VSTO Outlook 2003 - problem with actions



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old November 4th 06, 06:49 PM posted to microsoft.public.outlook.program_addins
Eddie
external usenet poster
 
Posts: 63
Default VSTO Outlook 2003 - problem with actions

I tried to build sample plugin using VSTO for Outlook 2003.
I ran into few problems. I hope somebody could answer my questions.

Sample code:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
explorer = this.Application.ActiveExplorer();
menu = explorer.CommandBars.ActiveMenuBar;
menuButton =
(Office.CommandBarButton)(menu.Controls.Add(Office .MsoControlType.msoControlButton,
Type.Missing, Type.Missing, menu.Controls.Count, true));
menuButton.Caption = "My menu item";
menuButton.Visible = true;
menuButton.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_Clic kEventHandler(menuButton_Click);

Outlook.NameSpace ns = Application.GetNamespace("MAPI");
contacts =
ns.GetDefaultFolder(Microsoft.Office.Interop.Outlo ok.OlDefaultFolders.olFolderContacts);
contacts.Items.ItemAdd += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemA ddEventHandler(Items_ItemAdd);

if (contacts.Items != null)
{
foreach (Outlook.ContactItem conItem in contacts.Items)
{
Outlook.Action action = conItem.Actions["My action"];
if (action == null)
{
action = conItem.Actions.Add();
action.Enabled = true;
action.Name = "My action";
action.ShowOn =
Microsoft.Office.Interop.Outlook.OlActionShowOn.ol Menu;

conItem.CustomAction += new
Microsoft.Office.Interop.Outlook.ItemEvents_10_Cus tomActionEventHandler(conItem_CustomAction);
conItem.Save();
}
}
}
}

void Items_ItemAdd(object Item)
{
// this isn't called, why?
}

void conItem_CustomAction(object Action, object Response, ref bool Cancel)
{
// this is called only once, why?
// when i use my action twice, another - not my - action is performed,
why?

MyForm form = new MyForm();
form.ShowDialog();
Cancel = true;
}

private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
// should I free my menuButton and my actions here?
}
Ads
  #2  
Old November 4th 06, 09:36 PM posted to microsoft.public.outlook.program_addins
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default VSTO Outlook 2003 - problem with actions

1. Why do you expect Items.ItemAdd event to fire? You are not addng new
items to the Contacts folder.

2. Items collection must be stored in a class member to make sure it is
alive at all times. You do not have even a local variable, only an implicit
one created by the
contacts.Items.ItemAdd += new ...
As soon as GC runs, that implicit variable will be release and you will
never get any events. You need something like

Outlook.Items Items; //must a class member
....
Items = contacts.Items;
Items.ItemAdd += new ...

3. conItem will end up pointing to the last item in the foreach loop.
Similar to #2, you need to store the items that you need to sink events from
in a list to make sure they are alive. You cannot use a single variable,
each item must be stored separately and be alive as long as you trakc the
events. Also note that sinking events from potemtially thousands of items is
a terrible idea.

4. In your CustomAction event handler you never even check *which* custom
action is firing. At the very least, check the Action.Name property to make
sure you get the expected action.

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

"Eddie" wrote in message
...
I tried to build sample plugin using VSTO for Outlook 2003.
I ran into few problems. I hope somebody could answer my questions.

Sample code:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
explorer = this.Application.ActiveExplorer();
menu = explorer.CommandBars.ActiveMenuBar;
menuButton =
(Office.CommandBarButton)(menu.Controls.Add(Office .MsoControlType.msoControlButton,
Type.Missing, Type.Missing, menu.Controls.Count, true));
menuButton.Caption = "My menu item";
menuButton.Visible = true;
menuButton.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_Clic kEventHandler(menuButton_Click);

Outlook.NameSpace ns = Application.GetNamespace("MAPI");
contacts =
ns.GetDefaultFolder(Microsoft.Office.Interop.Outlo ok.OlDefaultFolders.olFolderContacts);
contacts.Items.ItemAdd += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemA ddEventHandler(Items_ItemAdd);

if (contacts.Items != null)
{
foreach (Outlook.ContactItem conItem in contacts.Items)
{
Outlook.Action action = conItem.Actions["My action"];
if (action == null)
{
action = conItem.Actions.Add();
action.Enabled = true;
action.Name = "My action";
action.ShowOn =
Microsoft.Office.Interop.Outlook.OlActionShowOn.ol Menu;

conItem.CustomAction += new
Microsoft.Office.Interop.Outlook.ItemEvents_10_Cus tomActionEventHandler(conItem_CustomAction);
conItem.Save();
}
}
}
}

void Items_ItemAdd(object Item)
{
// this isn't called, why?
}

void conItem_CustomAction(object Action, object Response, ref bool Cancel)
{
// this is called only once, why?
// when i use my action twice, another - not my - action is performed,
why?

MyForm form = new MyForm();
form.ShowDialog();
Cancel = true;
}

private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
// should I free my menuButton and my actions here?
}



  #3  
Old November 5th 06, 10:06 AM posted to microsoft.public.outlook.program_addins
Eddie
external usenet poster
 
Posts: 63
Default VSTO Outlook 2003 - problem with actions

Hi there!

Yes, I'm adding new items at runtime manually. I think there shouldn't be
any problems with it.

I agree with You. Putting all my contacts into some collection object isn't
a good idea. I found some examples which are showing context menu
modification, just before they get fired.

This sample i saw, was made using Application_ItemCOntextMenu. But my
application object don't have this event.

I fought my CustomAction is only fired by action which I created, because my
event handler is added only to it.

I think all my problems are bacause GC, gets my objects.

I will try to fix it using your hints.
Thank you, for your help.

"Dmitry Streblechenko" wrote:

1. Why do you expect Items.ItemAdd event to fire? You are not addng new
items to the Contacts folder.

2. Items collection must be stored in a class member to make sure it is
alive at all times. You do not have even a local variable, only an implicit
one created by the
contacts.Items.ItemAdd += new ...
As soon as GC runs, that implicit variable will be release and you will
never get any events. You need something like

Outlook.Items Items; //must a class member
....
Items = contacts.Items;
Items.ItemAdd += new ...

3. conItem will end up pointing to the last item in the foreach loop.
Similar to #2, you need to store the items that you need to sink events from
in a list to make sure they are alive. You cannot use a single variable,
each item must be stored separately and be alive as long as you trakc the
events. Also note that sinking events from potemtially thousands of items is
a terrible idea.

4. In your CustomAction event handler you never even check *which* custom
action is firing. At the very least, check the Action.Name property to make
sure you get the expected action.

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

"Eddie" wrote in message
...
I tried to build sample plugin using VSTO for Outlook 2003.
I ran into few problems. I hope somebody could answer my questions.

Sample code:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
explorer = this.Application.ActiveExplorer();
menu = explorer.CommandBars.ActiveMenuBar;
menuButton =
(Office.CommandBarButton)(menu.Controls.Add(Office .MsoControlType.msoControlButton,
Type.Missing, Type.Missing, menu.Controls.Count, true));
menuButton.Caption = "My menu item";
menuButton.Visible = true;
menuButton.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_Clic kEventHandler(menuButton_Click);

Outlook.NameSpace ns = Application.GetNamespace("MAPI");
contacts =
ns.GetDefaultFolder(Microsoft.Office.Interop.Outlo ok.OlDefaultFolders.olFolderContacts);
contacts.Items.ItemAdd += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemA ddEventHandler(Items_ItemAdd);

if (contacts.Items != null)
{
foreach (Outlook.ContactItem conItem in contacts.Items)
{
Outlook.Action action = conItem.Actions["My action"];
if (action == null)
{
action = conItem.Actions.Add();
action.Enabled = true;
action.Name = "My action";
action.ShowOn =
Microsoft.Office.Interop.Outlook.OlActionShowOn.ol Menu;

conItem.CustomAction += new
Microsoft.Office.Interop.Outlook.ItemEvents_10_Cus tomActionEventHandler(conItem_CustomAction);
conItem.Save();
}
}
}
}

void Items_ItemAdd(object Item)
{
// this isn't called, why?
}

void conItem_CustomAction(object Action, object Response, ref bool Cancel)
{
// this is called only once, why?
// when i use my action twice, another - not my - action is performed,
why?

MyForm form = new MyForm();
form.ShowDialog();
Cancel = true;
}

private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
// should I free my menuButton and my actions here?
}




  #4  
Old November 5th 06, 10:08 AM posted to microsoft.public.outlook.program_addins
Eddie
external usenet poster
 
Posts: 63
Default VSTO Outlook 2003 - problem with actions

Hi there!

Yes, I'm adding new items at runtime manually. I think there shouldn't be
any problems with it.

I agree with You. Putting all my contacts into some collection object isn't
a good idea. I found some examples which are showing context menu
modification, just before they get fired.

This sample i saw, was made using Application_ItemCOntextMenu. But my
application object don't have this event.

I fought my CustomAction is only fired by action which I created, because my
event handler is added only to it.

I think all my problems are because GC, gets my objects.

I will try to fix it using your hints.
Thank you, for your help.

"Dmitry Streblechenko" wrote:

1. Why do you expect Items.ItemAdd event to fire? You are not addng new
items to the Contacts folder.

2. Items collection must be stored in a class member to make sure it is
alive at all times. You do not have even a local variable, only an implicit
one created by the
contacts.Items.ItemAdd += new ...
As soon as GC runs, that implicit variable will be release and you will
never get any events. You need something like

Outlook.Items Items; //must a class member
....
Items = contacts.Items;
Items.ItemAdd += new ...

3. conItem will end up pointing to the last item in the foreach loop.
Similar to #2, you need to store the items that you need to sink events from
in a list to make sure they are alive. You cannot use a single variable,
each item must be stored separately and be alive as long as you trakc the
events. Also note that sinking events from potemtially thousands of items is
a terrible idea.

4. In your CustomAction event handler you never even check *which* custom
action is firing. At the very least, check the Action.Name property to make
sure you get the expected action.

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

"Eddie" wrote in message
...
I tried to build sample plugin using VSTO for Outlook 2003.
I ran into few problems. I hope somebody could answer my questions.

Sample code:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
explorer = this.Application.ActiveExplorer();
menu = explorer.CommandBars.ActiveMenuBar;
menuButton =
(Office.CommandBarButton)(menu.Controls.Add(Office .MsoControlType.msoControlButton,
Type.Missing, Type.Missing, menu.Controls.Count, true));
menuButton.Caption = "My menu item";
menuButton.Visible = true;
menuButton.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_Clic kEventHandler(menuButton_Click);

Outlook.NameSpace ns = Application.GetNamespace("MAPI");
contacts =
ns.GetDefaultFolder(Microsoft.Office.Interop.Outlo ok.OlDefaultFolders.olFolderContacts);
contacts.Items.ItemAdd += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemA ddEventHandler(Items_ItemAdd);

if (contacts.Items != null)
{
foreach (Outlook.ContactItem conItem in contacts.Items)
{
Outlook.Action action = conItem.Actions["My action"];
if (action == null)
{
action = conItem.Actions.Add();
action.Enabled = true;
action.Name = "My action";
action.ShowOn =
Microsoft.Office.Interop.Outlook.OlActionShowOn.ol Menu;

conItem.CustomAction += new
Microsoft.Office.Interop.Outlook.ItemEvents_10_Cus tomActionEventHandler(conItem_CustomAction);
conItem.Save();
}
}
}
}

void Items_ItemAdd(object Item)
{
// this isn't called, why?
}

void conItem_CustomAction(object Action, object Response, ref bool Cancel)
{
// this is called only once, why?
// when i use my action twice, another - not my - action is performed,
why?

MyForm form = new MyForm();
form.ShowDialog();
Cancel = true;
}

private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
// should I free my menuButton and my actions here?
}




  #5  
Old November 6th 06, 05:00 PM posted to microsoft.public.outlook.program_addins
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default VSTO Outlook 2003 - problem with actions

Context menu events are only exposed in Outlook 2007, not in any previous
version of Outlook.

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

"Eddie" wrote in message
...
Hi there!

Yes, I'm adding new items at runtime manually. I think there shouldn't be
any problems with it.

I agree with You. Putting all my contacts into some collection object
isn't
a good idea. I found some examples which are showing context menu
modification, just before they get fired.

This sample i saw, was made using Application_ItemCOntextMenu. But my
application object don't have this event.

I fought my CustomAction is only fired by action which I created, because
my
event handler is added only to it.

I think all my problems are because GC, gets my objects.

I will try to fix it using your hints.
Thank you, for your help.

"Dmitry Streblechenko" wrote:

1. Why do you expect Items.ItemAdd event to fire? You are not addng new
items to the Contacts folder.

2. Items collection must be stored in a class member to make sure it is
alive at all times. You do not have even a local variable, only an
implicit
one created by the
contacts.Items.ItemAdd += new ...
As soon as GC runs, that implicit variable will be release and you will
never get any events. You need something like

Outlook.Items Items; //must a class member
....
Items = contacts.Items;
Items.ItemAdd += new ...

3. conItem will end up pointing to the last item in the foreach loop.
Similar to #2, you need to store the items that you need to sink events
from
in a list to make sure they are alive. You cannot use a single variable,
each item must be stored separately and be alive as long as you trakc the
events. Also note that sinking events from potemtially thousands of items
is
a terrible idea.

4. In your CustomAction event handler you never even check *which* custom
action is firing. At the very least, check the Action.Name property to
make
sure you get the expected action.

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

"Eddie" wrote in message
...
I tried to build sample plugin using VSTO for Outlook 2003.
I ran into few problems. I hope somebody could answer my questions.

Sample code:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
explorer = this.Application.ActiveExplorer();
menu = explorer.CommandBars.ActiveMenuBar;
menuButton =
(Office.CommandBarButton)(menu.Controls.Add(Office .MsoControlType.msoControlButton,
Type.Missing, Type.Missing, menu.Controls.Count, true));
menuButton.Caption = "My menu item";
menuButton.Visible = true;
menuButton.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_Clic kEventHandler(menuButton_Click);

Outlook.NameSpace ns = Application.GetNamespace("MAPI");
contacts =
ns.GetDefaultFolder(Microsoft.Office.Interop.Outlo ok.OlDefaultFolders.olFolderContacts);
contacts.Items.ItemAdd += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemA ddEventHandler(Items_ItemAdd);

if (contacts.Items != null)
{
foreach (Outlook.ContactItem conItem in contacts.Items)
{
Outlook.Action action = conItem.Actions["My action"];
if (action == null)
{
action = conItem.Actions.Add();
action.Enabled = true;
action.Name = "My action";
action.ShowOn =
Microsoft.Office.Interop.Outlook.OlActionShowOn.ol Menu;

conItem.CustomAction += new
Microsoft.Office.Interop.Outlook.ItemEvents_10_Cus tomActionEventHandler(conItem_CustomAction);
conItem.Save();
}
}
}
}

void Items_ItemAdd(object Item)
{
// this isn't called, why?
}

void conItem_CustomAction(object Action, object Response, ref bool
Cancel)
{
// this is called only once, why?
// when i use my action twice, another - not my - action is
performed,
why?

MyForm form = new MyForm();
form.ShowDialog();
Cancel = true;
}

private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
// should I free my menuButton and my actions here?
}






 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook 2003 and VSTO questions Christie Add-ins for Outlook 0 November 3rd 06 07:19 AM
Launch a Batch Task from Outlook 2003 - Custom Actions ? Steph Outlook and VBA 0 August 22nd 06 06:14 AM
VSTO - Market Share of Outlook 2003 (Pro)? Tadwick Add-ins for Outlook 0 July 30th 06 05:14 AM
VSTO Backwards compatibility with Outlook 2003 / 2007 abcomp Add-ins for Outlook 1 July 19th 06 04:14 PM
VSTO plugin + Distribution List resolution problem.. Sanjay Add-ins for Outlook 6 May 12th 06 06:44 PM


All times are GMT +1. The time now is 03:27 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2024 Outlook Banter.
The comments are property of their posters.