function parameters to pass a VB string array to a C++ DLL 
Author Message
 function parameters to pass a VB string array to a C++ DLL

Hi there,

I want to pass a string array to a C++ DLL, but i don't know which parameter
I have to use...
Is it :
    LPSTR myArray or something with SAFEARRAY or something else?

Sincerely, Paco



Thu, 07 Aug 2003 20:06:43 GMT  
 function parameters to pass a VB string array to a C++ DLL
Probably you don't want to pass a char array, but a pointer to a char array.
Whether you have to use LPSTR or SAFEARRAY depends on the DLL and its header
files. If you post some code, we might be able to help you.

Regards,
Aaron Isotton



Quote:
> Hi there,

> I want to pass a string array to a C++ DLL, but i don't know which
parameter
> I have to use...
> Is it :
>     LPSTR myArray or something with SAFEARRAY or something else?

> Sincerely, Paco



Thu, 07 Aug 2003 21:29:06 GMT  
 function parameters to pass a VB string array to a C++ DLL


Quote:
>Hi there,

>I want to pass a string array to a C++ DLL, but i don't know which parameter
>I have to use...
>Is it :
>    LPSTR myArray or something with SAFEARRAY or something else?

>Sincerely, Paco

Do a search of the MSDN help with the following search string (with
quotes):

"C DLL"

and you should find a few articles that will help you no-end.

Jimbo



Thu, 07 Aug 2003 21:37:59 GMT  
 function parameters to pass a VB string array to a C++ DLL
Hi Aaron,
I'm working on creating some DLLs to improve the speed of my VB
applications.
So, I try to make a C++ function which accepts a string array, modifies some
values in my array and return true or false whether everything went fine or
not during the process.
So, after reading articles in the MSDN Library I thought everything would
just run fine. But the point is that I'm getting just nowhere.
My question is : could you show me some C++ function prototype which accepts
a string array from VB. I just want to know what is wrong with the following
:

C++ function :
    OPARRAY_API bool __stdcall testVBArray(LPSTR pszArray)

VB API Call:
    Private Declare Function testVBArray  Lib "OPArray.dll" (pszVBArray() As
String) As Long

VB function Call:
    Sub main()
        Dim myarray(0 To 2) As String

        myarray(0) = "John"
        myarray(1) = "Doe"

        MsgBox "The result is : " & Cstr(EmptyCell(myarray(0)))
End Sub

and if it's not wrong, how can I get the values in the C++ function?

Thanks,
Paco



Quote:
> Probably you don't want to pass a char array, but a pointer to a char
array.
> Whether you have to use LPSTR or SAFEARRAY depends on the DLL and its
header
> files. If you post some code, we might be able to help you.

> Regards,
> Aaron Isotton



> > Hi there,

> > I want to pass a string array to a C++ DLL, but i don't know which
> parameter
> > I have to use...
> > Is it :
> >     LPSTR myArray or something with SAFEARRAY or something else?

> > Sincerely, Paco



Fri, 08 Aug 2003 00:41:54 GMT  
 function parameters to pass a VB string array to a C++ DLL
Hi Paco,

As far as I understand, you want to pass a string from VB to VC++. Tricky.

I've found out the following:

(Quoting from MS Platform SDK)

A parameter that is declared As String in Visual Basic is declared as a
pointer to a BSTR in C++. Setting a string pointer to NULL in C++ is
equivalent to setting the string to the vbNullString constant in Visual
Basic. Passing in a zero-length string ("") to a function designed to
receive NULL does not work, as this passes a pointer to a zero-length string
instead of a zero pointer.

(End Quote)

The function prototype will though look like this:
OPARRAY_API bool __stdcall testVBArray(BSTR *lpbstr);

A BSTR is a 16-bit (wide-char) string; as far as I understand it is
equivalent to LPWSTR. So you must use the wide-char functions of C++.

Sorry I can't give you any more accurate info, but I don't have VB, so I
can't try it out myself.

Regards,
Aaron Isotton



Fri, 08 Aug 2003 02:24:12 GMT  
 function parameters to pass a VB string array to a C++ DLL
My guess would be to use BSTR on the C side, since this is the type of
string that VB uses.  And ByRef in the VB call.  VC/VB does provide built in
conversion between VB String and C char*, however when you want to pass an
array of them I don't think it will recognize them.  Since you do have
overhead of DLL function call I'm not too sure that you will achieve speed
improvement calling an external DLL.

I have had little success when trying to pass complex user defined types
between VB and VC, and would recommend that if you can't get it working in a
day or so, switch to passing a single string, instead of an array of
them...or just code it in VB.

I would guess that the following will probably also not work...

   OPARRAY_API bool __stdcall testVBArray(BSTR *pszArray);

   Private Declare Function testVBArray  Lib "OPArray.dll" (ByRef
pszVBArray() As String) As Long


