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!

(MSVC/COM) Allocating BSTR strings?

Status
Not open for further replies.

BeanDog

Programmer
Jul 15, 2000
60
US
Who is responsible for allocating strings in COM calls?

For instance, if I have a method with an [out] BSTR* parameter, do I have to call AllocSysString and/or SysFreeString to pass it out? Same question for [out,retval]'s. i.e.:

STDMETHODIMP CESValhalla::GetFolderById(long lFolderId, BSTR *bsFolderName/*out*/, BSTR *bsFolderDescription/*out,retval*/)
{
*bsFolderName = CString("Name").AllocSysString();
*bsFolderDescription = CString("Description").AllocSysString();
return(S_OK);
}

Is this correct, or should I be doing something else? Sometimes unexpected things happen once in a while, like both BStr's will end up saying "Name" or both will end up saying "Description". How should I be doing this?


Same question for firing COM events. Should I do this:

Fire_OnFileScoutProgress(csPath.AllocSysString());

or what? Who's responsible for doing what for COM parameter strings?



~BenDilts( void );
 
Hello,

I noticed that the best translation from the IDL declaration
[out] BSTR *pbstrEtc... was BSTR **pbstrEtc in the C++ method declaration.

The drawback is that, in the class view tree, the method is no longer related to the interface node, but surprisingly, it suits the actual parameter passing scheme.

Maybe some marshalling issue ?
(Did anyone else experience this ?)

Hope it helps.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top