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!

returning strings in a COM method 1

Status
Not open for further replies.

johpje

Programmer
Jan 3, 2002
87
BE
Hi all,

I'm making a COM object in VC++, but I have a problem with a method returning a string.

the code in the COM class is goes like this:

Code:
STDMETHODIMP CCOMCLASS::get_String(/* [out/retval] */BSTR *pVal){
	_bstr_t tmp;
	tmp = _bstr_t(XXX);
	*pVal = tmp;
	return S_OK;
}

when i call the method in VB:

Code:
    op$ = myComClass.String()

I only get the first character of the string.
and if i replace
Code:
	*pVal = tmp;
with
Code:
	pVal = new BSTR(tmp);

it returns an empty string.

Can anyone tell me how to resolve this?
Do i have to send an existing fixed length string? If so; how do i modify the strings contents?

thanks,
Johpje
 
I think you should do like this:
STDMETHODIMP CCOMCLASS::get_String(/* [out/retval] */BSTR *pVal){
*pVal = SysAllocString((BSTR)_bstr_t(XXX));
return S_OK;
}

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top