Microsoft KB Archive/328275

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

Article ID: 328275

Article Last Modified on 7/30/2003

-

APPLIES TO


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

-



This article was previously published under Q328275



IN THIS TASK
SUMMARY
 * Background
 * Steps to Modify and to Rebuild Class Wrappers

REFERENCES



SUMMARY
The default class wrappers that are generated by Microsoft Visual Studio .NET do not allow you to handle events for the Office XP Chart, Spreadsheet, and PivotTable Web components. To handle the events for these components, you can modify the source code for these class wrappers, and then recompile. This article describes how to modify and how to regenerate the class wrappers for the Office XP Web Components so that you can manage their events in a Visual Studio .NET application.

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 for the IDispatch interface, instead of 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 with the ClassInterfaceType.None value to force COM Interop to return IDispatch for the interface instead of for the class. The IDispatch interface does contain the event DISPIDs.

back to the top

Steps to Modify and to Rebuild Class Wrappers
NOTE: The steps in this article assume that you have installed the Microsoft Office XP Primary Interop Assemblies (PIAs). For additional information about the Office XP PIAs, click the article number below to view the article in the Microsoft Knowledge Base:

328912 INFO: Office XP PIAs Available for Download

 Start the Visual Studio .NET command prompt.  Create a new directory, and then change to that directory:   md c:\owc10 cd &quot;c:\owc10&quot;   Generate the source code for C# for the Windows forms wrapper:   aximp &quot;c:\program files\common files\microsoft shared\web components\10\owc10.dll&quot; /source   Delete the generated assembly AxOWC10.dll:   del c:\owc10\axowc10.dll  Open C:\OWC10\AxOWC10.cs in any text editor.</li>  Add [ToolboxItem(true)] to the generated class for the Chart, the Spreadsheet, and the PivotTable components. For example: [System.ComponentModel.ToolboxItem(true)] public class AxChartSpace : System.Windows.Forms.AxHost { ...   } -and- [System.ComponentModel.ToolboxItem(true)] public class AxSpreadsheet : System.Windows.Forms.AxHost { ...   } -and- [System.ComponentModel.ToolboxItem(true)] public class AxPivotTable : System.Windows.Forms.AxHost { ...   }                    </li>  Mark the event classes as ClassInterfaceType.None: [System.Runtime.InteropServices.ClassInterface(    System.Runtime.InteropServices.ClassInterfaceType.None)] public class AxChartSpaceEventMulticaster : OWC10.IChartEvents { ...   } -and- [System.Runtime.InteropServices.ClassInterface(    System.Runtime.InteropServices.ClassInterfaceType.None)] public class AxSpreadsheetEventMulticaster : OWC10.ISpreadsheetEventSink { ...   } -and- [System.Runtime.InteropServices.ClassInterface(    System.Runtime.InteropServices.ClassInterfaceType.None)] public class AxPivotTableEventMulticaster : OWC10.IPivotControlEvents { ...   }                    </li> Save your changes to AxOWC10.cs, and then return to the command prompt.</li>  Add &quot;C:\Program Files\Microsoft.NET\Primary Interop Assemblies&quot; to your LIB environment variable: <pre class="fixed_text">  set lib=c:\program files\microsoft.net\primary interop assemblies;%path% </li>  Copy Microsoft.Office.Interop.OWC.dll and MSComCtl.dll from the directory where you have installed the Microsoft Office XP Primary Interop Assemblies: <pre class="fixed_text">  copy c:\officexppias\microsoft.office.interop.owc.dll copy c:\officexppias\mscomctl.dll </li>  Compile the source file, AxOWC10.cs:  <pre class="fixed_text">  csc /t:library /r:microsoft.office.interop.owc.dll /r:adodb.dll /r:msdatasrc.dll /r:mscomctl.dll axowc10.cs NOTE: You receive warning CS0108, &quot;The keyword new is required&quot;.

You may ignore this error. </li> Start Visual Studio .NET.</li> Add your newly-compiled AxOWC10.dll to the toolbox: <ol style="list-style-type: lower-alpha;"> On the Tools menu, click Customize Toolbox.</li> On the .NET Framework Components tab, click Browse.</li> Type c:\owc10\axowc10.dll, and then click Open.</li> Click OK to dismiss the Customize Toolbox dialog box.</li></ol> </li></ol>

back to the top

<div class="references_section">