passing a string by LPSTR or by BSTR 
Author Message
 passing a string by LPSTR or by BSTR

Hi all ,

I am a beginner to MSVC and I have a problem . I want to pass a
string from a C dll to Visual Basic . ( I use VC++ 2.2 and VB 4.0 on
Windows NT server )

my c function is implemented as follows : ( I receive the data from a
CP card in the form of an array of char , I will simulate them here .

int WINAPI read ( BSTR datastring )
char carddata [256] ;

carddata[0] = '30' ;  // this is a problem , because you cannot
                                define a character '30'
carddata[1] = 'b' ;
carddata[2] = '4' ;
carddata[3] = 'd' ;
carddata[4] = 'g' ;
carddata[5] = 'f' ;

SysReAllocstring ( &datastring , ( BSTR) datastring );


my VB declaration is

Declare Function read Lib "c:\stringdll.dll" (ByVal arg As String) As

Form :

Private Sub Command5_Click()
Dim resultaat As Integer
Dim arg1  As Integer
Dim value As String

value = String(256, 0)

resultaat = read(value)
Text6 = value
Text7 = resultaat
End Sub

I pass the string By Val  ; I use the SysReAllocString function
because I saw that in an example of MS .
The trouble is when I try to use LPSTR , I always get error messages
in my C compiler . What is the best way to pass a string to VB program
? It should also be possible to pass a string which contains an '\0'
char . What is now the exact usage of LPSTR and BSTR or which is the
best way to do so ?( returning as returnvalue or as argument ) What
does the SysReallocString ? Is it really necessary ?

Wed, 24 May 2000 03:00:00 GMT  
 passing a string by LPSTR or by BSTR

>Hi all ,

>I am a beginner to MSVC and I have a problem . I want to pass a
>string from a C dll to Visual Basic . ( I use VC++ 2.2 and VB 4.0 on
>Windows NT server )

The C language doesn't define any support DLL's or inter-language linking.
Your question is really about the Windows environment and the working
of particular compilers under that environment so you really need to
post in a Windows related newsgroup such as



Thu, 25 May 2000 03:00:00 GMT  
 [ 2 post ] 

 Relevant Pages 

1. Passing strings - BSTR vs CComBSTR

2. trouble passing String from VB to ATL com object expecting BSTR

3. Pass a Null string from Delphi to an ActiveX control BSTR property

4. Conversion of BSTR to LPSTR problem

5. How to convert between lpstr and bstr?

6. Convert BSTR to LPSTR

7. BSTR <-> LPSTR in C, not C++

8. LPSTR from BSTR?



11. LPSTR from BSTR?



Powered by phpBB® Forum Software