VSTO vs. COM Add-In

S

Sreedhar

What is the difference between VSTO and COM Add-In (implements
IDTExtensibility2 interface)? Why do you choose one over the other? I
searched for this topic over the web, but couldn't find anything. Are they
just two approaches to do the same thing? Any help is appreciated.
 
P

pavan

Hi Sreedhar,
VSTO add-ins are scoped at document-level while COM Add-ins are at
application level. It, infact, depends on the host application that you
intend to develop the add-in for also. For example using VSTO you can
create an add-in scoped at application level but you can't do the same
for Word or Excel. But COM add-ins, for any host app, run at the app
level.

Just in case you are not aware of app-level and doc-level scopes: An
add-in scoped at app-level runs for all the documents of the host app
whole an add-in scoped at doc-level runs only for the specific document
for which the add-in has been developed for.

Chk this article for more info:
http://www.codeproject.com/useritems/wordaddindesign.asp
It deals with MS Word

Hope this helps,
regards
Pavan
 
A

Alex

pavan said:
VSTO add-ins are scoped at document-level while COM Add-ins are at
application level. It, infact, depends on the host application that you
intend to develop the add-in for also. For example using VSTO you can
create an add-in scoped at application level but you can't do the same
for Word or Excel. But COM add-ins, for any host app, run at the app
level.

Just in case you are not aware of app-level and doc-level scopes: An
add-in scoped at app-level runs for all the documents of the host app
whole an add-in scoped at doc-level runs only for the specific document
for which the add-in has been developed for.

Chk this article for more info:
http://www.codeproject.com/useritems/wordaddindesign.asp
It deals with MS Word

Is it possible to create a template-scoped VSTO template and load it on a per-document basis (instead of in the startup older)?

For example, say I have a document doc_x.doc which is based on tpl_x.dot
I also have a VSTO addin in a template addin.dot
I want to load doc_x.doc, then load addin.dot (activating the addin) but keep the document's association with tpl_x.dot.

Is it possible?


Best wishes,
Alex.
 
C

Cindy M.

Hi Alex,
Is it possible to create a template-scoped VSTO template and load it on a per-document basis (instead of in the startup older)?

For example, say I have a document doc x.doc which is based on tpl x.dot
I also have a VSTO addin in a template addin.dot
I want to load doc x.doc, then load addin.dot (activating the addin) but keep the document's association with tpl x.dot.

Is it possible?
Not directly. I'm not quite clear on what you're imagining, as a VSTO addin cannot be IN a template. AVSTO Addin (as in VSTO 2005
SE) is a COM Add-in...

What you could do, for example, is hook into the DocumentOpen event in the x.dot. In this procedure, load the Addin. You'd
probably also want to hook into WindowSelectionChange so that you can unload it when the focus leaves this particular document
(so the addin isn't visible in other documents).

Or, just put all the functionality in x.dot (why not?) so that it really is document-specific.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply in the newsgroup and not by e-mail :)
 
A

Alex

Hi Cindy, long time no talk...

Cindy M. said:
I'm not quite clear on what you're imagining, as a VSTO addin cannot be IN a template. AVSTO Addin (as in VSTO 2005
SE) is a COM Add-in...

OK, my fault for being unclear, I'll rephrase.

The intent is to have some functionality available for documents. I implemented it as a COM add-in.

However, this COM add-in is quite intrusive and occasionally does not play well with some other add-ins (that assume they are the only ones loaded), applications that embed MS-Word, etc.

Now, the problem with COM add-ins is that once they are loaded, they are available for all the MS-Word windows that use that application instance. Currently I do some fancy stuff to try to detect specific cases and disable some functionality but it's not very reliable.

What I would like to do:

1) Assume the user has several MS-Word documents open (only one application instance is loaded)

2) The user clicks on a toolbar button in one of the windows. This "loads" some "add-in" only for this particular document, all the others are unaffected. If the user so desires, they can "load" it for the other documents as well.

3) Since the document size is a concern, I cannot have the "add-in" be a part of the document itself. It has to be external.

Is this possible? Any suggestions?

Now, I am not familiar with VSTO but I was under the impression that I can attach a VSTO project to a document or a template.


Best wishes,
Alex.
 
C

Cindy M.

