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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning a String to VB from C DLL

Status
Not open for further replies.

RichardF

Programmer
Oct 9, 2000
239
GB
Hi,

I am really stuck with this.

I want to return to my vb client a String (BSTR) from a function in my (normal) dll. Thing is im converting from a TCHAR and am getting funny results.

Heres the code :
Code:
TCHAR cValue[MAXBUFFER];

..

BSTR __stdcall GetValue()
{
    CComBSTR bstr = cValue;

    return bstr;
}

in VB this returns H...E...L...L...O... (where . = 0)
(or 'H' if you print it)

I also tried :
Code:
BSTR __stdcall GetValue()
{
    int iLen = _tcslen(StringList[Index].Value);
    CComBSTR bstr = StringList[Index].Value;
    char cBuffer[MAXBUFFER];

    WideCharToMultiByte(CP_ACP,0,bstr,iLen,cBuffer,MAXBUFFER,NULL,NULL);
    cBuffer[iLen] = 0;

    bstr = cBuffer;

    return bstr;
}

in VB this one returns H E L L O

Something strange is going on, im just not sure what !


Rich.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top