P
Petrowi
I have this code attach a command bar in Visio 2003 and add a button to it.
The code works ok until a document is opened. The error looks like garbage
collection issue, but I keep a reference to the .Net object, so it shouldn't
get collected.
For some reason after a document is opened, access to cbbX throws a COM
exception "HRESULT 0x800A01A8"
I can't figure out what is going wrong, please help.
Thank you.
public static Core.CommandBarButton cbbX = null;
public static Core.CommandBar cb = null;
public static void AddToolbar(Visio.Application va) {
Core.CommandBars cbrs = va.CommandBars as Core.CommandBars;
if (cbrs == null) {
System.Windows.Forms.MessageBox.Show("Visioplugin can't
create Toolbar [MNADCBRC]");
} else {
cb = cbrs.Add("X Toolbar", Core.MsoBarPosition.msoBarTop,
Type.Missing, true);
cb.Visible = true;
object o = Type.Missing;
Core.CommandBarButton testButton =
(Core.CommandBarButton)cb.Controls.Add(Core.MsoControlType.msoControlButton,
o, o, o, true);
testButton.Caption = "X Button";
testButton.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(testButton_Click);
testButton.Style = Core.MsoButtonStyle.msoButtonCaption;
testButton.Tag = "X Button";
cbbXDLS = testButton;
}
}
static void testButton_Click(Microsoft.Office.Core.CommandBarButton
Ctrl, ref bool CancelDefault) {
if (Ctrl.Tag == cbbX.Tag) // THIS LINE THROWS "HRESULT 0x800A01A8"
System.Windows.Forms.MessageBox.Show("Visio Click!");
}
The code works ok until a document is opened. The error looks like garbage
collection issue, but I keep a reference to the .Net object, so it shouldn't
get collected.
For some reason after a document is opened, access to cbbX throws a COM
exception "HRESULT 0x800A01A8"
I can't figure out what is going wrong, please help.
Thank you.
public static Core.CommandBarButton cbbX = null;
public static Core.CommandBar cb = null;
public static void AddToolbar(Visio.Application va) {
Core.CommandBars cbrs = va.CommandBars as Core.CommandBars;
if (cbrs == null) {
System.Windows.Forms.MessageBox.Show("Visioplugin can't
create Toolbar [MNADCBRC]");
} else {
cb = cbrs.Add("X Toolbar", Core.MsoBarPosition.msoBarTop,
Type.Missing, true);
cb.Visible = true;
object o = Type.Missing;
Core.CommandBarButton testButton =
(Core.CommandBarButton)cb.Controls.Add(Core.MsoControlType.msoControlButton,
o, o, o, true);
testButton.Caption = "X Button";
testButton.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(testButton_Click);
testButton.Style = Core.MsoButtonStyle.msoButtonCaption;
testButton.Tag = "X Button";
cbbXDLS = testButton;
}
}
static void testButton_Click(Microsoft.Office.Core.CommandBarButton
Ctrl, ref bool CancelDefault) {
if (Ctrl.Tag == cbbX.Tag) // THIS LINE THROWS "HRESULT 0x800A01A8"
System.Windows.Forms.MessageBox.Show("Visio Click!");
}