Visio exe add-on how-to?

J

Josef Meile

Hi,

I'm trying to find a guide on doing external exe add-ons for
visio. The only add-on example I have found is the c++ flow
chart example from the sdk, which generates a vsl file and
not an exe file which is what I want. I'm planning to use C#,
but I suppose that the procedure to do an exe add-on isn't
be much different as by a vsl, is it?

I have tried to guess what the code does, but for me isn't
jet clear the following things:

1) I know that you can catch the Document_created event on
an add-in and see if the template that the new document
is using is the one included with your solution. If I'm not
wrong, visio will excecute all the Document_created handlers
of all the loaded add-ins, then do something according to
the written code there. But, with add-ons is diferent because
they aren't on memory and are loaded when you need them.

So, my question is: How do you associate the add-on with a
template in order to make it load when a new document based
on the template is created?

2) According to the interop tutorial, you can catch the events of
an add-in by using the "WITH EVENTS" keyword on the declaration
of your visio application variable, or by associating a Event handler
class with your application by doing this:

Private resultEvent As Microsoft.Office.Interop.Visio.Event
Private eventSink As IVisEventProc

I found the "VFlowSample::HandleVisioEvent" method on the
Flow Char add-on, but the question is: is it enough with just
defining this or are there other steps to handle the events?

3) What other libraries you have to include to do a visio add-on?
For example: on the Flow Chart add-on, I saw the "DocumentCreator",
class. Is it a predefined class or do you have to code it from
zero?

4) The visio add-on wizard ask allways what to include:
* C++ without ATL or MFC
* MFC
* ATL
What's the purpose of each option?

2) I have tried to build, install and run the flow chart example,
but I always see a page with a text shape which says:

"This template is designed to work with the Flowchart Sample
Application that must be built by compiling sample code located
in the SDK install directory under samples\flowchart\cpp."

I don't see anything else. What is this add-on supose to
do?

I did what is written there: Open the C++ net project, build
the solution by choosing "Build solution" from the "Debug" menu,
place the mouse over "FlowchartSampleSetup", then choose
"Install" from the context menu. I got the following files
installed:

* ATL71.DLL
* Flowchart (VSL).vst
* Flowchart.xls
* FlowSample.vsl

on the following directory:
C:\Program Files\Microsoft Office\Visio 2003 SDK Samples\Flowchart Sample
(C++)

Then, I set the add-ons path to that directory. When I restarted
visio, I saw a reference to the installed vsl on the "new" option
of the "file" menu. So, I hit it, but I saw again that text shape. What
am I missing here?

3) How do you debug an exe add-on on visual studio net? I tried doing
this by setting the "command action" of the "Debugging" section to:
C:\Program Files\Microsoft Office\Visio11\VISIO.EXE

Then, I put a breakpoint on the first code line after the "try" command
of the "VFlowSample::Run" example.

but when trying to run it, I got a warning that says:
"'VISIO.EXE' does not contain debugging information. (No symbols
loaded.) Click OK to debug anyway."

So, I clicked OK. But the breakpoint got a question mark,
it were never hit, and I saw the following message when
placing the mouse over it:

"At VFlowSample.cpp, line 101

The breakpoint will not currently be hit.
No excecutable code is currently loaded at this location."

How do you configure your debugger?

Thanks in advanced,
Josef
 
M

Michael Keilhack

Hey,

a good starting point for me was the MSDN - Office Development
Documentation!
There is an abstract named Development of Office Solutions->MS
Visio->Visio2002->SDK-Documentation->Developing MS Visio Solutions.

To create an EXE Addon just use the ComAddon Wizard in VS.Net!
This creates you a new Project with all References set and a sample
Main() with a DialogBox and the Visio Object!

Best regards Michael
 
A

Al Edlund

