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

Reference to AddIn



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 9th 09, 03:50 PM posted to microsoft.public.outlook.program_addins
Nenad
external usenet poster
 
Posts: 11
Default Reference to AddIn

I am programming Outlook 2003 AddIn using Visual Studio 2008 and C#.

I need to pass a reference to AddIn to user control embedded in Folder Home
Page, but it is always a null. I already found out that it's a security
barrier which prevents passing a reference.

Did anyone knows any other way to pass a reference to C# AddIn?

Thanks, Nenad
  #2  
Old January 9th 09, 10:02 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Reference to AddIn

You need to make the addin COM visible and then depending on whether or not
it's a VSTO addin make public a reference to the addin if you want to call
on methods or properties of the addin.

I don't have anything for VS 2008, but I do have C# templates for VS 2005
for both shared addins and VSTO 2005SE addins that shows how to expose your
addin and methods/properties in it to outside code. You can find them at
http://www.slovaktech.com/outlook_2007_templates.htm. The templates are all
Outlook 2007 specific.

To just reference the addin as an Office.COMAddIn you would use code
something like this assuming olApp is your Outlook.Application object
reference:

Office.COMAddIn addin = olApp.COMAddIns.Item("MyAddinName");

If your addin is shared and uses a Connect class that would look like this:
"MyAddinName.Connect".

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Nenad" wrote in message
...
I am programming Outlook 2003 AddIn using Visual Studio 2008 and C#.

I need to pass a reference to AddIn to user control embedded in Folder
Home
Page, but it is always a null. I already found out that it's a security
barrier which prevents passing a reference.

Did anyone knows any other way to pass a reference to C# AddIn?

Thanks, Nenad


  #3  
Old January 12th 09, 02:14 PM posted to microsoft.public.outlook.program_addins
Nenad
external usenet poster
 
Posts: 11
Default Reference to AddIn

I can get a reference to Office.COMAddIn, but what I really need is a
reference to TheAddIn (which is a subclass of a Microsoft.Office.Tools.AddIn
class and is inherited from
Microsoft.VisualStudio.Tools.Applications.Runtime. IStartup interface).

This is code from Initialize(Outlook.Application app) method from user
control hosted in FHP:

object name = "MyAddIn";
Office.COMAddIn addin = (Office.COMAddIn)app.COMAddIns.Item(ref
name);
ThisAddIn add = addin.Object as AddIn.ThisAddIn;

I was hoping that I will get a reference to VSTO AddIn using addin.Object
property, but it is always null. I also tried to set that property in the
start-up event of the add-in, but it caused TypeMismatch error, so I assume
that it is a misleading.

Anyway, I have set [ComVisible(true)] attribute on the add-in, but it didn't
helped.

Thanks for templates, they are great, but I didn't find what I needed there.

Thanks

"Ken Slovak - [MVP - Outlook]" wrote:

You need to make the addin COM visible and then depending on whether or not
it's a VSTO addin make public a reference to the addin if you want to call
on methods or properties of the addin.

I don't have anything for VS 2008, but I do have C# templates for VS 2005
for both shared addins and VSTO 2005SE addins that shows how to expose your
addin and methods/properties in it to outside code. You can find them at
http://www.slovaktech.com/outlook_2007_templates.htm. The templates are all
Outlook 2007 specific.

To just reference the addin as an Office.COMAddIn you would use code
something like this assuming olApp is your Outlook.Application object
reference:

Office.COMAddIn addin = olApp.COMAddIns.Item("MyAddinName");

If your addin is shared and uses a Connect class that would look like this:
"MyAddinName.Connect".

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Nenad" wrote in message
...
I am programming Outlook 2003 AddIn using Visual Studio 2008 and C#.

I need to pass a reference to AddIn to user control embedded in Folder
Home
Page, but it is always a null. I already found out that it's a security
barrier which prevents passing a reference.

Did anyone knows any other way to pass a reference to C# AddIn?

Thanks, Nenad



  #4  
Old January 12th 09, 03:39 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Reference to AddIn

You didn't look closely enough at the templates. Look at the code at the end
of the ThisAddin class in the section starting with this line:

public static AutomationObject AddinObject = null

That code and what follows in the override and interfaces, along with the
AutomationObject class are what you need. That will expose the addin and
from there the code in the CalledFromOutside method shows how to expose
properties to the outside. You can modify that to call methods in your addin
code also.

To call from outside you'd use something like this (VBA code):

Dim oAddin As Office.COMAddIn

Set oAddin = Application.COMAddIns.Item("MyVSTOAddIn") ' the addin name
here
If Not (oAddin Is Nothing)
oAddin.Object.CalledFromOutside
End If

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Nenad" wrote in message
...
I can get a reference to Office.COMAddIn, but what I really need is a
reference to TheAddIn (which is a subclass of a
Microsoft.Office.Tools.AddIn
class and is inherited from
Microsoft.VisualStudio.Tools.Applications.Runtime. IStartup interface).

This is code from Initialize(Outlook.Application app) method from user
control hosted in FHP:

object name = "MyAddIn";
Office.COMAddIn addin = (Office.COMAddIn)app.COMAddIns.Item(ref
name);
ThisAddIn add = addin.Object as AddIn.ThisAddIn;

I was hoping that I will get a reference to VSTO AddIn using addin.Object
property, but it is always null. I also tried to set that property in the
start-up event of the add-in, but it caused TypeMismatch error, so I
assume
that it is a misleading.

Anyway, I have set [ComVisible(true)] attribute on the add-in, but it
didn't
helped.

Thanks for templates, they are great, but I didn't find what I needed
there.

Thanks


  #5  
