How easy is it to create an ActiveX DLL with Visual Basic? If you can declare variables and write procedures, you can create an in-process component.
This section provides step-by-step instructions on how to define a simple class, and demonstrates the life cycle of objects provided by components. You can use objects created from this class with any application that can use Automation to control objects.
Note This topic is part of a series that walks you through creating a sample ActiveX DLL. It begins with the topic Creating an ActiveX DLL.
To create the ThingDemo project
The default value for the Instancing property is MultiUse. This allows clients to create multiple instances of the Thing class. For a full discussion of the Instancing property, see "Instancing for Classes Provided by ActiveX Components," in "General Principles of Component Design."
The project name, ThingDemo, is also used as the name of the component’s type library. It can be combined with the name of each class the component provides, to produce unique class names.
If two components each provide a Thing class, the fully qualified class name lets you specify which component’s Thing class you want to use, for example, ThingDemo.Thing
.
Note If you’ve used the Options dialog box (accessed from the Tools menu) to disable the Add Module dialog box, you’ll just get the module. This is okay.
Option Explicit
Public gdatServerStarted As Date
Sub Main()
' Code to be executed when the component starts,
' in response to the first object request.
gdatServerStarted = Now
Debug.Print "Executing Sub Main"
End Sub
' Function to provide unique identifiers for objects.
Public Function GetDebugID() As Long
Static lngDebugID As Long
lngDebugID = lngDebugID + 1
GetDebugID = lngDebugID
End Function
File | File name | Extension |
Module | ThingDemo_Module1 | .bas |
Class module | ThingDemo_Thing | .cls |
Project | ThingDemo | .vbp |
For More Information See "Choosing a Project Type and Setting Project Properties" in "General Principles of Component Design."
This topic is part of a series that walks you through creating a sample ActiveX DLL.
To | See |
Go to the next step | Creating Properties and Methods for the Thing Class |
Start from the beginning | Creating an ActiveX DLL. |