How to work with simple properties in SDK products

Question

How to work with simple properties in SDK products?

Answer

It is possible to use the Boolean property to describe how simple properties are used.

This property is described in the type library as follows: 

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

[propput]
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;
...
VARIANT_BOOL res;
pMyObject->get_MyProperty(&res);
if( res != VARIANT_TRUE )
   pMyObject->put_MyProperty(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 following article.

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.