|
-
Jun 11th, 2006, 03:19 PM
#1
Thread Starter
Fanatic Member
[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?
Last edited by Slyke; Jun 11th, 2006 at 03:45 PM.
-
Jun 11th, 2006, 03:23 PM
#2
PowerPoster
Re: DLL Problem...
Dunno if this is the issue, but you call "MsgBox Add_Numbers("7", "8")" when you've assigned them as integer
Try MsgBox Add_Numbers(7, 8)
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Jun 11th, 2006, 03:25 PM
#3
Re: DLL Problem...
That not how you use a VB dll. A VB dll is an ActiveX dll not a windows dll. You call a VB dll from your program just as you would a regular subroutine aside from that you just need to set a reference to it in your program first.
-
Jun 11th, 2006, 03:26 PM
#4
Thread Starter
Fanatic Member
Re: DLL Problem...
 Originally Posted by smUX
Dunno if this is the issue, but you call "MsgBox Add_Numbers("7", "8")" when you've assigned them as integer
Try MsgBox Add_Numbers(7, 8)
Same error, shouldn't it come up with type mismatch or somthing lol?
And what do you mean that's not how you create a vb dll? Is there a another type? Yes, i want to call it like a function.
-
Jun 11th, 2006, 03:27 PM
#5
Re: DLL Problem...
ActiveX dll and standard dll work different.
While you declare function/sub from standard dll you are required to set references to an ActiveX dll.
So, go to your project's refences and point to that dll first.
Then declare object variable as YourDll.YourClass so you may access any public method from that class.
Let me know if you need some code snippet.
-
Jun 11th, 2006, 03:30 PM
#6
Thread Starter
Fanatic Member
Re: DLL Problem...
Yeah, i will i can't find anything apart from ActiveX DLL projects There is no Standard DLL project i'm not sure if VB came with it, i have VB 2005 as well. Some code would help alot thanks.
-
Jun 11th, 2006, 03:36 PM
#7
PowerPoster
Re: DLL Problem...
I'm probably going to need to learn all this too...I've never made my own DLLs before and I plan to do so in my "pet project" :-)
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Jun 11th, 2006, 03:36 PM
#8
Re: DLL Problem...
ActiveX dll only - so go ahead and set refences as we suggested.
-
Jun 11th, 2006, 03:44 PM
#9
Thread Starter
Fanatic Member
Re: DLL Problem...
ok, will do.
I need to do something like...
VB Code:
Private Sub Form_Load()
Dim MyDLL As New TestDLL.Class1
MsgBox MyDLL.Add_Numbers(7, 8)
End Sub
(The TestDLL is the DLL's project name, not the DLL's file name).
After adding it to the references.
Which gives the result 15.
Thanks!
Last edited by Slyke; Jun 11th, 2006 at 03:47 PM.
-
Jun 11th, 2006, 04:00 PM
#10
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)
-
Jun 11th, 2006, 10:14 PM
#11
Thread Starter
Fanatic Member
Re: [Partly Resolved] DLL Problem...
Ok, will do. Is it destroyed when the sub finishes? Or does it still linger around in the memory?
-
Jun 12th, 2006, 07:55 AM
#12
Hyperactive Member
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.
Intel 486dx3 - VB4 - DR-Dos - 2mb EdoRam - 2x CDrom drive - Window for Workgroups - CGA monitor
Real programmers use less....
-
Jun 12th, 2006, 08:34 AM
#13
Re: [Partly Resolved] DLL Problem...
 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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|