Old January 12th 09, 04:54 PM posted to microsoft.public.outlook.program_addins
Nenad
external usenet poster
 
Posts: 11
Default Reference to AddIn

Thanks, that is exactly what I have asked for.

One final question: As I can see, using this technique, only static methods
and properties can be invoked on add-in class?

"Ken Slovak - [MVP - Outlook]" wrote:

You didn't look closely enough at the templates. Look at the code at the end
of the ThisAddin class in the section starting with this line:

public static AutomationObject AddinObject = null

That code and what follows in the override and interfaces, along with the
AutomationObject class are what you need. That will expose the addin and
from there the code in the CalledFromOutside method shows how to expose
properties to the outside. You can modify that to call methods in your addin
code also.

To call from outside you'd use something like this (VBA code):

Dim oAddin As Office.COMAddIn

Set oAddin = Application.COMAddIns.Item("MyVSTOAddIn") ' the addin name
here
If Not (oAddin Is Nothing)
oAddin.Object.CalledFromOutside
End If

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Nenad" wrote in message
...
I can get a reference to Office.COMAddIn, but what I really need is a
reference to TheAddIn (which is a subclass of a
Microsoft.Office.Tools.AddIn
class and is inherited from
Microsoft.VisualStudio.Tools.Applications.Runtime. IStartup interface).

This is code from Initialize(Outlook.Application app) method from user
control hosted in FHP:

object name = "MyAddIn";
Office.COMAddIn addin = (Office.COMAddIn)app.COMAddIns.Item(ref
name);
ThisAddIn add = addin.Object as AddIn.ThisAddIn;

I was hoping that I will get a reference to VSTO AddIn using addin.Object
property, but it is always null. I also tried to set that property in the
start-up event of the add-in, but it caused TypeMismatch error, so I
assume
that it is a misleading.

Anyway, I have set [ComVisible(true)] attribute on the add-in, but it
didn't
helped.

Thanks for templates, they are great, but I didn't find what I needed
there.

Thanks



  #6  
Old January 12th 09, 09:39 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Reference to AddIn

I believe that static is a requirement, but I'm not positive. Try it without
and see if it works. If it doesn't that still lets you set the externally
visible interfaces as static and still work with non-static methods and
properties.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Nenad" wrote in message
...
Thanks, that is exactly what I have asked for.

One final question: As I can see, using this technique, only static
methods
and properties can be invoked on add-in class?


  #7  
Old January 27th 09, 02:08 AM posted to microsoft.public.outlook.program_addins
YM
external usenet poster
 
Posts: 3
Default Reference to AddIn

Hi Ken,

I'm trying to access functions in add-in created by VB6.
I noticed you have vb6 version of template as well. This template include a
function 'CalledFromOutside'. To make the function visible, is it enough to
make the method public? I do not see any of the automation code in vb6
template.

Thanks

Y

"Ken Slovak - [MVP - Outlook]" wrote:

You didn't look closely enough at the templates. Look at the code at the end
of the ThisAddin class in the section starting with this line:

public static AutomationObject AddinObject = null

That code and what follows in the override and interfaces, along with the
AutomationObject class are what you need. That will expose the addin and
from there the code in the CalledFromOutside method shows how to expose
properties to the outside. You can modify that to call methods in your addin
code also.

To call from outside you'd use something like this (VBA code):

Dim oAddin As Office.COMAddIn

Set oAddin = Application.COMAddIns.Item("MyVSTOAddIn") ' the addin name
here
If Not (oAddin Is Nothing)
oAddin.Object.CalledFromOutside
End If

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Nenad" wrote in message
...
I can get a reference to Office.COMAddIn, but what I really need is a
reference to TheAddIn (which is a subclass of a
Microsoft.Office.Tools.AddIn
class and is inherited from
Microsoft.VisualStudio.Tools.Applications.Runtime. IStartup interface).

This is code from Initialize(Outlook.Application app) method from user
control hosted in FHP:

object name = "MyAddIn";
Office.COMAddIn addin = (Office.COMAddIn)app.COMAddIns.Item(ref
name);
ThisAddIn add = addin.Object as AddIn.ThisAddIn;

I was hoping that I will get a reference to VSTO AddIn using addin.Object
property, but it is always null. I also tried to set that property in the
start-up event of the add-in, but it caused TypeMismatch error, so I
assume
that it is a misleading.

Anyway, I have set [ComVisible(true)] attribute on the add-in, but it
didn't
helped.

Thanks for templates, they are great, but I didn't find what I needed
there.

Thanks



  #8  
Old January 27th 09, 03:18 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Reference to AddIn

Using the template as is will expose that method to the outside.

How you do these things varies from VB6 to managed code. You don't have the
COM Interop getting in the way with VB6 code.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"YM" wrote in message
...
Hi Ken,

I'm trying to access functions in add-in created by VB6.
I noticed you have vb6 version of template as well. This template include
a
function 'CalledFromOutside'. To make the function visible, is it enough
to
make the method public? I do not see any of the automation code in vb6
template.

Thanks

Y


 




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
what reference do i need. why error Dickery1 Outlook and VBA 2 March 6th 08 12:01 PM
Smarter NameSpace Reference... DG Outlook and VBA 1 October 21st 07 03:26 PM
How to remove reference to Outlook Add-in Richard Skilton Outlook - Installation 4 July 28th 07 09:40 PM
Problem to reference FM20.dll Christian Havel Add-ins for Outlook 2 July 13th 07 08:32 AM
Reference Formula ~KO Outlook - Using Forms 3 February 24th 06 09:20 PM


All times are GMT +1. The time now is 07:02 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-2025 Outlook Banter.
The comments are property of their posters.