Miscellaneous Debris

Avner Kashtan's Frustrations and Exultations
COM Add-Ins : Multiple Madness!

[Don't you hate it when IE throws your long post to the trash? We need a smart client for updates!]

COM AddIns for Office are a nice feature. A rather easy way to add some buttons and functionality to your documents, and even deployment isn't too much of a hassle.

But I ran into a problem today when I had two Word documents open at once. It seems that the button was loaded for both, but was only functional for the first instance. The second instance had something that looked like a button, got clicked like a button, but all-in-all did nothing that buttons did - that is, trigger an event.

Several hours of furious debugging followed. VB6 code was translated to VB.NET and then to C#. No go. Code was moved from the OnConnection event to OnStartupComplete - still nothing. A working sample retrieved and compared - nothing relevant seemed to pop up from the page.
Only after going line-by-line over the sample and copying it to my code did we get an answer:

VB controls and similar APIs tend to have a Tag property for all their controls. A convenient, loosely-typed way to store extra data about the control without having to subclass the control or design your own interface.
A great workaround for lazy programmers, up until the time it bites you back. It bites you when you have to go over someone’s code where he uses properties for data other that their intended use. It bites you when you have a “Title” field for a mailbox that is actually used to store an organizational Department. It bites you when your code doesn’t document itself – it does something other than what you expect it to do.

And that’s exactly what Office does – it uses the Tag property of the CommandBarButton to keep track of control instances between multiple open documents.
It doesn’t matter what the Tag holds – the minute you put something in it, the button works fine on as many instances of Word as you’d like.

Why does it rely on the generic, optional, misleading Tag property for this? Couldn’t they add some internal property? Some automatic mechanism? Why do I have to set a random, pointless string to an arbitrary, pointless property to get functionality to work?

Lazy workaround for Lazy programmers. Bah.

Published Thursday, June 17, 2004 5:52 PM by AvnerK

Filed under:

Comments

# Troubling APIs@ Thursday, June 17, 2004 10:13 AM

TrackBack

# re: COM Add-Ins : Multiple Madness!@ Friday, June 18, 2004 8:31 AM

You should read this :)
http://weblogs.asp.net/okloeten/archive/2004/05/21/136769.aspx

Omer van Kloeten

# re: COM Add-Ins : Multiple Madness!@ Sunday, June 17, 2007 5:34 AM

medications on the orders of physicians, and it also includes more modern services related to patient care, <a href= http://1url.org/go/1yolui|Viagra 30 pills x 100 mg

></a>*[url=http://1url.org/go/1yolui|Viagra 30 pills x 100 mg

][/url]* Other symbols are common in different countries: the green Greek cross in France and the United Kingdom,

tolslvh

# re: COM Add-Ins : Multiple Madness!@ Thursday, August 02, 2007 8:00 AM

<a href="httpwwwgmauvzrdcnpage80html">shoppingtrolleymanufacture</a> shoppingtrolleymanufacture,<a href="httpwwwuiidlecxcnpage7html">flamebegonias</a> flamebegonias,<a href="httpwwwgmauvzrdcnpage87html">imknowninallthewrongplaces</a> imknowninallthewrongplaces,<a href="httpwwwgmauvzrdcnpage81html">universityofmarylandofmusicofsuzukiteachertraining</a> universityofmarylandofmusicofsuzukiteachertraining,<a href="httpwwwgmauvzrdcnpage81html">suzukits25079</a> suzukits25079,<a href="httpwwwgmauvzrdcnpage83html">homegardenautomotivefinance</a> homegardenautomotivefinance,<a href="httpwwwgmauvzrdcnpage80html">ventilatormanufactures</a> ventilatormanufactures,<a href="httpwwwgmauvzrdcnpage89html">articlesonelementaryeducationphysicalhealth</a> articlesonelementaryeducationphysicalhealth,<a href="httpwwwgmauvzrdcnpage87html">allsearchenginespiledintoonesearchengine</a> allsearchenginespiledintoonesearchengine,<a href="httpwwwgmauvzrdcnpage89html">directoryeducation</a> directoryeducation,

034

Leave a Comment

(required) 
(required) 
(optional)
(required)