two pieces of the puzzle that aren't readily obvious is the need to a.)
create a user defined field in you template that identifies the add-on that
is valid for it and b.) create a persistent event in the template that will
fire off when it is opened. Where the example in the sdk looks for the
event, I didn't notice where it told you to create one in the template.
Al
 
J

Josef Meile

Hi Michael,
Hey,

a good starting point for me was the MSDN - Office Development
Documentation!
There is where I saw the interop tutorial to develop COM add-ins.
There is an abstract named Development of Office Solutions->MS
Visio->Visio2002->SDK-Documentation->Developing MS Visio Solutions.
I didn't see it on the visio2003 SDK-Documentation. I guess microsoft
haven't updated it jet. I will read this version and see if it helps me.
To create an EXE Addon just use the ComAddon Wizard in VS.Net!
This creates you a new Project with all References set and a sample
Main() with a DialogBox and the Visio Object!
Yes, I have done it, but I didn't see how to hook your add-on on a
template like you do with an add-in. Anyway, I will take a look more
carefully and see if I passed something.

Thanks for your reply.

Best regards,
Josef
 
J

Josef Meile

Hi Al,

I'm not sure what you meant on your reply. Are you asking me for a explanation
or do you agree with me? Anyway, I think you are asking me to clarify my
problem.
So, here it goes...
two pieces of the puzzle that aren't readily obvious is the need to a.)
create a user defined field in you template that identifies the add-on that
is valid for it
I would like to do it like the COM add-ins do it, but with an Add-on: to
have a template with my own shapes, which have some actions associated
to them. ie: when dropping a shape to the visio main window, it will get an
oid, then it will be inserted on a tree view control (like explorer of
windows)
and finaly it will be stored on an excel file. Additionally, each shape will
have
a context menu with some options like: delete shape, add child, add links to
excel rows, etc..

If you see on my example I need to activate the add-on as soon as I create
a document based on my template because I need to access the code that
creates the excel file, intercept the drop and delete shape events from my
visio document and manipulate the tree view control.

I have done some things already with VBA and I have and idea about doing
this with an add-in, but I don't like both solutions becase:
1) VBA can be manipulated for a curious user.
2) Each document will store a copy of the VBA code, so, it will be a waste
of space and updates of my solution will be dificult.
3) Add-ins load as soon as visio starts. So, it doesn't matter if the user
works
with my solution, he will have to wait till it is loaded in RAM. (Users with
low
RAM will see this problem more easily).
and b.) create a persistent event in the template that will
fire off when it is opened.
That's how the add-ins I have seen do this: there is a handler
to the open document event, where it is checked wheter or
not the current document is based on my template.
Where the example in the sdk looks for the
event, I didn't notice where it told you to create one in the template.
Actually, I haven't seen this on the example. I only saw it on the add-ins
and that's the way I would like to do it.

Thanks for your reply,
Josef
 
A

Al Edlund

Josef,
When you install the v2003 sdk it will give you access to additional tools.
Open v2003 (and the template you are creating) go to tools => sdk =>
persistent events and then you can manipulate your document and put in the
calls to your add-in. A good example is the flowchart add-on for how to
create the calls to event markers and the need for a user field in your
template so the code can validate that it is your template. The tree diagram
example in the SDK might also be of help in some of your design work.

v2003 likes a lot of memory, so users with low memory may see performance
issues can be annoying.

I suspect you will be writing your add-on in something other than VBA,
otherwise it is merely a template with embedded code. For help in deciding
platform I'd suggest Graham Widemans book "Visio 2003 Developers Survival
Pack".

Al
 
J

Josef Meile

