SUMMARY
This step-by-step article describes how to modify the class wrappers for Microsoft Office 2003 Web Components. It then describes how to regenerate the class wrappers so that you can manage their events in an application that you create by using Microsoft Visual Studio .NET.
By default, the class wrappers that Microsoft Visual Studio .NET generates do not permit you to handle events for the following Office 2003 Web components:
- Chart
- Spreadsheet
- PivotTable
To handle the events for these components, you can modify the source code for the class wrappers, and then recompile the code.
back to the topBackground
Microsoft Visual Studio .NET generates an
event listener class that implements an
event interface. This
event listener class is passed to the Office Web Components (OWC). The OWC then calls the
QueryInterface method for the
IDispatch interface, instead of calling the
event interface. However, the
IDispatch interface for the generated class does not contain the dispatch identifiers (DISPIDs) for the events.
To resolve this issue, you can mark the generated class by using the
ClassInterfaceType.None
value to force COM interop to return
IDispatch for the interface instead of for the class. The
IDispatch interface contains the event DISPIDs.
back to the topSteps to Modify and to Rebuild the Class Wrappers
- Start the Visual Studio .NET command prompt.
- At the command prompt, do the following:
- Create a new directory named owc11, and then change to that directory:
-
Generate the source code in C# for the Microsoft Windows Forms wrapper:
aximp "c:\program files\common files\microsoft shared\web components\11\owc11.dll" /source
-
Delete the generated assembly AxOWC11.dll:
- In a text editor (such as Notepad), open C:\OWC11\AxOWC11.cs.
-
Add
[ToolboxItem(true)]
to the generated class for the Chart component, the Spreadsheet component, and the PivotTable component, as in the following examples:
Chart Component [System.ComponentModel.ToolboxItem(true)]
public class AxChartSpace : System.Windows.Forms.AxHost {
...
}
Spreadsheet Component [System.ComponentModel.ToolboxItem(true)]
public class AxSpreadsheet : System.Windows.Forms.AxHost {
...
}
PivotTable Component [System.ComponentModel.ToolboxItem(true)]
public class AxPivotTable : System.Windows.Forms.AxHost {
...
}
-
Mark the event classes as
ClassInterfaceType.None, as in the following examples:
Chart Component [System.Runtime.InteropServices.ClassInterface(
System.Runtime.InteropServices.ClassInterfaceType.None)]
public class AxChartSpaceEventMulticaster : OWC11.IChartEvents {
...
}
Spreadsheet Component [System.Runtime.InteropServices.ClassInterface(
System.Runtime.InteropServices.ClassInterfaceType.None)]
public class AxSpreadsheetEventMulticaster : OWC11.ISpreadsheetEventSink {
...
}
PivotTable Component [System.Runtime.InteropServices.ClassInterface(
System.Runtime.InteropServices.ClassInterfaceType.None)]
public class AxPivotTableEventMulticaster : OWC11.IPivotControlEvents {
...
}
- Save your changes to AxOWC11.cs.
-
At the Visual Studio .NET command prompt, do the following:
- Add C:\Program Files\Microsoft.NET\Primary Interop Assemblies to your
LIB
environment variable:
set lib=c:\program files\microsoft.net\primary interop assemblies;%path%
-
Copy Microsoft.Office.Interop.OWC11.dll and MSComCtl.dll from the GAC where the Microsoft Office 2003 Primary Interop Assemblies are installed:
copy %windir%\assembly\GAC\Microsoft.Office.Interop.Owc11\11.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Owc11.dll
copy %windir%\assembly\GAC\mscomctl\10.0.4504.0__31bf3856ad364e35\mscomctl.dll
-
Compile the source file, AxOWC11.cs:
csc /t:library /r:microsoft.office.interop.owc11.dll /r:adodb.dll /r:msdatasrc.dll /r:mscomctl.dll axowc11.cs
Note You receive the following CS0108 error message:The keyword new is required
You may ignore this error.
- Start Visual Studio .NET.
-
Add your newly-compiled AxOWC11.dll to the Toolbox:
-
On the
Tools
menu, click
Customize Toolbox
(in Visual Studio .NET 2002), or click Add/Remove Toolbox Items (in Visual Studio .NET 2003), and then click the .NET Framework Components tab.
-
On the
.NET Framework Components
tab, click
Browse.
-
In the File name text box, type
c:\owc11\axowc11.dll. Click
Open.
-
Click
OK
to close the
Customize Toolbox
dialog box.
When you create a new Microsoft Visual Basic .NET project or a new Microsoft Visual C# .NET project, notice that the list of controls on the
General tab in the
Toolbox contains the
AxChartSpace control, the
AxPivotTable control, and the
AxSpreadsheet control. You can now add these components to your forms.
back to the topREFERENCES
For additional information about managing events for the Office XP Web Components by using Visual Studio .NET, click the following article numbers to view the articles in the Microsoft Knowledge Base:
328275
HOW TO: Handle Events for the Office Web Components in Visual Studio .NET
back to the top