|
-
Sep 26th, 2000, 01:14 AM
#1
I have been programming for several years now, and i think myself, that I'm getting better and better all the time. Now. My apps are getting better and more advanced all the time, and therefore I would like to move some of the common procedures and commonly used forms etc. to DLL-files. Does anyone know how to do that in VB 6??
I want to fx. move my entire error handling system to a single DLL, so that I can distribute it along with the EXE...
Can anyone help me??
-
Sep 26th, 2000, 06:18 AM
#2
Member
Hello Henrik,
Actually it's very simple to make a DLL with VB5 or VB6.
Just make a new project of the "ActiveX DLL" type. You will now get a new project containing only one class.
In this class you can make for example one subroutine which generates a messagebox with an error message. You can use parameters to make the message fit any error.
A short sample could be:
Code:
Public Sub Generate_Error(Number As Long, Description As String, Source As String)
MsgBox "An error occurred. Details:" & vbCrLf & "Number: " & Number & vbCrLf & "Description: " & Description & vbCrLf & "Source: " & Source
End Sub
Give the Class module as sensible name, as you have to refer to it later (for example: clsErrorHandler).
If you compile this into a DLL then you can make a reference in an EXE project (Project -> References menu) to you DLL.
Now you declare the clsErrorHandler within the new project:
Code:
Public hdErrorHandler As New clsErrorHandler
Now you can call the object in each sub when an error occurs. Example:
Code:
hdErrorHandler.Generate_Error Err.Number, Err.Description, "Error happened in sub Main"
Hope this helps...
Hajo Dijkstra
-
Sep 26th, 2000, 07:04 AM
#3
Thank you very much
Thanks for the help! It was pretty much like I had figured out, although I couldn't get my app accept the subroutine, cause I called the DLL wrong.
Thanks again :-)
-
Oct 2nd, 2000, 08:00 AM
#4
It works fantastic now, but I still have a smaller problem with it :
I'm planning to distibute it along with all my apps for common use, but if I create an .EXE file, and then recompile the DLL, the EXE will not accept it!
Do I have to recompile all my apps every time i make a new version of my DLL-file??
If this is the case... Is there a better way of doing it???
-
Oct 2nd, 2000, 09:54 AM
#5
Member
It's possible without recompiling...
Hi,
Well, it is possible to have your EXE to accept the new DLL
without recompiling the EXE. To do this you have to do two
things:
First, you may not change the parameters or functions of
the DLL. If you do this, the EXE will crash when trying to
use the new compiled DLL.
Second, you have to set the "Version Compatibility" to
"Binary Compatibility" (see the project options, the
Component property page). This is for the DLL project!
(it's not even possible for an EXE if I remember correctly.)
If you follow both instructions your EXE should be able to
work with the new DLL without being recompiled.
Hope this helps.
Greetings,
-
Oct 3rd, 2000, 04:09 AM
#6
You mean, that I can't chance the NAME of the existing functions in the DLL? I suppose nothing will happen if a chance the code in the functions or add new functions then?
Parameters...hhmmm...Will it also crash, if I add extra parameters, just with the "Optional" statement in the end of the parameter list??
Thanks again
-
Oct 3rd, 2000, 04:23 AM
#7
Addicted Member
Well,
If you distribute your exe to a user, with the dll, the the user will always be able to use it. Now if you break compatibility by changing parameters listings or changing/deleting functions then as long as the user does not upgrade to your new dll, it will work for him/her.
If your dll were installed on a server and you brak compatibility, then all clients would crash.
Think of it as a contract, I give you 5 dollars and you give me 5 oranges, and that's it. Then you can't ask for money and a letter because is not in the contract. To add this parameter we need a new contract, ergo a new exe compiled against the new dll.
Compatibilty is not broken when you add functions,
you have to be careful with:
-Changing the names of methods properties etc. If you do, you will break compatibility
-Removing methods or properties.If you do, you will break compatibility
-Modifying the parameter list, If you do, you will break compatibility
-Changing datatypes of parameters or return values of functions.If you do, you will break compatibility
Hope this helps you on your quest to master dll's
André
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
|