COM Addin Connect?

S

sorina.negulescu

I created a COM addin with the "Visio add-in and add-on wizard".
I want to load the addin on demand, not when Visio starts up.

With the Visio application, I accomplish this from:

Tools > Trust Center > Addins --> Manage COM addins
After checking the checkbox from the COM Add-ins dialog, the message
box from the OnConnection method pops up, which shows that visio
loaded my addin.

I would like to accomplish the same behavior from the Visio Drawing
control.
I could not find any API in the Visio 2007 SDK for connecting to an
addin.

From the VBA help, it appears that I would have to call comething
like:
Application.COMAddIns(1).Connect

In the Visio SDK for C++ though, there's no COMAddins object (there is
a ComAddins method, that retrieves an IDispatch).
How do I tame this IDispatch into a nice object that I can browse?

Thanks in advance for your help,
Sorina
 
N

Nikolay Belyh

Application.COMAddIns(1).Connect

In the Visio SDK for C++ though, there's no COMAddins object (there is
a ComAddins method, that retrieves an IDispatch).
How do I tame this IDispatch into a nice object that I can browse?

IF you are writing in C++, then

1. Add reference the "mso.dll" (this "com addin" stuff is shared
between all office applications). I mean:

#import "libid:{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}" auto_rename

2. Just cast that IDispatch to the COMAddins. I mean:

Office::COMAddInsPtr addins = app->COMAddIns;

variant_t index = 1L;
Office::COMAddInPtr my_addin = addins->Item(&index);
my_addin->Connect = VARIANT_TRUE;

May work :)
 
S

sorina.negulescu

I imported mso.dll and obtained CComAddins and CComAddin. However,
they are totally different from what is described in the
documentation.
The CComAddins class I obtained is not even a collection.
It offers LPDISPATCH get_Application(), long get_Creator(), LPDISPATCH
get_Parent(), and a bunch of color format methods.
 
N

Nikolay Belyh

What do you mean by "imported"? How did you do that?
What I have meant is that you could write in your C++ file
something like the code below and then give it a shot:

// --- cut here ---

#import "libid:{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}" auto_rename

void ConnectAddin1(IVApplicationPtr app)
{
Office::COMAddInsPtr addins = app->COMAddIns;

variant_t index = 1L;
Office::COMAddInPtr my_addin = addins->Item(&index);
my_addin->Connect = VARIANT_TRUE;
}

// --- cut here ---

You can find more about #import directive in MSDN.

Kind regards, Nikolay
 
S

sorina.negulescu

Thank you, Nikolay, that worked.
I was using the Project->Add Class feature from the MSDEV, expecting
to obtain the same result. I'm still puzzled why that did not happen.
 

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