Microsoft KB Archive/184322

= BUG: Error "438" When Implementing Base Class in ActiveX Exe =

Article ID: 184322

Article Last Modified on 5/13/2003

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 5.0 Control Creation Edition

-



This article was previously published under Q184322



SYMPTOMS
If you late-bind to an ActiveX EXE that contains a derived class that implements a base class, you receive the following error when trying to use a method or property of that base class:

Run Time Error "438"

Object Doesn't Support This Property Or Method



RESOLUTION
Use early binding or put the base and derived classes into an ActiveX DLL.



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



Part 1
 Start a new ActiveX EXE Project in Visual Basic. Form1 is created by default. On the Project menu, click Project1 Properties, and change the name of the ActiveX EXE project to "OutProcServer." Add two additional class modules to the Project. Name the existing three class modules as follows:

clsBase

clsDerived

clsStarter  Paste the following code into the clsBase module: Property Get MyFirstProperty As String End Property

  Paste the following code into the clsDerived module: Implements clsBase

Private Property Get clsBase_MyFirstProperty As String clsBase_MyFirstProperty = "Hello from MyFirstProperty!" End Property

  Paste the following code into the clsStarter module : Public Function CreateDerivedClass As clsBase Set CreateDerivedClass = New clsDerived End Function

</li> Save the ActiveX EXE project, and then compile it.</li></ol>

Part 2
<ol> Create a new Standard EXE project. Form1 is created by default.</li> On the Project menu, click References, then select "OutProcServer," which is the server that was just compiled step 7 of Part 1 above.</li> Add two Command Buttons to Form1 (Command1 and Command2).</li>  Paste the following code into the code module of Form1: ' Early bound object references. Dim oEarlyStarterClass As OutProcServer.clsStarter Dim oEarlyDerivedClass As OutProcServer.clsBase

' Late bound object references. Dim oLateStarterClass As Object Dim oLateDerivedClass As Object

Private Sub Command1_Click

' Create an instance of the out-proc server starter class object. Set oEarlyStarterClass = New clsStarter

' Now that there is a reference to the starter class object; use ' this object to return an instance of the derived class, which ' implements the base class declared in the out-proc server. Set oEarlyDerivedClass = oEarlyStarterClass.CreateDerivedClass

' Show the object type of the newly created object returned ' from the starter class object; it will be the derived class. MsgBox "oEarlyDerivedClass Is Of Type : " & _ TypeName(oEarlyDerivedClass)

' To prove that an instance of the derived class was successfully ' created, call the base class's interface, which the derived ' class implemented. MsgBox oEarlyDerivedClass.MyFirstProperty

' Destroy our objects. Set oEarlyDerivedClass = Nothing Set oEarlyStarterClass = Nothing

End Sub

Private Sub Command2_Click

' Create an instance of the out-proc server starter class object ' late-bound. Set oLateStarterClass = CreateObject("OutProcServer.clsStarter")

' Create a late-bound instance of the derived class. Set oLateDerivedClass = oLateStarterClass.CreateDerivedClass

' The first test is to show the type of the object that was just ' created through the starter class object. The MsgBox will show ' the correct value; which is the derived class, and not the base ' class. MsgBox "oLateDerivedClass Is Of Type : " & _ TypeName(oLateDerivedClass)

' Finally, try to call the property that the derived class ' has implemented. This will fail! MsgBox oLateDerivedClass.MyFirstProperty

End Sub

</li> Press the F5 key to run the project.</li> Click the Command1 button; this creates an instance of the "Starter Class." The Starter Class is used to create an instance of the derived Class. The Starter Class then checks to make sure that the proper class is being returned, and then calls the base class's property. This test uses early binding.</li> Click the Command2 button; similar to the Command1 button, the Command2 button creates an instance of the "Starter Class." This class then returns an instance of the derived class, then checks that that the proper object type is returned. Calling the base class property results in the 438 error. This second test uses late binding, and fails when it should succeed.</li></ol>

Additional query words: kbVBp500bug kbVBp600bug kbdss kbDSupport kbVBp kbActiveX

Keywords: kbbug kbpending KB184322

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.