Page 1 of 1
Passing all variables between Dinosaurs VB6 to Baby PB
Posted: Wed Sep 29, 2010 3:46 pm
by Kwai chang caine
Hello
Welcome in the new club of the dinosaurs users of VB6 !!!
Since several years, i try to passing all style of variables between PB and VB.
It's not simple for KCC, because VB not managing his variables like C and PB
He use BSTR, UNICODE ans SAFEARRAY
KCC have not big knowledge.. before he was helped by his MASTER...but now...his MASTER is tired to help KCC
Perhaps he don't like whirligig.....and KCC is the king for turned round..
But i thanks him when even, for all his help since several month....
So, perhaps a day ...a member need to do this, and be happy to find this tips, and not eat all his fingers to the bone
..........................................................................
.............................. THE STRINGS ..........................
..........................................................................
Passing a VB6 string by reference (Method allocate string by VB)
VB6 code
Code: Select all
Private Declare Sub GetMessage Lib "Fonctions.dll" (ByRef Chaine As String)
Private Sub Form_Load()
Test
End Sub
Sub Test()
ChDrive (Left(App.Path, 1))
ChDir App.Path
Dim Chaine As String
Chaine = String(255, vbNullChar)
GetMessage Chaine
MsgBox "Longueur de la chaine = " + Str(Len(Chaine)) + Chr(13) + Chaine
End Sub
PB code
Code: Select all
ProcedureDLL GetMessage(*chaine)
a$ = "Hello World !"
CopyMemory(@a$, PeekL(*chaine), Len(a$))
EndProcedure
Passing a VB6 string by value (Method allocate string by VB)
VB6 code
Code: Select all
Private Declare Sub GetMessage Lib "Fonctions.dll" (ByVal Chaine As String)
Private Sub Form_Load()
Test
End Sub
Sub Test()
ChDrive (Left(App.Path, 1))
ChDir App.Path
Dim Chaine As String
Chaine = String(255, vbNullChar)
GetMessage Chaine
MsgBox "Longueur de la chaine = " + Str(Len(Chaine)) + Chr(13) + Chaine
End Sub
PB code
Code: Select all
ProcedureDLL GetMessage(*chaine)
a$ = "Hello World !"
CopyMemory(@a$, *chaine, Len(a$))
EndProcedure
Re: Passing all variables between Dinosaurs VB6 to Baby PB
Posted: Wed Sep 29, 2010 3:47 pm
by Kwai chang caine
Reserved
VB6 code
PB code
Re: Passing all variables between Dinosaurs VB6 to Baby PB
Posted: Wed Sep 29, 2010 3:48 pm
by Kwai chang caine
..............................................................................
...................... THE STRUCTURE (UDT) ..........................
..............................................................................
Passing a structure with three differents elements (Method VB allocate string)
VB6 code
Code: Select all
Private Declare Sub InitData Lib "Fonctions.dll" (Donnees As TDATA)
Private Type TDATA
x As Integer
y As Long
strVariable As String
End Type
Private Sub Form_Load()
Test
End Sub
Sub Test()
ChDrive (Left(App.Path, 1))
ChDir App.Path
Dim Donnees As TDATA
Donnees.strVariable = Space(30)
InitData Donnees
MsgBox "x = " + Str(Donnees.x) + Chr(13) + "y = " + Str(Donnees.y) + Chr(13) + "Len of sentence = " + Str(Len(Donnees.strVariable)) + Chr(13) + Donnees.strVariable
End Sub
PB code
Code: Select all
Structure DataPb
x.i
y.l
strVariable.s
EndStructure
ProcedureDLL InitData(*Variable.DataPb)
NewStrVariable$ = "String of lenght variable"
*Variable\x = 15
*Variable\y = 52445
CopyMemory(@NewStrVariable$, @*Variable\strVariable, Len(NewStrVariable$))
EndProcedure
Passing a structure of five differents elements (Method VB allocate string)
VB6 code
Code: Select all
Private Declare Sub InitData Lib "Fonctions.dll" (Donnees As TDATA)
Private Type TDATA
x As Integer
y As Long
reel As Double
strVariable As String
strFixe As String * 11
End Type
Private Sub Form_Load()
Test
End Sub
Sub Test()
ChDrive (Left(App.Path, 1))
ChDir App.Path
Dim Donnees As TDATA
Donnees.strVariable = Space(30)
Donnees.strFixe = Space(11)
InitData Donnees
MsgBox "x = " + Str(Donnees.x) + Chr(13) + _
"y = " + Str(Donnees.y) + Chr(13) + _
"Reel = " + Str(Donnees.reel) + Chr(13) + _
"String fixe = " + Donnees.strFixe + Chr(13) + _
"Len of sentence = " + Str(Len(Donnees.strVariable)) + Chr(13) + _
Donnees.strVariable
End Sub
PB code
Code: Select all
Structure DataPb
x.i
y.l
Reel.d
strVariable.s
strFixe.s{11}
EndStructure
ProcedureDLL InitData(*Variable.DataPb)
NewStrVariable$ = "String of lenght variable"
*Variable\x = 15
*Variable\y = 52445
*Variable\reel = 2459.65
CopyMemory(@"0123456789A", @*Variable\strFixe, SizeOf(*Variable\strFixe))
CopyMemory(@NewStrVariable$, @*Variable\strVariable, Len(NewStrVariable$))
EndProcedure
Re: Passing all variables between Dinosaurs VB6 to Baby PB
Posted: Wed Sep 29, 2010 3:48 pm
by Kwai chang caine
Reserved
VB6 code
PB code
Re: Passing all variables between Dinosaurs VB6 to Baby PB
Posted: Wed Sep 29, 2010 3:50 pm
by Kwai chang caine
Reserved
VB6 code
PB code
Re: Passing all variables between Dinosaurs VB6 to Baby PB
Posted: Wed Sep 29, 2010 4:02 pm
by Flower
I like your writing and posting style, KCC
I don't have VB6 installed at this time, but you could try some secret function called StrConv, StrPtr & CopyMemory
Some references here:
http://vb.mvps.org/tips/varptr.asp
(Declare Function is not necessary for XxxPtr on VB6)
Re: Passing all variables between Dinosaurs VB6 to Baby PB
Posted: Wed Sep 29, 2010 4:13 pm
by Kwai chang caine
The first member of my new club wrote:I like your writing and posting style, KCC
Thanks a lot FLOWER, and welcome in my new club
Take a drink...it's the house who pay to you

