Microsoft KB Archive/223362

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

Article ID: 223362

Article Last Modified on 6/14/2006

-

APPLIES TO


 * Microsoft Visual J++ 6.0 Standard Edition
 * Microsoft Java Virtual Machine
 * Microsoft Software Development Kit for Java 3.1

-



This article was previously published under Q223362



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



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are 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:

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

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



Steps to Reproduce Behavior
 Open a new Control project in Visual J++ 6.0. Create a simple control that includes a custom event as outlined in MSDN under the topic, "Creating a Custom Event." Build and deploy the control. Test the control in a Visual Basic application.  Create a new Standard .exe project in Visual Basic. From the Project menu, click Components and add your new custom control to the project.</li> In the Visual Basic designer, drag-and-drop the control onto the Visual Basic Form.</li>  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: 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. </li></ol> </li></ol>

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; } }

<div class="references_section">