Click to See Complete Forum and Search --> : C++ DLL to return BSTR to VB


May 27th, 1999, 09:24 AM
I have a function in a DLL (VC++5) that needs to return a BSTR. This DLL uses Automation
The problem I am having is that the string in VB that receives the returned BSTR from the DLL only receives the first character of the string!

here is the DLL function:

BSTR __stdcall MyFunction (void)
{
CString strg;
strg="Hello There!";
return strg.SysAllocString();
}



The VB side of things is obvious:
Declare Function MyFunc Lib "DLLFile" () As String
Dim MyStrg As String
MyString=MyFunc
MsgBox MyString //This Displays an H only, not Hello World!

I believe this has to do with the fact that a BSTR in C++ is an unsigned short*, but I don't know how to resolve this!

Thanks in advance
Jeff