Search Tools Links Login

Creating ActiveX DLL's

This Articles shows you how to create a Simple ActiveX DLL and reference it to your Project.

Original Author: Dan Wold


Creating ActiveX DLL's

Creating a simple ActiveX DLL

To create a simple ActiveX DLL to use with your program follow these instructions

Step 1: Open Visual Basic, For the New Project, Select "ActiveX Dll"
Step 2: Rename the Class Module "Class1" to "Math" You will be calling this class later.
Step 3: Goto the menu and select, Project > Project Properties
Step 4: Change the Project name to MathFuncDll
Step 5: Change the Project Description to "Simple Math Functions" And click "OK"
Step 6: In the Class Module (Math) Put the following code:

Option Explicit
Public Function Add(ByVal FirstNumber As Long, ByVal SecondNumber As Long)
Add = FirstNumber + SecondNumber
End Function

Public Function Subtract(ByVal FirstNumber As Long, ByVal SecondNumber As Long)
Subtract = FirstNumber - SecondNumber
End Function

Public Function Divide(ByVal FirstNumber As Long, ByVal SecondNumber As Long)
Divide = FirstNumber / SecondNumber
End Function

Public Function Multiply(ByVal FirstNumber As Long, ByVal SecondNumber As Long)
Multiply = FirstNumber * SecondNumber
End Function

Step 7: Now goto the menu "File > Make MathFuncDll.dll" And Compile your ActiveX dll

Congrats If it compiled correctly you have just created your first ActiveX Dll!

If it didnt compile make sure your code is exactly like mine..

Question: How do I use this ActiveX DLL now?
Answer: Follow the rest of the steps ;)

Step 8: Open a New Project, This time select a New "Standard EXE"
Step 9: Now goto menu "Project > References" And click "Browse"
Step 10: Now Browse for your Newly Created DLL And select it. Click "OK"
Step 11: Click "OK" Again to add the referance to your Project.
Step 12: Now in the Form Put the following Code:

Option Explicit
'Creates The Object Reference
Dim objNew As MathFuncDll.Math
Private Sub Form_Load()
  'Sets objNew to the new Object referance
  Set objNew = New MathFuncDll.Math
  MsgBox objNew.Add(2, 4)
  MsgBox objNew.Subtract(5, 3)
  MsgBox objNew.Multiply(5, 2)
  MsgBox objNew.Divide(10, 5)
End Sub

Step 13: Run your project.

 OK, Ok, Now your Probably wondering "HOW The Heck Did he referance that?" Well now.. After you 
added the DLL Into the Projects Refereances I called upon them by setting them to an Object. I.e:

Dim objNew As MathFuncDll.Math

That Refrenced objNew to the "Math" Class inside MathFuncDll.Dll

Set objNew = New MathFuncDll.Math

Created the Object Referance.
Now I called upon that referance by using objNew

MsgBox objNew.Add(2, 4)

MsgBox objNew.Subtract(5, 3)

MsgBox objNew.Multiply(5, 2)

MsgBox objNew.Divide(10, 5)

objNew.Subtract(FirstNumber,SecondNumber) AKA objNew.Subtract(5, 3)
This is My first tutorial, I know, I understand If you couldnt understand it... Err..
Anyways, Im not the best Tech Writer, Heck Im not a tech writer :P. But if you want an example feel free
to email me at E_MAN_DAN@HOTMAIL.COM

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 89 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.