Working with simple properties

We will use the Boolean property to describe how simple properties are used.

This property is described in the type library as follows: 

interface IMyObject : IUnknown {
HRESULT MyProperty([out, retval]VARIANT_BOOL* result);

HRESULT MyProperty([in]VARIANT_BOOL value);

In Visual Basic this property is handled as follows:

If MyObject.MyProperty <> True Then
   MyObject.MyProperty = True
End If

In C++ there are two ways to use this property. These methods have get_ and put_ prefixes. C++ code sample:

IMyObject* pMyObject;
if( res != VARIANT_TRUE )

 Native COM support makes this procedure simpler. Code sample:

IMyObjectPtr pMyObject;
if(pMyObject->MyProperty != VARIANT_TRUE) pMyObject->MyProperty = VARIANT_TRUE;

 If the type library only defines the "get" method for a property, this property is called read-only. Its value cannot be changed by the user and it may only be accessed for reading.

Working with string properties is described in the next article.

Was this article helpful?

3 out of 3 found this helpful

Have more questions? Submit a request



Please sign in to leave a comment.