Hi Al,
When you install the v2003 sdk it will give you access to additional tools.
Open v2003 (and the template you are creating) go to tools => sdk =>
persistent events and then you can manipulate your document and put in the
calls to your add-in.
Thanks for your reply. Persistent events was exactly what I was looking
for; however, when you use this tool, does the user, who is going to install
your add-on, need to install the sdk to use the "Persistent Events Tool" as
well?
A good example is the flowchart add-on for how to
create the calls to event markers and the need for a user field in your
template so the code can validate that it is your template.
Yes, I saw they create a SinkClass to handle the visio events. So, once
you add load your add-on with a persistent event on your template, will it
overwrite the visio's default event handler with your own till the document is
closed?
The tree diagram
example in the SDK might also be of help in some of your design work.
Yes, that's where I got the idea to make a tree view for my project.
v2003 likes a lot of memory, so users with low memory may see performance
issues can be annoying.
Yes, that's the reason why I want to do this with an add-on. You don't have to
force users with low memory to load it at visio start-up.
I suspect you will be writing your add-on in something other than VBA,
otherwise it is merely a template with embedded code. For help in deciding
platform I'd suggest Graham Widemans book "Visio 2003 Developers Survival
Pack".
Yes, I saw that a lot of people recommended it on all the posts I found. So, I
will try to convince my boss to buy it.

Just some questions:

1) Always when I install an add-on, I have to include the path to the
executable
on the "Visio add-on path". Is there any way to tell the setup of your project
to register your add-on on visio, so that it knows that there is a new tool?

2) What's the correct way to debug an exe add-on from C#? I created a new
add-on with the "Visio add-in or add-on" template, then I tried to copy the
path
of the visio excecutable under the "start application" field of the Debugging
settings of my project, it doesn't allow me to do that. The field is
disabled, so,
how can I activate it? After activating it, do I have to set up something
additional
on visio, in order to debug the add-on?

Thanks,
Josef
 
A

Al Edlund

Josef,
Let's see if I can get these
when you create your event handler you will also create an addadvise routine
to add your event handler pointer to visio so it knows what to forward to
you. You don't want the users to play with persistent events, it is a sure
way to cause problems.

when the sdk installed on my system I got an extra vs.net template for visio
addon that included (I believe) a project for installing the addon. All of
the mechanics were already created for me (or I forgot that I did them).

Understand when you distribute your document with the code as vba, anybody
who wants to use it / change it /copy it, has the source code. It is not an
addon it is VBA....

regarding debugging addons, there has to be several hundred ways to do it.
The key concept is that while you develop your solution, develop your error
handling as well. In vs.net I've learned that whenever there is an
opportunity to fail for whatever reason I wrap my code in Try... Catch... At
a minimum I have it point to an external log to record the errors.

Al
 
J

Josef Meile

2) What's the correct way to debug an exe add-on from C#? I created a new
add-on with the "Visio add-in or add-on" template, then I tried to copy the
path
of the visio excecutable under the "start application" field of the Debugging
settings of my project, it doesn't allow me to do that. The field is
disabled, so,
how can I activate it? After activating it, do I have to set up something
additional
on visio, in order to debug the add-on?
Ok, I found the solution to this one. For the interested here are the steps:

1) Choose the "Debugging" tab of your project properties.
2) On "Debug Mode" select "Programm"

I had done always those two steps, but I forgot:

3) Click on the button "Apply". If you don't do this, the "Start Application"
field won't become active -> according to the post I found, this seems to
be a bug on visual studio net.

4) Now you can write the path to the visio executable on that field.

I got debugging working together with visio. I put two breakpoints on the
the FlowChart add-in for C#: one on the "OnConnection" method of the
add-in and other on the "VisEventProc" of the "EventSink" class. The
first one is hit as soon as visio is started. Then I see how the marker
events are added to visio and associated to an instance of the EventSink
class. However, when I create a document based on the add-in template,
the second breakpoint is never hit and as I said on my original post, I
only see a blank template with the following message:

"This template is designed to work with the Flowchart Sample Application
that must be built by compiling sample code located in the SDK install
directory under samples\flowchart\csharp."

and nothing else happens. So, visio isn't calling the VisEventProc of the
add-in. I will try to do a small example to see if I get it working.

Thanks anyway for your help.
Josef
 

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