![]() |
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. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
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 |