|
-
Mar 4th, 2011, 07:59 AM
#1
Thread Starter
Junior Member
[RESOLVED] DLL + VB6 + Global variables + ByRef
Hi everyone,
I have declared some global variables in one of my class module of my DLL ActiveX VB6 project.
I can access those global variables in a client VB6 project referencing the DLL but the "ByRef" mechanism does not work. I mean that a global variable from the DLL passed by reference in a function of the client VB6 project does not keep value affected in the function after its execution.
Could someone help me please ?
-
Mar 4th, 2011, 08:13 AM
#2
Re: DLL + VB6 + Global variables + ByRef
VB6 Library
If I helped you then please help me and rate my post!
If you solved your problem, then please mark the post resolved
-
Mar 4th, 2011, 08:15 AM
#3
Re: DLL + VB6 + Global variables + ByRef
First of all, you cannot have a 'Global' variable in a class module. If you meant
a Public variable in a class module, it is the same as a Public Property, without
any error checking. In other words, in a class module:
is the same as:
Code:
Private mFoo As Long
Public Property Get Foo() As Long
Foo = mFoo
End Property
Public Property Let Foo(NewVal As Long)
mFoo = NewVal
End Property
Although VB allows Global variables in a Bas Module, it is the same as Public.
Perhaps you could show some code in the relevant modules.
-
Mar 4th, 2011, 08:31 AM
#4
Thread Starter
Junior Member
Re: DLL + VB6 + Global variables + ByRef
Ok.
My DLL ActiveX VB6 project is made up of class modules including a class module containing only global variables. Here is a declaration of one of those global variables :
Code:
Public glngSociete As Long
For information, the class module Instancing property is GlobalMultiUse.
My Exe standard VB6 project references the DLL created from the DLL ActiveX VB6 project. My Exe standard VB6 project contains forms, modules and class modules. In one module, I call a function with the global variable mentionned above as a "ByRef" parameter. Here is the call of the function :
Code:
intResult = Decryptage_Cle_Validation(strCleValid, _
glngNumeroLicence, _
glngNumeroPilote, _
dtmDateValid, _
dtmDateValidTemp, _
gintConnexionsMaxi, _
gblnLicenceEducation, _
gblnMaintenance, _
glngSociete, _
tblnOptions(), _
lngOptions, _
lngCleControle)
Here is the prototype of Decryptage_Cle_Validation :
Code:
Public Function Decryptage_Cle_Validation(ByVal vstrCleValid As String, _
ByRef lngLicence As Long, _
ByRef lngPilote As Long, _
ByRef dtmDateValid As Date, _
ByRef dtmDateValidTemp As Date, _
ByRef intConnexions As Integer, _
ByRef blnEducation As Boolean, _
ByRef blnMaintenance As Boolean, _
ByRef lngSociete As Long, _
ByRef tblnOptions() As Boolean, _
ByRef lngOptions As Long, _
ByRef lngCleControle As Long) As Integer
The parameter lngSociete matches with the global variable glngSociete. In Decryptage_Cle_Validation, I assign a value to lngSociete as following :
Code:
lngSociete = lngValeur
Let consider that glngSociete is equal to 5 before the call to the Decryptage_Cle_Validation function and we assign lngSociete to 10 (i.e. the value contained in lngValeur) then glngSociete is still equal to 5 when the execution goes back to the calling function.
Before I created the DLL, the global variable glngSociete was present in the Exe standard VB6 project and there was no problem.
Thanks in advance for your help.
-
Mar 4th, 2011, 08:51 AM
#5
Re: DLL + VB6 + Global variables + ByRef
Sounds like you have two variables called glngSociete. One in the exe and one in the dll. I bet you will solve your problem if you change Public glngSociete to a property.
VB6 Library
If I helped you then please help me and rate my post!
If you solved your problem, then please mark the post resolved
-
Mar 4th, 2011, 08:51 AM
#6
Re: DLL + VB6 + Global variables + ByRef
Before I created the DLL, the global variable glngSociete was present in the Exe standard VB6 project and there was no problem.
Present where? In a module, not a class? Correct?
As mentioned by VBClassicRocks, public variables in classes are actually properties. When code runs, VB creates a Public Let & Public Get statement, behind the scenes, for those variables. Understanding that, when you pass the variable to a function, you are passing it ByVal in reality. If you want the values to change, pass the class to your function, then within the function, use/update the class public variable.
If the class you created has its instancing property set to GlobalMultiUse then don't pass the class or public variables at all. Just use them, directly, within the function. GlobalMultiUse classes are public to the entire project.
Tags for this Thread
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
|