Passing array of strings to a dll in VB 
Author Message
 Passing array of strings to a dll in VB

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.*-*-*.com/
Before you buy.



Sun, 08 Sep 2002 03:00:00 GMT  
 Passing array of strings to a dll in VB

Erm not entirely sure what you want..hope this helps...
Declare the function something like this ...

Public Function AnArray(ByRef arr() As String) As String()


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.

Sent via Deja.com http://www.deja.com/
Before you buy.


Sun, 08 Sep 2002 03:00:00 GMT  
 Passing array of strings to a dll in VB

DOH!!! Erm  or this even ...

Public Sub AnArray(ByRef arr() As String)

Whats the point of returning the array in a function if you
are passing it by reference ???

Sorry bout that.


Quote:

> Erm not entirely sure what you want..hope this helps...
> Declare the function something like this ...

> Public Function AnArray(ByRef arr() As String) As String()



> > 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.

> Sent via Deja.com http://www.deja.com/
> Before you buy.

Sent via Deja.com http://www.deja.com/
Before you buy.


Sun, 08 Sep 2002 03:00:00 GMT  
 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.



Sun, 08 Sep 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. passing (string) arrays from VB to C-DLL and vice versa

2. Passing VB String array to DLL???

3. passing (string) arrays from VB to C-DLL and vice versa

4. passing (string) arrays from VB to C-DLL and vice versa

5. How to pass a string Array from VB to a C++ DLL

6. Passing array from VB to DLL and returning array

7. how to pass a string array to mfc dll

8. Passing string Array from VB3 to DLL

9. Passing String Arrays to API DLLs

10. passing string arrays to dll

11. help with pass string array to C DLL procedure

12. Passing string Arrays from Fortran DLL to Visual Basic

 

 
Powered by phpBB® Forum Software