Written by: Harris Phram

Participates: Patty Buchanan and Tom Curry

 

 

VIII. Registering COM Objects in Visual BasicRegistering COM Objects in Visual Basic 5.0 or 6.0

In order to have the DirectX7 program work under the launcher, it must be registered in the registry. The following program based upon the DirectX Documentation is an example of how to register and unregister these programs using the functions in the DirectX 7 for Visual Basic Type Library.

Step 1

Create a VB project and add the resource for the DirectX 7 for Visual Basic Type Library as instructed in the section on How to Compile A DirectX Application with Visual Basic 5.0 or 6.0.

Step 2

Create a form with three command buttons on it. One to register the program, one to unregister the program and one to exit the program.

Step 3

Below is a listing of VB code using the DirectX 7 library.

General Declarations

Dim dx As New DirectX7

Dim dpl As DirectPlayLobby3

Const AppGuid = "{EB5E7E20-0303-11d3-9AAB-00104BCC1EAA}"

 

Private Sub cmdExit_Click()

Unload Me

End

End Sub

Private Sub cmdRegister_Click()

Call RegisterApp

End Sub

Private Sub RegisterApp()

Dim dpappdesc As DPAPPLICATIONDESC2

Dim dpl As DirectPlayLobby3

With dpappdesc

.strApplicationName = "DXVBCHAT"

.strCommandLine = ""

.strCurrentDirectory = App.Path

.strDescription = "Chat (DirectX for Visual Basic)"

.strFilename = "DXVBChat.exe"

.strGuid = AppGuid

.strPath = App.Path

End With

On Local Error GoTo ERRORS

Set dpl = dx.DirectPlayLobbyCreate

Call dpl.RegisterApplication(dpappdesc)

Exit Sub

ERRORS:

MsgBox "Failed to register application."

Unload Me

End Sub

Private Sub cmdUnRegister_Click()

Call UnregisterApp

End Sub

Private Sub UnregisterApp()

On Local Error GoTo FAILED

Call dpl.UnregisterApplication(AppGuid)

MsgBox "Unregistration successful."

Exit Sub

FAILED:

If Err.Number = DPERR_UNKNOWNAPPLICATION Then

MsgBox "Application not registered."

End If

Unload Me

End Sub

 

Next Page

Index