Page 3 of 3
Posted: Thu Jun 04, 2009 8:19 am
by helpy
Posted: Sat Jun 06, 2009 6:29 pm
by Kwai chang caine
A kind programmer of VBForum give to me this solution in VB only.
He can't give me more, because he don't have PB
VB code
Code: Select all
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any , pSrc As Any , ByVal ByteLen As Long )
Private Sub Command1_Click()
Dim xs(2) As String
xs(0) = "Ligne 1"
xs(1) = "Ligne 2"
xs(2) = "Ligne 3"
'appel méthode magique simulant la dll PB
CloneStringArray VarPtr(xs(0)), UBound(xs)
End Sub
Is it possible to convert the code of this procedure in PB ??? :roll:
VB code to try to translate in PB
Code: Select all
Sub CloneStringArray(ByVal lhPointer As Long, ByVal lSize As Long)
Dim saNew() As String
ReDim saNew(lSize)
CopyMemory ByVal VarPtr(saNew(0)), ByVal lhPointer, 12
'test
Dim i As Integer
For i = LBound(saNew) To UBound(saNew)
Debug.Print i & ". '" & saNew(i) & "'"
Next i
End Sub
Posted: Sun Jun 07, 2009 7:31 pm
by thearr
Kwaï chang caïne wrote:A kind programmer of VBForum give to me this solution in VB only.
This won't help you. Your problem is you'd like to pass a Unicode string from VB (BSTR) to DLL, compiled in ANSI mode. So all you have to do is to convert Unicode to ANSI no matter where:
in VB:
thearr wrote:PostPosted: Thu Jun 04, 2009 12:03 am Post subject:
Code: Select all
MyArrayVB(0) = StrConv("one", vbFromUnicode)
MyArrayVB(1) = StrConv("two", vbFromUnicode)
or in PB for example like this (not tested):
Code: Select all
Procedure.s PeekBSTR(*BSTR)
lenBSTR=PeekL(*BSTR-4)/2
Dim Char.c(lenBSTR)
For i=0 To lenBSTR
Char(i)=PeekC(*BSTR+i*2)
Next i
ProcedureReturn PeekS(@Char(0))
EndProcedure
;Change MessageRequester(PeekS(MyArray(0)), PeekS(MyArray(1))) to
;MessageRequester(PeekBSTR(MyArray(0)), PeekBSTR(MyArray(1)))
Posted: Sun Jun 07, 2009 8:58 pm
by Kwai chang caine
Thanks thanks my savior THEARR
I have test quickly your solution, and i believe that's works
But it's too late in france for build all the code and tomorrow i go to work in five hour, and i have not again eat
So, tomorrow i build all the code and say you the result
I wish you a good night
But already i thanks you very much for your gold help

Posted: Mon Jun 08, 2009 10:36 am
by Kwai chang caine
Yes i have tested the code now, and obviously you are right

Now, i can import all my array thanks to you
8 day of search and try all the method, for just one function
It's very difficult to put VB and PB in the same room

They don't eat the same food, don't watch the same program TV, no sleep at the same time
You never know, how your help is precious for me