Hi Alex,
Now, I am not familiar with VSTO but I was under the impression that I can attach
a VSTO project to a document or a template.You can do that, yes. But VSTO code can't be loaded as an Add-in from the Startup
folder. It's like VBA code-behind a template or document - it's specific to that
document (or documents attached to the template).
What I would like to do:

1) Assume the user has several MS-Word documents open (only one application instance is loaded)

2) The user clicks on a toolbar button in one of the windows. This "loads" some
"add-in" only for this particular document, all the others are unaffected. If the
user so desires, they can "load" it for the other documents as well.
3) Since the document size is a concern, I cannot have the "add-in" be a part of
the document itself. It has to be external.What I usually recommend (never tried it in production, but have suggested it to
others and it appears to work):

1. Set up an Add-in template in the Startup folder that displays its own toolbar.
You want to do this so because other add-ins might manipulate built-in
menus/toolbars). It has one button: to manage Add-ins

2. Remove everything else from the Startup folder

3. The code in the "manager" template can list all templates in an alternate
"Startup" folder. All COM Add-ins found in the Registry for the user, and for the
machine. It can then take care of loading and unloading them.

You can also have an AutoExec macro in it that takes care of removing anything else
in the Addins collection, when Word starts, although you might need to use OnTime
for this because there's no way to control the order in which things load and new
COM Add-ins will load; existing COM Add-ins might get re-enabled to load
automatically.

The only problem that can crop up is if some other Addin is trying to do the same
thing...

This is part of the reasoning behind the Ribbon introduce in Office 2007. Another
Add-in can't affect what tabs your Add-in adds to the Ribbon. There's also a better
"Add-ins manager" functionality in Office 2007.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply in
the newsgroup and not by e-mail :)
 
A

Alex

Hi Cindy,

I'm not sure I explained the problem correctly.

I need to *selectively* enable the add-in functionality for *some* of open documents.
Once I load the add-in, it is loaded for *all* the documents that that instance of MS-Word loads.

Currently, I use complicated logic and WindowChanged events to simulate this. This is not a robust solution as it breaks in certain scenarios.

VSTO gives me an option to have add-in-like functionality on a per-document basis.
However, as you said, it is attached to the document.

What I would like to do is a sort of combination -- allow the user to selectively load an "extension" (for lack of a better word) into an open document that will:
(a) not affect any other MS-Word documents on the machine, whether open before or after the event, and
(b) not save the actual "extension" code in the document itself (contrary to the VBA model)

Is there a way to accomplish that?

Also, I cannot use features specific to Word-2007 at this time since I have to support Word-2003 (and preferably Word-XP as well).

Thanks,
Alex.
 
C

Cindy M.

Hi Alex,

Are you aware of how Word TEMPLATES work? You set up a template with any standard text, and you can include toolbars and macros. Every document generated from the
template will always have access to the toolbars and macros, but none of these will be saved in the document. It all stays in the template. That's the closest Word
has to what you're requesting.

Anything else will involve using Events, such as you're currently doing.
I'm not sure I explained the problem correctly.

I need to *selectively* enable the add-in functionality for *some* of open documents.
Once I load the add-in, it is loaded for *all* the documents that that instance of MS-Word loads.

Currently, I use complicated logic and WindowChanged events to simulate this. This is not a robust solution as it breaks in certain scenarios.

VSTO gives me an option to have add-in-like functionality on a per-document basis.
However, as you said, it is attached to the document.

What I would like to do is a sort of combination -- allow the user to selectively load an "extension" (for lack of a better word) into an open document that will:
(a) not affect any other MS-Word documents on the machine, whether open before or after the event, and
(b) not save the actual "extension" code in the document itself (contrary to the VBA model)

Is there a way to accomplish that?

Also, I cannot use features specific to Word-2007 at this time since I have to support Word-2003 (and preferably Word-XP as well).

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply in the newsgroup and not by e-mail :)
 
A

Alex

Cindy M. said:
Hi Alex,

Are you aware of how Word TEMPLATES work? You set up a template with any standard text, and you can include toolbars and macros. Every document generated from the
template will always have access to the toolbars and macros, but none of these will be saved in the document. It all stays in the template. That's the closest Word
has to what you're requesting.

Yes Cindy, this is what I am talking about.

My question is: can I make those macros, toolbars and, in particular, VSTO code available to documents that were not originally generated from the template (e.g., by loading the template into an open document)?


Best wishes,
Alex.
 

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