Passing VB Arrays

Just starting out? Need help? Post your questions and find answers here.
thearr
User
User
Posts: 21
Joined: Sun Apr 26, 2009 3:18 am
Location: RU

Post by thearr »

Kwaï chang caïne wrote:If you have the same code, who don't crash the RAD....i'm interesting :D
Because i prefer close the VB with the button "quit" :lol:
I haven't got the code, because I haven't got VB and can't test the code I post.

So, the next step: I think that the possible problem why VB crashes is that DLL tries to free memory, allocated for the array, after the procedure is done. You can test if it's so if you change a DLL code a little:

Code: Select all

ProcedureDLL MyFunctionPB(*ArrayFromVB)
 Dim MyArray.l(1)
 CopyMemory(*ArrayFromVB, @MyArray(), 2*4)
 MessageRequester(PeekS(MyArray(0)), PeekS(MyArray(1)))
EndProcedure
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

Kwaï chang caïne wrote:... since the beginning of the big adventure of "KCC in the land of the programming"
oh boy, why didn't you take the blue pill... :?

*joke* :wink:
oh... and have a nice day.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5502
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Jester KCC wrote:If you have the same code, who don't crash the RAD....i'm interesting
Because i prefer close the VB with the button "quit"
Don't worry and not offense :D
It's french humor :D
I have all my trust in you 8)
And you help me very much

And the winner is.....THEARR !!!!

You have right, your new code works fine.
I can use my "quit button" for VB now :D

You are an ANGEL and an angel must have wifes

It's the reason why ............KCC is proud, to offer you, for thanks of your great and kindness help, a nice picture of your "Charlie's Angels" after a big french lunch :D
France it's the land of food :roll:

I hope it's a good present for you :roll:
I make you a big smile with

Image

Again thanks at you, and all help me, in this dangerous mission, in the middle of the PC memory :?

PS: It's not a sex picture.
All this "angels" (I believe she can't fly :?) are dressed.
If you don't see their knikers....perhaps it is too small :D
ImageThe happiness is a road...
Not a destination
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

What the hell ... :shock:
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5502
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Apparently.....you don't like too, my THEARR present :cry:
ImageThe happiness is a road...
Not a destination
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Sir Mix-A-Lot - I Like Big Butts wrote:I like big butts and I can not lie
You other brothers can't deny
That when a girl walks in with an itty bitty waist
And a round thing in your face
You get sprung
...
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5502
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Aaaahhhh yeeeess !!!!!
KCC have understand what you try to say to me....

This super nice girls is "rappers" :D
That's the sisters of the fat boys :lol:
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5502
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

thearr wrote:
Kwaï chang caïne wrote:And i obtain a msgbox with a "o" in the titlebar and a "t" in the prompt :shock:
When i click ok......VB crash

KCC is very very sad :cry:
OK, we've almost got it.

Now try to chek "Unicode executable" option in PB IDE before compiling DLL.
It's again me :oops:

The passing of array works fine now, thanks to THEARR, but when i pass a string variable at my DLL i have square character in the messagerequester :shock:

Code: Select all

ProcedureDLL MyFunctionPB(String.s, *ArrayFromVB) 
 MessageRequester("", String)
 Dim MyArray.l(1) 
 CopyMemory(*ArrayFromVB, @MyArray(), 2*4) 
 MessageRequester(PeekS(MyArray(0)), PeekS(MyArray(1))) 
EndProcedure
Then i disable the UNICODE in the DLL, my string is OK, but i have just the first character of my array :cry:

Someone know what i must do ????? :roll:
Programming is really the HELL for KCC :cry:
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5502
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Well...it's christmas :D
KCC have found alone the solution...like a big :shock:

KCC think the problem is in the side of VB :roll:

So KCC add this line in the VB code :

Code: Select all

Private Declare Sub MyFunctionPB Lib "c:\MyDll.dll" (ByRef MyArray As Long) 

Public Sub Form_Load() 
  
 MyArrayVB(0) = "one" 
 MyArrayVB(1) = "two" 
 
 MyStr = StrConv(MyArrayVB(0), vbFromUnicode)
 MyArrayPB(0) = StrPtr(MyStr) 
 
 MyStr = StrConv(MyArrayVB(1), vbFromUnicode)
 MyArrayPB(1) = StrPtr(MyStr) 
  
 MyFunctionPB MyArrayPB(0) 'Send pointer to PB DLL function (ByRef) 

End Sub
And "Roll my hen" (French expression = "Roule ma poule")....that's works fine now :D

If this........... can help anybody a day :wink:
ImageThe happiness is a road...
Not a destination
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Post by helpy »

Windows 10 / Windows 7
PB Last Final / Last Beta Testing
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5502
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Thanks HELPY for your links. 8)
I try to understand it :oops:

