How to work with string properties in SDK products


How to work with string properties in SDK products?


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.

In this example, 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 it is possible to free the string

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

Have more questions? Submit a request



Please sign in to leave a comment.