passing Array of Strings between a C/C++ DLL and VB 
Author Message
 passing Array of Strings between a C/C++ DLL and VB

Hi

I need to pass an array of strings between a DLL written in
C/C++ and a calling language like VB or Powerbuilder. I would
leave it to the calling routine to allocate the memory for the
array. The "C" DLL routine would just fill it in and return to
the calling function.

What is the typical way of passing arrays of strings between VB
and C/C++ DLL? I've seen some comments on SafeArray.

thanks

* Sent from RemarQ http://www.*-*-*.com/ The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



Fri, 30 Aug 2002 03:00:00 GMT  
 passing Array of Strings between a C/C++ DLL and VB


Quote:
> Hi
Hi.
> I need to pass an array of strings between a DLL written in
> C/C++ and a calling language like VB or Powerbuilder. I would
> leave it to the calling routine to allocate the memory for the
> array. The "C" DLL routine would just fill it in and return to
> the calling function.

> What is the typical way of passing arrays of strings between VB
> and C/C++ DLL? I've seen some comments on SafeArray.

Arrays of anything are passed to/from VB with
the SAFEARRAY struct.  One of the fields in it
siginfies the content type so it can be disposed
of properly.  Among the types supported is BSTR,
which is VB's string type.

You would do better to just allocate the BSTR's
and the array yourself, in the called routine,
rather than trying to get this done in VB.  The
code will be no more complicated, it will reside
in the right place for efficiency and convenience,
and it will be most consistent with the way VB
normally works and is used.

BTW, a SAFEARRAY of BSTR is the typical way.

--
Larry Brasfield
Above opinions may be mine alone.



Fri, 30 Aug 2002 03:00:00 GMT  
 passing Array of Strings between a C/C++ DLL and VB

Thanks for the response Larry.  One more quick question - are
you suggesting that I allocate the array within the C/C++ Dll?
If so, then i would have to make sure to free up the memory with
another call to the dll - correct?

I just want to make sure that whatever method I use to solve
this issue is one that is generally accepted.

thanks

Greg

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



Fri, 30 Aug 2002 03:00:00 GMT  
 passing Array of Strings between a C/C++ DLL and VB


Quote:

> Thanks for the response Larry.

You're welcome.

Quote:
> One more quick question - are
> you suggesting that I allocate the array within the C/C++ Dll?

Yes.

Quote:
> If so, then i would have to make sure to free up the memory with
> another call to the dll - correct?

No.  One of several advantages to doing it per my
suggestion is that you are using the same protocol
that VB itself uses.  If you pass a SAFEARRAY **,
(which is the equivalent of a ByRef array in VB),
all allocation issues will be properly handled on
the VB side as long as you do your part on the DLL
side.  That means, for example, that you free any
array that comes in if you have to reform it.  The
array will be treated by VB just as one of its own
because that's what it will be.  This means it will
be freed as appropriate.

Quote:
> I just want to make sure that whatever method I use to solve
> this issue is one that is generally accepted.

What I suggested is *the* way accepted by VB and
what it uses internally.  Take a look at the
routines SafeArrayCreate(), SafeArrayDestroy(),
SysAllocString(), SysFreeString() and associated
routines.

Quote:
> thanks

Sure.

--
Larry Brasfield
Above opinions may be mine alone.



Fri, 30 Aug 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. function parameters to pass a VB string array to a C++ DLL

2. passing string array from VB to C++ 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. Processing strings passed from VB in C++ DLL

6. Passing strings to VB dll from c++

7. How To pass 2D String array to VB from VC++ Using Safe array

8. Passing string Arrays between VB and VC

9. How to pass var length array of string to event in VB

10. Passing array of Strings between VB and VC

11. How String Array passed to VB ActiveX Control

12. How to pass a string array from VB to VC

 

 
Powered by phpBB® Forum Software