Accessing a COM addin from outside

B

Bernd

Hi,

I' ve developed a COM addin for Word using VB.NET. Now, I want to access
it from 'outside' (by a Word macro, for instance).
To make my addin accessible, the AddInInst parameter of the OnConnection
sub is assigned a reference to the addin:
------------------------------------------------------------------
Public Sub OnConnection(_
ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, _
ByRef custom As System.Array) _
Implements AddInDesignerObjects.IDTExtensibility2.OnConnection
....
AddInInst.Object = Me
....

end sub
------------------------------------------------------------------

My Word macro for accessing the COM addin looks like:
------------------------------------------------------------------
Dim MyAddin As COMAddIn
Set MyAddin = Application.COMAddIns("MyAddin.Connect")
------------------------------------------------------------------

But the property 'MyAddin.Object' turns out to be nothing!
Any idea why?

Thanks a lot in advance for your answers.
Bernd
 
B

Bernd

Hi again,

in the meantime I found a solution (it's still before midnight :)
I used the InvokeMember-method in the OnConnection sub:
------------------------------------------------------------------
Public Sub OnConnection(_
ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, _
ByRef custom As System.Array) _
Implements AddInDesignerObjects.IDTExtensibility2.OnConnection
...
Dim args(0) As Object
args(0) = New TestClass ' Class, the methods of which should
' be accessible
AddInInst.GetType.InvokeMember(_
"Object", _
BindingFlags.Public Or BindingFlags.SetProperty, _
Nothing, AddInInst, args)


end sub
-------------------------------------------------------------------
In the Word macro, all public methods of TestClass can be used:
Dim MyAddin As COMAddIn
Set MyAddin = Application.COMAddIns("MyAddin.Connect")
MyAddin.Object.Method1

Now, I am beginning to see dark spots on the screen. It's time to go to bed.
G'night
Bernd
 

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