(Not fred ...not FRED

just little KCC :roll: )
Yeeeaaahh !!!!!
My first client a nice little flower
Can i put you, in a vase, for make my new THREAD CLUB more nice ????
Thanks a lot for your link

Re: Passing all variables between Dinosaurs VB6 to Baby PB
Posted: Fri Oct 01, 2010 1:54 pm
by Vitor_Boss®
Split strings
VB:
Code: Select all
Dim ExampleArray(0) As String
Dim Size As Integer
ExampleArray = Split("This|is|a|Split|Example", "|")
For Size = 0 to Ubound(ExampleArray) 'Size of array
Debug.Print ExampleArray(Size) & vbCrLf
Next
Output is:
This
is
a
Split
Example
PB:
Code: Select all
Procedure Split(Array Result.s(1), Expression.s, Delimiter.s,Limit.l=-1)
Protected C.w = 0
Protected Size.w = 0
Size=CountString(Expression,Delimiter)
If Size=0
ReDim Result(0)
Result(0) = Expression
Else
If Limit > 0 And Size > Limit-1
Size = Limit-1
EndIf
ReDim Result(Size)
For C = 0 To Size
Result(C) = StringField ( Expression, C+1, Delimiter ); Thanks to peterb
Next
EndIf
EndProcedure
Dim ExampleArray.s(0)
Dim Size.w
Split(ExampleArray(),"This|is|a|Split|Example", "|")
For Size = 0 to ArraySize(ExampleArray()) 'Size of array
Debug ExampleArray(Size) + Chr(10)+Chr(13) ; Thanks KCC
Next
Output is:
This
is
a
Split
Example
Re: Passing all variables between Dinosaurs VB6 to Baby PB
Posted: Fri Oct 01, 2010 2:20 pm
by peterb
to Vitor_Boss®: in PB exist function StringField
Code: Select all
text.s = "This|is|a|Split|Example"
delimiter.s = "|"
ubound = CountString ( text, delimiter )
Dim ExampleArray.s( ubound )
For c = 0 To ubound
ExampleArray( c ) = StringField ( text, c + 1, delimiter )
Debug ExampleArray( c )
Next
Re: Passing all variables between Dinosaurs VB6 to Baby PB
Posted: Fri Oct 01, 2010 2:39 pm
by Kwai chang caine
1 / Another thing, apparently since some version of PB, there is a problem to passing array with procedureDLL