So i say to my son......who say later at his son......who is THEARR ......one of my heroes and savior of KCC
I wish you...a very very very good day.
Posted: Mon Jun 08, 2009 4:34 pm
by Kwai chang caine
I know i know....you say KCC is very a mule
But for good understand, i try to convert the BSTR in the VB and not in the PB.
That's works nearly fine.
I don't know why there are a chr(0) under each bit in VB ????
Then i have delete it, and find, that the record of each array, finish by two chr(0)
What is your mind about this ??? :roll:
VB code
Code: Select all
Private Declare Function FenetreTexte Lib "MyDll.dll" (Titre As String, Texte As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As _
Any, source As Any, ByVal bytes As Long)
Function PointerFromBSTR(ByVal pointer As Long) As Long
Dim temp As String, Longueur As String
' copy the pointer into the temporary string's BSTR
CopyMemory ByVal VarPtr(temp), pointer, 4
' now Temp points to the original string, so we can copy it
PointerFromBSTR = StrPtr(temp)
' manually clear then temporary string to avoid GPFs
CopyMemory ByVal VarPtr(temp), 0&, 4
End Function
Private Sub Form_Load()
Dim TabloVB(15) As String
TabloVB(1) = "Hello...i'm KCC"
TabloVB(2) = "i'm locked in VB :-("
TabloVB(3) = "and i want to jump in PB :-)"
TabloVB(4) = " "
For i = 5 To 14
TabloVB(i) = "Line " + Str(i)
Next
Pb Code
Code: Select all
ProcedureDLL FenetreTexte(Titre.s, *AdresseTablo)
Dim MyArray.l(1)
SizeOfArray.l = PeekL(*AdresseTablo)
ReDim MyArray.l(SizeOfArray)
CopyMemory(*AdresseTablo, @MyArray(), SizeOfArray * 4)
For i = 1 To SizeOfArray - 1
Mot$ = ""
Zero = 0
For o = 0 To 1000
b = PeekB(MyArray(i) + o)
If b <> 0
Mot$ + Chr(b)
Zero = 0
ElseIf b = 13 Or zero = 2
Break
Else
Zero + 1
EndIf
Next
MessageRequester("C'est magique, m'vl'a dans la DLL", Mot$)
Next
EndProcedure
Posted: Mon Jun 08, 2009 5:30 pm
by Demivec
Kwaï chang caïne wrote:I know i know....you say KCC is very a mule
But for good understand, i try to convert the BSTR in the VB and not in the PB.
That's works nearly fine.
I don't know why there are a chr(0) under each bit in VB ????
Then i have delete it, and find, that the record of each array, finish by two chr(0)
What is your mind about this ??? :roll:
Sounds like Unicode.
Posted: Tue Jun 09, 2009 6:58 am
by Kwai chang caine
Hello DEMIVEC
You mean that the UNICODE is like that???
I don't understand anything
I have tested one of a element of the array, in VB, with the API
IsTextUnicode and the return is 0.
So why y have in the DLL a chr(0) between each bit ????
Posted: Tue Jun 09, 2009 8:53 am
by Demivec
Kwaï chang caïne wrote:I have tested one of a element of the array, in VB, with the API IsTextUnicode and the return is 0.
So why y have in the DLL a chr(0) between each bit ????
I thought you had meant that there was a zero "byte" between each character.
If you have tested it, and it was reported as "not unicode," then I guess it must be something else. Alas, it was my best quess.

Posted: Tue Jun 09, 2009 9:41 am
by Kwai chang caine
Yes it's exactly that.
In the code above
B, sometimes, in fact one time on two, is equal at 0

And i don't know why ???
I search a method in VB for not send this 0 :roll:
But apparently it's not easy
I go to create a new thread....perhaps someone have an idea ??? :roll:
Posted: Tue Jun 09, 2009 1:14 pm
by thearr
1. BSTR that is used in VB is always a Unicode string (each symbol is coded with 2 bytes). It also has 2 bytes of zeros at the end of the string for compatibility with WinAPI functions, that usually use null-terminated strings (PB uses them as well).
2.
Kwaï chang caïne wrote:I have tested one of a element of the array, in VB, with the API IsTextUnicode and the return is 0
How did you declare the function and use it?
3. If you'd like to convert strings to ANSI in VB, did you try internal VB functions the way I've posted:
Code: Select all
Dim TabloVB(15) As String
TabloVB(1) = "Hello...i'm KCC"
TabloVB(2) = "i'm locked in VB :-("
TabloVB(3) = "and i want to jump in PB :-)"
TabloVB(4) = " "
For i = 5 To 14
TabloVB(i) = "Line " + Str(i)
Next
'**********
For i = 1 to 14
TabloVB(i) = StrConv(TabloVB(i), vbFromUnicode)
Next
4. By the way your wish to convert initially Unicode strings to ANSI makes your program limited, as users may have problems with certain symbols, for ex. with Russian alphabet.
Posted: Tue Jun 09, 2009 4:15 pm
by Kwai chang caine
Thanks THEARR for your explanation
I'm tired of this history of UNICODE/ANSI, 2 byte, 4 byte, STR, BSTR....
Finally, i believe, i use the first method with the convert in the DLL.
It's more simple, and that's works.....
This is two reasons for use it
One thousand of thanks for your kindness, you have help me so much

Posted: Wed Aug 26, 2009 2:50 pm
by doctorized
I translate a code from VB 6.0 to PB 4.31.
Is there a way to translate:
"StrConv(ImgColor, vbUnicode)" with ImgColor byte array?