CString to BSTR question dealing with nul characters
- From: "Danny" <fernandez.dan@xxxxxxxxx>
- Date: 3 Jan 2006 12:43:25 -0800
I'm creating a C++ DLL for a VB application. I'm using VC7 for creating
the DLL application. I'm trying to return a string from this function,
here is a simple example
extern "C" DLL_API int __stdcall GetString(BSTR* myStr)
{
int rtnCode = PASS; // PASS is defined as 1 somewhere else
CString temp = "Hello";
*str = temp.AllocSysString();
return rtnCode;
}
>>From my test VB 6 app I declare
Private Declare Function GetString GetStr "My.dll" (ByRef myStr As
String,) As Integer
Dim tempStr as String
Dim rtnCode as Integer
rtnCode = GetString(tempStr)
I call the this funciton from my VB 6 application and passes
successfully. BUT I'm getting extra nul characters.
I converted tempStr into a Byte array to check out the individual
bytes. Dim b() as Byte
b = tempStr
I got the following
b(0) = 72
b(1) = 0
b(2) = 0
b(3) = 0
b(4) = 101
b(5) = 0
b(6) = 0
b(7) = 0
b(8) = 108
b(9) = 0
b(10) = 0
b(11) = 0
b(12) = 108
b(13) = 0
b(14) = 0
b(15) = 0
b(16) = 111
b(17) = 0
b(18) = 0
b(19) = 0
While if I declare
Dim anotherStr as String
anotherStr = "Hello"
b = anotherStr
The byte array for this is
b(0) = 72
b(1) = 0
b(2) = 101
b(3) = 0
b(4) = 108
b(5) = 0
b(6) = 108
b(7) = 0
b(8) = 111
b(9) = 0
So am kinda of confused the best way to convert a CString to a BSTR.
Thanks for any help or information.
.
- Follow-Ups:
- Prev by Date: Re: Improving VC6 IntelliType
- Next by Date: Re: CString to BSTR question dealing with nul characters
- Previous by thread: Locking out student IM etc.
- Next by thread: Re: CString to BSTR question dealing with nul characters
- Index(es):
Relevant Pages
|
Loading