[Partly Resolved] DLL Problem...
I want to create a DLL that any program can access.
I've had a look through the search and i've only found a few answers to my question...
First of all i found out that it needs to be an ActiveX DLL Project.
So i created one and put the following code into it.
VB Code:
Public Function Add_Numbers(Number1 As Integer, Number2 As Integer) As Integer
Add_Numbers = Number1 + Number2
End Function
I compiled the DLL and placed it in the Visual Basic main directory.
I then created another project and put this code into it
VB Code:
Private Declare Function Add_Numbers Lib "TestDll.dll" (Number1 As Integer, Number2 As Integer) As Integer
Private Sub Form_Load()
MsgBox Add_Numbers("7", "8")
End Sub
When i start the project it comes up with the following error
"Can't find DLL entry point Add_Numbers in TestDll.dll"
From what i can tell, it can't find the function that i placed into the dll.
I need to know what i'm doing wrong, wether i've created the dll the wrong way (so that the function is not in some way accessable outside the dll) or if i'm calling it incorrectly.
I've had a few goes at acreating ActiveX ocx files and i know that all the functions methods, properties, subs etc i wanted other programs to have access to i had to tell visual basic manually (i used a wizard when creating).
Can some one tell me what's going on, or point me in the right direction, without referecing... or is that impossible?
Re: [Partly Resolved] DLL Problem...
@Slyke (and everybody else):
declaring object variable as New is bad habit i VB6 and here's why:
it does NOT create new instance until you actually access one of the object's properties/methods (in your case object is created when you did MyDLL.Add_Numbers). So, what you do instead is something like the following:
VB Code:
Dim MyDLL As TestDLL.Class1
Set MyDLL = New TestDLL.Class1 'this creates new instance of an object immediately
MsgBox MyDLL.Add_Numbers(7, 8)
Re: [Partly Resolved] DLL Problem...
Ok, will do. Is it destroyed when the sub finishes? Or does it still linger around in the memory?
Re: [Partly Resolved] DLL Problem...
Hi,
sorry for butting in here when you are already being given good advice from the others..
but, when you sort vb dll and are finally ok with it you might like to look at the following URL
http://www.windowsdevcenter.com/pub/...reate_dll.html
I found it interesting - it takes you thru the process of turning a VB activex dll into a standard windows dll by hooking into the linker/compiler options and adding the relevant entry points manually.
I wouldn't try it till familiar with the normal vb ones though or it might get a bit confusing, but it does work..
Cheers AJP
>>Is it destroyed when the sub finishes? Or does it still linger around in the memory?
dll's are loaded into the memory space of the program that calls it. when the calling program is dropped, so is the dll.
:)
Re: [Partly Resolved] DLL Problem...
Quote:
Originally Posted by Slyke
Ok, will do. Is it destroyed when the sub finishes? Or does it still linger around in the memory?
That depends on the scope of your variable but in any case you may always set it to Nothing explicitly so all references will be destroyed:
Set MyObjVar = Nothing