Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2004

Tip: Looking for answers? Try searching our database.

COM Add-in toolbar click events only fire once if window is initialized

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Carlos - 03 Sep 2004 02:51 GMT
This is a very bizare problem.  So, I have a C# COM Add-in for Excel
which creates a toolbar, then pops-up meaningful windows when you
click the toolbar buttons.  Everything works fine the first time.
After that, my event handlers do not get called when I click the
toolbar handlers.  I've isolated the problem down to initializing a
dialog window (never actually showing the window).  Explicitely, the
VisualStudio IDE is initializing the first component, failing on:

 this.instructionLabel.Location = ((System.Drawing.Point)
   (resources.GetObject("instructionLabel.Location")));

in InitializeComponent().  If I comment out the rest of the
initialization code from this line to "this.ResumeLayout(false);", the
event will fire every time.  Note that there are plenty of lines
before this with plenty of equally 'severe' calls:

 System.Resources.ResourceManager resources = new
     System.Resources.ResourceManager(typeof(AuthenticationPopup));
 this.instructionLabel = new System.Windows.Forms.Label();
 this.userIdLabel = new System.Windows.Forms.Label();
 ...

 this.SuspendLayout();
 ...
 
 this.instructionLabel.Anchor = ((System.Windows.Forms.AnchorStyles)
   (resources.GetObject("instructionLabel.Anchor")));
 ...

Unfortunately, this isn't a clear relationship, as I can't duplicate
it in a simple sample app where I create the add-in, toolbar, form
(localized), and one simple label.  Other things happening:
- If I comment out all of the form stuff, there is also a networking
class that basically does XML-RPC http client calls that causes the
same problem.  Commenting out the 2 together allows for multiple
firings.
- I was previously developing this app as a simple COM interop
application launching it from some Excel VB code.  This issue wasn't
present in that mode.

Thanks,
Carlos
versions: .NET 1.1, OfficeXP, VisualStudio.NET 2003 (latest service
packs)
Carlos - 07 Sep 2004 19:29 GMT
Problem solved thanks to one of my brilliant collegues.  Turns out
that the sample app makes the seemingly innocuous action of
maintaining a reference to the toolbar button once it is created.  If
this is not done (as was the case in my application), the C#/.NET
structures get garbage collected.  The thing is COM is supposed to
maintain the same sort of reference counting (the ugly thing with COM
is that you have to do it all yourself if I remember correctly).  This
suggests that it's office that only creates the COM programming
structures when asked, but maintains only Excel/VBE structures
independently.  It's ugly, but important to understand.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.