Melody's VSTA Blog

Get the latest and greatest information on VSTA here! Find new samples, workarounds, and inside tips in our downloads and blogs. Get your questions answered quickly in our forums or search our site for a FAQ. We're here to help- just ask.

Events in VSTA Part I: Declaring Non-Custom Events to Expose

To declare non-custom events to expose to VSTA is fairly straight forward in C#.  For Visual Basic, the events should* be declared explicitly (for more information on using implicitly declared events, see the workaround).  This is because VB hides implementation for implicitly declared events and creates a hidden nested event handler class.  Since ProxyGen v 2 does not support nested types, this causes problems.  Below is an example showing an explicitly and implicitly declared non-custom event in VB as well as, the error and descriptor file produced by ProxyGen when this implicitly declared event is exposed.  Notice the delegate in the descriptor file ImplicitEventEventHandler, which VB hides as a nested type.  To avoid these problems, declare events explicitly.

Example explicit and implicit declaration of an event:
Public Class Application
   'OK
   Public Event ExplicitEvent As System.EventHandler  

   'Creates hidden nested type
   Public Event ImplicitEvent(ByVal sender As Object, ByVal e As System.EventArgs)
End
Class
 

ProxyGen warning when creating descriptor file:
ProxyGen.exe Error: 11110 : Cannot generate a proxy for the following types, bec
ause they contain an inner type. ProxyGen does not support nested types. In the
XML descriptor file, nested types are extracted from the outer type and marked a
s excluded. To generate proxy code for these types, you must modify the XML desc
riptor file.
    EventApp_VB.Application
    EventApp_VB.Application.ImplicitEventEventHandler
ProxyGen.exe Information: 0 : Finished
ProxyGen.exe Information: 0 :   1 Errors
 

ProxyGen descriptor file output:
<Class originalFullyQualifiedName="EventApp_VB.Application" isExcluded="false" isAddInEntryPoint="false">
  
<
Event originalName="ExplicitEvent" isExcluded="false">
 
    <
Type>
         <
ExternalTypeReference isInterface="false" type="System.EventHandler" />
     
</
Type>
   </
Event>
   <Event originalName="ImplicitEvent" isExcluded="false">
     
<
Type>
         <
TypeReference type="EventApp_VB.Application.ImplicitEventEventHandler" />
     
</
Type>
   </
Event>
</Class> 
<
Delegate originalFullyQualifiedName="EventApp_VB.Application.ImplicitEventEventHandler" newName="Application_ImplicitEventEventHandler" isExcluded="true" newNamespace="EventApp_VB">
  
<
Parameter originalName="sender">
     
<
Type>
         <
ExternalTypeReference isInterface="false" type="System.Object" />
  
   </
Type>
   </
Parameter>
   <
Parameter originalName="e">
     
<
Type>
         <
ExternalTypeReference isInterface="false" type="System.EventArgs" />
     
</
Type>
   </
Parameter>
   <
Type>
      <
ExternalTypeReference isInterface="false" type="System.Void" />
  
</
Type>
</
Delegate
>

* Updated to reflect workaround for nested types, including the hidden types created to handle implicitly declared events.  For more information, see Nested Types in VSTA v 2 Part II:  VB Implicitly Declared Events.

Published Tuesday, May 06, 2008 11:14 AM by Melody

Comments

  • No Comments
Anonymous comments are disabled