Working with string properties

Working with string properties is similar to working with simple properties, but there are important differences. A C++ developer working with string properties must free the strings that are passed to set methods, and also those that are returned by get-methods. This is done automatically in Visual Basic and in C++ with Native COM support.

Assume MyObject also supports a string property called Name. This property is described in the type library as follows:
interface IMyObject : IUnknown {
...
[propget]
HRESULT Name([out, retval]BSTR* result);

[propput]
HRESULT Name([in]BSTR value);
...
};

Below is a C++ code sample property that uses this property.

IMyObject* pMyObject;
...
// "get" method
BSTR res;
pMyObject->get_Name(&res);
...
// Now free the string allocated in ABBYY FineReader Engine
::SysFreeString(res);

// "put" method
BSTR str = ::SysAllocString(L"New Name");
pMyObject->put_Name(str);
// Now free the string that we allocated
::SysFreeString(str);

Was this article helpful?

3 out of 3 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.