Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VC++ DLL in VB

Status
Not open for further replies.

ss2905

Programmer
Nov 2, 2000
10
JP
Hi,
I have a VB app that needs to call a function written in VC++.The VB app passes an int and the function returns a LPSTR.
e.g VB passes 1 to the function which returns "st".Similarly, for 2, "nd" is returned,etc..that The function works fine but problem is it returns junk char after the string.So, I am not able to append any strings to this variable in VB.
eg.Instead of "2nd day" I am getting only "2nd".I'm padding up the LPSTR with nulls in my code.
Is this a problem with calling conventions of VB and VC++?BSTR and LPSTR?
Thanx in advance
----Sanjeev
 
Sanjeev,

You might try asking this question in a VB forum.

Good luck
-pete
 
ss2905 -
Returning a string as result of a function call is a problem in VB because of the various BSTR, LPSTR, Unicode, and ANSI problems. It's much better if you returned it as an "Out" parameter in the function call.

If you were to do that, in your VB code you'd do the following:
[tt]
Declare sub lib "MyDLL.dll"(ByVal SendAnInteger as Long, ByRef GetAString as string)
[/tt]
Note that all strings need to be passed "Byref" to external DLLs in VB. Also note that 'int' datatype in C++ is a 32-bit value, and needs to be declared as 'long' in VB.

Also Also note, that when VB7 (aka .NET) comes out, this hassle of mis-matched datatypes will go away, since VB and VC++ will use the same runtime libraries.

Chip H.
 
You might try using an
InStr(retStr,0) and see if you can find the end of the character string returned. Then apply the Right (Left??? i forget which, it has been a while) function to modify your string.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top