Quote:
> Hi Aaron,
> I'm working on creating some DLLs to improve the speed of my VB
> applications.
> So, I try to make a C++ function which accepts a string array, modifies
some
> values in my array and return true or false whether everything went fine
or
> not during the process.
> So, after reading articles in the MSDN Library I thought everything would
> just run fine. But the point is that I'm getting just nowhere.
> My question is : could you show me some C++ function prototype which
accepts
> a string array from VB. I just want to know what is wrong with the
following
> :

> C++ function :
>     OPARRAY_API bool __stdcall testVBArray(LPSTR pszArray)

> VB API Call:
>     Private Declare Function testVBArray  Lib "OPArray.dll" (pszVBArray()
As
> String) As Long

> VB function Call:
>     Sub main()
>         Dim myarray(0 To 2) As String

>         myarray(0) = "John"
>         myarray(1) = "Doe"

>         MsgBox "The result is : " & Cstr(EmptyCell(myarray(0)))
> End Sub

> and if it's not wrong, how can I get the values in the C++ function?

> Thanks,
> Paco



> > Probably you don't want to pass a char array, but a pointer to a char
> array.
> > Whether you have to use LPSTR or SAFEARRAY depends on the DLL and its
> header
> > files. If you post some code, we might be able to help you.

> > Regards,
> > Aaron Isotton



> > > Hi there,

> > > I want to pass a string array to a C++ DLL, but i don't know which
> > parameter
> > > I have to use...
> > > Is it :
> > >     LPSTR myArray or something with SAFEARRAY or something else?

> > > Sincerely, Paco



Fri, 08 Aug 2003 03:29:59 GMT  
 function parameters to pass a VB string array to a C++ DLL
Well, it seems that I'm going to pass a single string instead of my array.
But I must admit, it's a little bit frustrating.
I thought I would achieve this without much problems, but it's not the
case...
However, now the question is : if I fill my array with a few thousands
strings and make a call to my dll function a thousand times, won't this take
more time, than just calling my Dll function once and passing a single array
?

I know VB and I like C++, it would be so great if I could work with both...

Anyway, thank you very much. And if you get any idea, tell me. I think the
problem is interesting.

Best Regards,
PaCo.



Quote:
> My guess would be to use BSTR on the C side, since this is the type of
> string that VB uses.  And ByRef in the VB call.  VC/VB does provide built
in
> conversion between VB String and C char*, however when you want to pass an
> array of them I don't think it will recognize them.  Since you do have
> overhead of DLL function call I'm not too sure that you will achieve speed
> improvement calling an external DLL.

> I have had little success when trying to pass complex user defined types
> between VB and VC, and would recommend that if you can't get it working in
a
> day or so, switch to passing a single string, instead of an array of
> them...or just code it in VB.

> I would guess that the following will probably also not work...

>    OPARRAY_API bool __stdcall testVBArray(BSTR *pszArray);

>    Private Declare Function testVBArray  Lib "OPArray.dll" (ByRef
> pszVBArray() As String) As Long



> > Hi Aaron,
> > I'm working on creating some DLLs to improve the speed of my VB
> > applications.
> > So, I try to make a C++ function which accepts a string array, modifies
> some
> > values in my array and return true or false whether everything went fine
> or
> > not during the process.
> > So, after reading articles in the MSDN Library I thought everything
would
> > just run fine. But the point is that I'm getting just nowhere.
> > My question is : could you show me some C++ function prototype which
> accepts
> > a string array from VB. I just want to know what is wrong with the
> following
> > :

> > C++ function :
> >     OPARRAY_API bool __stdcall testVBArray(LPSTR pszArray)

> > VB API Call:
> >     Private Declare Function testVBArray  Lib "OPArray.dll"
(pszVBArray()
> As
> > String) As Long

> > VB function Call:
> >     Sub main()
> >         Dim myarray(0 To 2) As String

> >         myarray(0) = "John"
> >         myarray(1) = "Doe"

> >         MsgBox "The result is : " & Cstr(EmptyCell(myarray(0)))
> > End Sub

> > and if it's not wrong, how can I get the values in the C++ function?

> > Thanks,
> > Paco


message

> > > Probably you don't want to pass a char array, but a pointer to a char
> > array.
> > > Whether you have to use LPSTR or SAFEARRAY depends on the DLL and its
> > header
> > > files. If you post some code, we might be able to help you.

> > > Regards,
> > > Aaron Isotton



> > > > Hi there,

> > > > I want to pass a string array to a C++ DLL, but i don't know which
> > > parameter
> > > > I have to use...
> > > > Is it :
> > > >     LPSTR myArray or something with SAFEARRAY or something else?

> > > > Sincerely, Paco



Fri, 08 Aug 2003 04:00:02 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. passing Array of Strings between a C/C++ DLL and VB

2. passing string array from VB to C++ DLL

3. passing short array parameters to VC++ DLL in VB

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

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

6. Processing strings passed from VB in C++ DLL

7. Passing strings to VB dll from c++

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

9. Passing VB DAO objects to C++ DLL functions?

10. Passing C++ Class Member Function to as a C Callback Function Parameter

11. VC++ pass object parameter to VB ActiveX DLL

12. how do I pass arrays as parameters to functions - newbie

 

 
Powered by phpBB® Forum Software