Visual Basic: Information and Guidelines
Here is a brief outline of the steps needed to build an OLE DB Simple Provider in Visual Basic.
Building a Simple Provider in Visual Basic 6
-
Start Microsoft Visual Basic. From the File menu, select New Project. The New Project dialog box appears. Use this dialog box to select the ActiveX DLL icon.
-
From the Project menu, select References. The References dialog box appears, listing the available references. Select the Microsoft OLE DB Simple Provider 1.5 Library check box.
When you select Object Browser from the View menu or press F2 to display the Object Browser dialog box, the classes OLEDBSimpleProvider and OLEDBSimpleProviderListener should appear in the Classes pane of the Object Browser. You can focus on these classes and their members by selecting MSDAOSP in the Project/Library list.
-
From the Project menu, select Add Class Module. The Add Class Module dialog box appears. Use this dialog box to select and open the Class Module icon. In the Procedure (Declarations) of the Object (General) inside the Code window, type the following as your first line of code:
Implements OLEDBSimpleProvider
-
Now you can develop your own simple provider class. Use the OSP language reference supplied with the Toolkit to implement all the OSP methods. You can view the sample code in the file MyOSPObject.cls as a reference.
-
You also need to add a Data Source class and its GetDataMember function. Add a second class to your project and in its Properties window, select DataSourceBehavior = "1 - vbDataSource". In the Object drop-down box, select Class. In the Procedure drop-down box, select GetDataMember. Implement the GetDataMember by using the DataMember input argument to determine a simple provider object to return. For example,
Private Sub Class_GetDataMember(Datamember As String, Data As Object)
Dim MyOSP As New MyOSPObject
Set Data = MyOSP
End Sub
-
From the File menu, select Make ProjectName.dll… to build and register your provider.
Registration
As part of the information required to register the provider, you need a ProgID for the OSP Data Object.
In Visual Basic, the ProgID is the project name followed by the name of the data source object class or control name on which the OSP Data Object is implemented. The two names are separated with a "." (period).
For example, suppose you have a project named "MyOSPProject", and a class that implements the msDataSourceObject method named "MyOSPClass". The ProgID will be "MyOSPProject.MyOSPClass". The Version-Independent ProgID will be " MyOSPProject.MyOSPClass.1".
Programming Notes for Visual Basic 5 Users
-
In Visual Basic 5 implementations, use msDataSourceObject and the appropriate IDispatch methods (such as Invoke) to expose the correct OSP implementation to the Simple Provider DLL (MSDAOSP.DLL).
-
When coding data source notifications in Visual Basic 5, use the addDataSourceListener and removeDataSourceListener methods with IDispatch.
-
Make sure to code the implementation for the addDataSourceListener method in your OSP Data Object. Implementing msDataSourceObject without implementing addDataSourceListener will result in a run-time error when your data source is being used.
-
For Visual Basic 5 users, Step 5 in the previous procedure is:
You also need to implement two data source functions. Add a second class module and implement msDataSourceObject and addDataSourceListener. For example:
Public Function msDataSourceObject(DataMember$)
AS OLEDBSimpleProvider
You can view the sample code in the file MyDataSource.cls as a reference.