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 {
HRESULT Name([out, retval]BSTR* result);

HRESULT Name([in]BSTR value);

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

IMyObject* pMyObject;
// "get" method
BSTR res;
// Now free the string allocated in ABBYY FineReader Engine

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

Was this article helpful?

3 out of 3 found this helpful

Have more questions? Submit a request



Please sign in to leave a comment.