So i think that perhaps your code risk to create bug ...
2 / And a little fix in your PB call
Code: Select all
Dim ExampleArray.s(0)
Define Size.w
Split(ExampleArray(),"This|is|a|Split|Example", "|")
For Size = 0 To ArraySize(ExampleArray()) ;Size of array
Debug ExampleArray(Size) + Chr(13)
Next
3 / In the VB code, it's interesting to see how you declare your DLL and the parameter BYVAL, BYREF, etc...
Because it's the more difficult to do
Thanks for your apport

Re: Passing all variables between Dinosaurs VB6 to Baby PB
Posted: Fri Oct 01, 2010 3:20 pm
by Vitor_Boss®
@peterb
I'm newer on PB and don't know about that.
Thank you for improve the code. This is the way.
@KCC
This thread is only to DLL like functions?
I'm sorry, I'm not an expert in VB6 programming.
Re: Passing all variables between Dinosaurs VB6 to Baby PB
Posted: Fri Oct 01, 2010 3:51 pm
by Kwai chang caine
Aaaaahhh !!!! yes i better understand now
You believe it's for converting VB code in PB or reverse
So it's also a good idea

, but not the first idea of this thread
Yes, it's for using VB6 and PB together, and for do that just one solution is possible, because VB don't know create standard DLL.
Create PB exe.....create VB exe....and create PB Dll for working with the both applications
I'm sorry, I'm not an expert in VB6 programming.
With me...we are two

Re: Passing all variables between Dinosaurs VB6 to Baby PB
Posted: Fri Oct 01, 2010 6:27 pm
by Vitor_Boss®
The title of this thread isn't specific for that.
Sorry but I read "Passing all variables between Dinosaurs VB6 to Baby PB" and not "Passing all variables from DLL between Dinosaurs VB6 and Baby PB"

Re: Passing all variables between Dinosaurs VB6 to Baby PB
Posted: Sat Oct 02, 2010 6:27 am
by Kwai chang caine
But what is the variable you passing
between VB and PB in your code ????
You pass variable PB to a procedure PB and VB to a procedure VB, but never a variable PB to a procedure VB, or a variable VB to a procedure PB.
It's that
BETWEEN VB and PB
In fact it's not really forced to use DLL....
There are several method to passing variables between EXE (Pb or VB)
Pipe, Shared memory, and other....
If you have this style of code it's really interesting too
The important things it's that a variable (Array, Udt...) is in VB and go to PB exe or dll..
Or a Variable is in PB and go to a VB exe...(Not Dll because VB6 DLL are activex, and not interesting...for me)
And the miracle.....it's variables (UDT, ArrayString, String....) is in VB, go to PB ...
is modify by PB..and return to VB....
Since one year, i try to do this correctly and there are always a problem
I have use several method and never can finish one perfectly
SROD found always a problem in my code....often with the VB <===> PB
