HOWTO: Implement Additional Interfaces in an ActiveX Control
ID: Q186914
|
The information in this article applies to:
-
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, versions 5.0, 6.0
SUMMARY
This article demonstrates how to implement an additional interface in a
Visual Basic ActiveX control. ActiveX EXE and DLL components are better
suited for this purpose, but it may be desirable, for example, to implement
a custom interface that is present in all of your ActiveX controls. That is
the approach taken in the example shown in this article.
MORE INFORMATIONStep-by-Step Example
- Start a new ActiveX DLL project in Visual Basic. Change the name of the
project to BaseClass. Change the name of Class1 to CustomInterface.
Insert the following code into the CustomInterface class module:
Public Function testCustomInterface()
End Function
- On the File menu, click Add Project to add a new ActiveX Control
project. Click References on the Project menu, and check the reference
to BaseClass. Insert the following code into the General Declarations
section of the UserControl's code module:
Implements BaseClass.CustomInterface
Private Function CustomInterface_testCustomInterface() As Variant
CustomInterface_testCustomInterface = _
"Custom Interface test successful."
End Function
Public Function testStandardInterface() As Variant
testStandardInterface = "Standard Interface test successful."
End Function
- Change the name of the project to interfacesControl. Click Add Project
on the File menu to add a new Standard EXE project. Right-click on
Project1 in the Project window and select the Set as Start Up option.
- On the Project menu, click References, and then check the reference to
BaseClass. Place the UserControl (interfacesControl) on Form1. Add a
CommandButton to Form1.
- Insert the following code into the General Declaration section of
Form1:
Private Sub Command1_Click()
Debug.Print Me.UserControl11.testStandardInterface
Dim obj As BaseClass.CustomInterface
Set obj = Me.UserControl11.Object
Debug.Print obj.testCustomInterface
End Sub
- Run the project, click Command1 and note that both interfaces responded
in the Immediate Window,.
Additional query words:
kbDSupport kbDSD kbActiveX kbClientServer kbVBp500 kbVBp600
Keywords : kbGrpVB
Version :
Platform : WINDOWS
Issue type : kbhowto
|