I have send the skin of bear to quickly :oops:

This function of VB don't works

Code: Select all

MyStr = StrConv(TabloVB(i), vbFromUnicode)
I must convert UNICODE to ANSI in VB not in PB
I have found a function who convert UNICODE/ANSI in PB and that's works

But i search the same function vor VB and don't find it :cry:
ImageThe happiness is a road...
Not a destination
thearr
User
User
Posts: 21
Joined: Sun Apr 26, 2009 3:18 am
Location: RU

Post by thearr »

Kwaï chang caïne wrote:The passing of array works fine now, thanks to THEARR, but when i pass a string variable at my DLL i have square character in the messagerequester :shock:

Code: Select all

ProcedureDLL MyFunctionPB(String.s, *ArrayFromVB) 
 MessageRequester("", String)
 Dim MyArray.l(1) 
 CopyMemory(*ArrayFromVB, @MyArray(), 2*4) 
 MessageRequester(PeekS(MyArray(0)), PeekS(MyArray(1))) 
EndProcedure
I don't know how do you pass the string, but this way can work:

Code: Select all

Private Declare Sub MyFunctionPB Lib "c:\MyDll.dll" (ByVal MyString as String, ByRef MyArray As Long) 


MyFunctionPB TestString, MyArrayPB(0) 'TestString is a string variable you'd like to pass to Dll
Ceterum censeo Carthaginem esse delendam!
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5502
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Hello THEARR :D

Yes that's works only if i compile in UNICODE the DLL :cry:
But if i compile in UNICODE it's the title string who don't pass.

I prefer convert in VB the UNICODE to ANSI and pass the array in ANSI mode, if it's possible.
At my mean it's more simple, and like i have never compiled all my DLL in UNICODE, i'm affraid if one or much more variable don't pass :cry:

I have try also to compile in ANSI and add this function

Code: Select all

Procedure.s Unicode2Ansi(*Unicode, UniLen.l) 
  ;/ *Unicode [in]  Points To the wide-character string To be converted. 
  ;/ UniLen   [in]  Specifies the number of wide characters in the string pointed to by the lpWideCharStr parameter. If this value is -1, the string is assumed to be null-terminated and the length is calculated automatically. The length will include the null-terminator. 
  ;/ string   [out] The translated (ANSI) string. 
  Protected Ansi.s,AnsiLen.l 
  AnsiLen = WideCharToMultiByte_(#CP_ACP,0,*Unicode,UniLen,0,AnsiLen,0,0) 
  If AnsiLen 
    Ansi = Space(AnsiLen) 
    If WideCharToMultiByte_(#CP_ACP,0,*Unicode,UniLen,@Ansi,AnsiLen,0,0);"•",#True) 
      ProcedureReturn Ansi 
    EndIf 
  EndIf 
  ProcedureReturn "" 
EndProcedure
 

Code: Select all

  Ansi.s = Unicode2Ansi(MyArray(i), 1000)
  AddGadgetItem(#ListviewTexte, - 1, ReplaceString(Ansi, Chr(13), ""))
And that's works fine too.
But i search to convert in VB in ANSI not in PB
Because i don't want to modify all my DLL :roll:
ImageThe happiness is a road...
Not a destination
thearr
User
User
Posts: 21
Joined: Sun Apr 26, 2009 3:18 am
Location: RU

Post by thearr »

:?:

Code: Select all

 MyArrayVB(0) = StrConv("one", vbFromUnicode)
 MyArrayVB(1) = StrConv("two", vbFromUnicode) 
Ceterum censeo Carthaginem esse delendam!
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5502
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Ooouuuiinnn !!!!
KCC become crazy....Ooouuuiinnn !!!!
Image
KCC don't understand anything now...Ooouuuiinnn !!!!
UNICODE, ANSI, MEMORY, POINTER, VB, SAFEARRAY, PB ....oouuuiinnn !!!!

KCC just want pass a string array of VB to PB...is just that ...only that.......Oiuiinnn !!!!
The programming is very bad with KCC .....Oiuiinnn !!!!

KCC have an idea :?:
This is the VB code and PB code of KCC :D

http://erdsjb.free.fr/TabloDll.zip

Perhaps you, you can do a magical tower and pass this #([**@"=## of array of VB to PB :roll:
ImageThe happiness is a road...
Not a destination
Post Reply