FIX: WFC ActiveX Controls Do Not Fire Custom Events in VB

ID: Q223362


The information in this article applies to:


SYMPTOMS

When creating an ActiveX control using WFC, custom events are not fired in the target/client application.


STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

This bug was corrected in Visual Studio 6.0 Service Pack 3. For more information about Visual Studio service packs, please see the following articles in the Microsoft Knowledge Base:

Q194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why

Q194295 HOWTO: Tell That Visual Studio 6.0 Service Packs Are Installed


MORE INFORMATION

Steps to Reproduce Behavior

  1. Open a new Control project in Visual J++ 6.0.


  2. Create a simple control that includes a custom event as outlined in MSDN under the topic, "Creating a Custom Event."


  3. Build and deploy the control.


  4. Test the control in a Visual Basic application.


    1. Create a new Standard .exe project in Visual Basic.


    2. From the Project menu, click Components and add your new custom control to the project.


    3. In the Visual Basic designer, drag-and-drop the control onto the Visual Basic Form.


    4. From the code view, select the variable name for the control object (MyControl1 is the default) in the right-hand drop-down list and select the custom event in the left-hand drop-down list. This will cause Visual Basic to generate an outline for the custom event handler that will look something like this:


    5. 
      Private Sub MyControl1_errorEvent(ByVal Parameter0 As Object, ByVal Parameter1 As Object)
      
      End Sub 
      Do the same for the Form Load event and insert code that will cause your custom event to fire. The following code handles the MSDN errorEvent sample mentioned below. It should look something like this:
      
      Private Sub Form_Load()
      MyControl1.myProp = 201
      End Sub 
      Notice that the custom event doesn't get fired whenever the myProp property value exceeds 200.
For convenience, here is the code pasted from the MSDN documentation:

 // MyControl.java
import com.ms.wfc.ui.* ;
import com.ms.wfc.core.* ;
import com.ms.lang.Delegate;

/**
 * @com.register ( clsid=428B4065-E8B5-11D2-A801-00C04FB624C0, typelib=428B4064-E8B5-11D2-A801-00C04FB624C0 )
 */ 
public class MyControl extends Control 
{
  private int myProp = 1;
  public int getMyProp()
  {
    return myProp;
  }
  public void setMyProp(int value)
  {
    // Fires error event if property value exceeds 200
    if(value > 200)
    {
      onErrorEvent(new ErrorEvent(1020, "Invalid value"));
    }
    myProp = value;
  }

  protected void onPaint( PaintEvent p)
  {
    super.onPaint(p);
    Graphics g=p.graphics;
    g.drawString( getText(), 0, 0);
  }

  // event setup to be able to fire event "ErrorEvent"
  private ErrorEventHandler errDelegate = null;
  public final void addOnErrorEvent(ErrorEventHandler handler)
  {
    errDelegate = (ErrorEventHandler)Delegate.combine(errDelegate,
                                                      handler);
  }
  public final void removeOnErrorEvent(ErrorEventHandler handler)
  {
    errDelegate = (ErrorEventHandler)Delegate.remove(errDelegate,
                                                     handler);   
  }
  protected void onErrorEvent(ErrorEvent event)
  {
    if(errDelegate != null)
    {
      errDelegate.invoke(this, event);
    }   
  }
  
  public static class ClassInfo extends Control.ClassInfo
  {
    public static final PropertyInfo myProp = new 
                                              PropertyInfo(MyControl.class, "myProp", int.class);
    public void getProperties(IProperties props)
    {
      super.getProperties(props);
      props.add(myProp);
    }
    
    public static EventInfo evt = new EventInfo(MyControl.class, 
                                                "errorEvent", ErrorEventHandler.class);
    public void getEvents(IEvents events)
    {
      super.getEvents(events);
      events.add(evt);
    }
  }
}

// ErrorEventHandler.java
import com.ms.wfc.core.*;
public final multicast delegate void ErrorEventHandler(Object sender, 
  ErrorEvent event)
;

// ErrorEvent.java
import com.ms.wfc.core.*;
public class ErrorEvent extends Event
{
  public final int errorNumber;
  public final String errorText;
  public ErrorEvent( int eNum, String eTxt)
  {
    this.errorNumber = eNum;
    this.errorText   = eTxt;
  }
} 


REFERENCES

For the latest Knowledge Base articles and other support information on Visual J++ and the SDK for Java, please see the following pages on the Microsoft Technical Support site:

http://support.microsoft.com/support/visualj/

http://support.microsoft.com/support/java/

© Microsoft Corporation 1999, All Rights Reserved.
Contributions by Robert LaCasse, Microsoft Corporation

Additional query words:


Keywords          : kbservicepack kbCOMt kbCtrlCreate kbJava kbJavaVM kbSDKJava kbVJ600bug kbGrpJava kbVS600sp2 kbVS600SP1 kbVS600sp3fix 
Version           : WINDOWS:3.1,6.0
Platform          : WINDOWS 
Issue type        : kbbug 

Last Reviewed: July 13, 1999