
Passing array of strings to a dll in VB
A couple of comments which may or may not help.
It is possible to pass a single String to a C DLL using the ByVal keyword,
and I am also fairly sure that you can change the String in the C DLL and it
is passed back changed. The C has a built in conversion to change from the
VB String "object" to the C's Null ended Byte array type string.
When you pass in an Array of Strings you essentially create a "User Defined
Type" which the I think that the C DLL can not recognize as a VB String
anymore.
From experience I have found that retrieving a Two-Dimensional Array via a C
Dll causes some unexpected results. The Array is swapped Row to Col and Col
to Row which is due to the way Two-Dimensional Arrays are defined in VB and
VC. I wrote an additional routine just to swap the values back to where
they were supposed to be in yet another two-dimensional array. In other
words try to avoid passing more that a Single-Dimension Array to the DLL.
So instead of using an array of strings to pass data in and out of the DLL,
how about an array of Long's? Should not be hard at all to fit a 4
character string into the 4 bytes of a Long data type. To load the highest
Byte of the Long, multiply the Byte (Character) value by &H1000000, and then
add to the Long output.
&H35 * &H1000000 = &H35000000
&H27 * &H10000 = &H270000
&H12 * &H100 = &H1200
&H98
Add them all together = &H35271298
Just some ideas because I don't think you can pass an array of strings...
Quote:
> If have a dll and I need to pass an array of strings to
> a routine in the dll:
> public String_array(MAX) as String*4
> But the declare statment only lets you pass strings by
> value
> Private Declare Sub "Subname" Lib "Libname" _
> (... ByVal String_array() as String, ...)
> Well ByVal means I can't change the darn array
> values. What to do?
> VB doesn't let you manipulate strings in a dll?
> That seems crazy!?
> Thanks for assistance.
> --
> Fred Phelan
> Sent via Deja.com http://www.deja.com/
> Before you buy.