2003 add-in in Custom form

G

GSK

I have created a outlook 2003 add in VS 2005. I am referencing the add-in in
a custom outlook form. I am not able to call the Test method from the from,
am getting the error "object required". Pls find the code below. Kindly help
me in identifiying this issue.
--------------------------------------------------------------------------------------
Add-in Code :
namespace OutlookTest
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
public void Test(string Name)
{
MessageBox.Show(Name);
}
}
------------------------------------------------------------------------------------------
Custom form code
Function Item_Open()
Set myObj = Application.COMAddIns.Item("OutlookTest")
myObj.Connect = True
Set oCOMAddinObj = GetObject("","OutlookTest")
oCOMAddinObj.Test("Add-in call") /--Getting error in this line..
End Function
------------------------------------------------------------------------------------------
 
K

Ken Slovak - [MVP - Outlook]

There's a lot more you need to do in a VSTO addin to make your addin code
available to outside calls. You need to override
RequestComAddInAutomationService() and provide a dual interface ComVisible
class, among other things.

You need something like this in your ThisAddIn class

private AddinUtilities addinUtilities;

protected override object RequestComAddInAutomationService()
{
if (addinUtilities == null)
{
addinUtilities = new AddinUtilities();
}
return addinUtilities;
}
}

[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IAddinUtilities
{
void CalledFromOutside();
}

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
public class AddinUtilities : IAddinUtilities
{
// Demonstrates a method that can be called from outside the addin.
// This technique can be used to call functions and to read/write
properties.
public void CalledFromOutside()
{
MessageBox.Show("This is a test of an outside call to the COM
addin");
}
}
:
Then your calling code has to be specially formatted:

Dim oAddin

Set oAddin = Application.COMAddins.Item("myAddinProgID") ' myAddinProgID is
the ProgID of the addin
If Not (oAddin Is Nothing) Then
oAddin.Object.CalledFromOutside 'this calls the addin procedure
End If
 
G

GSK

Thanks very much Ken. It worked now after the changes.

Ken Slovak - said:
There's a lot more you need to do in a VSTO addin to make your addin code
available to outside calls. You need to override
RequestComAddInAutomationService() and provide a dual interface ComVisible
class, among other things.

You need something like this in your ThisAddIn class

private AddinUtilities addinUtilities;

protected override object RequestComAddInAutomationService()
{
if (addinUtilities == null)
{
addinUtilities = new AddinUtilities();
}
return addinUtilities;
}
}

[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IAddinUtilities
{
void CalledFromOutside();
}

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
public class AddinUtilities : IAddinUtilities
{
// Demonstrates a method that can be called from outside the addin.
// This technique can be used to call functions and to read/write
properties.
public void CalledFromOutside()
{
MessageBox.Show("This is a test of an outside call to the COM
addin");
}
}
:
Then your calling code has to be specially formatted:

Dim oAddin

Set oAddin = Application.COMAddins.Item("myAddinProgID") ' myAddinProgID is
the ProgID of the addin
If Not (oAddin Is Nothing) Then
oAddin.Object.CalledFromOutside 'this calls the addin procedure
End If




GSK said:
I have created a outlook 2003 add in VS 2005. I am referencing the add-in
in
a custom outlook form. I am not able to call the Test method from the
from,
am getting the error "object required". Pls find the code below. Kindly
help
me in identifiying this issue.
--------------------------------------------------------------------------------------
Add-in Code :
namespace OutlookTest
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
public void Test(string Name)
{
MessageBox.Show(Name);
}
}
------------------------------------------------------------------------------------------
Custom form code
Function Item_Open()
Set myObj = Application.COMAddIns.Item("OutlookTest")
myObj.Connect = True
Set oCOMAddinObj = GetObject("","OutlookTest")
oCOMAddinObj.Test("Add-in call") /--Getting error in this line..
End Function
------------------------------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top