Microsoft KB Archive/823982

= HOW TO: Handle Events for the Office 2003 Web Components in Visual Studio .NET =

Article ID: 823982

Article Last Modified on 9/17/2003

-

APPLIES TO


 * Microsoft Office Web Components
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition

-



IN THIS TASK

 * SUMMARY
 * Background
 * Steps to Modify and to Rebuild the Class Wrappers
 * REFERENCES



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 top

Background
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 top

Steps 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:

md c:\owc11

cd c:\owc11

 Generate the source code in C# for the Microsoft Windows Forms wrapper:

aximp &quot;c:\program files\common files\microsoft shared\web components\11\owc11.dll&quot; /source

 Delete the generated assembly AxOWC11.dll:

del c:\owc11\axowc11.dll

  In a text editor (such as Notepad), open C:\OWC11\AxOWC11.cs.</li>  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 { ... } </li>  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 { ... } </li> Save your changes to AxOWC11.cs.</li> 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%

</li> 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

</li> 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.</li></ol> </li> Start Visual Studio .NET.</li> 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.</li> On the .NET Framework Components tab, click Browse.</li> In the File name text box, type c:\owc11\axowc11.dll. Click Open.</li> Click OK to close the Customize Toolbox dialog box.</li></ol> </li></ol>

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 top

<div class="references_section">