tags:

views:

90

answers:

2

I am relatively new to development within COM, and I was wondering what the community standard was for access of COM object properties. I have seen both of the following conventions in code:

comObjectPtr->PutValue(value);

and

comObjectPtr->Value = value;

and both seem to work, but I was wondering if there was an inherent advantage or disadvantage to either approach and why.

+1  A: 

You're talking about the smart wrapper classes created with #import, right?

PutValue() is more explicit as to what you're doing; "Value = " is easier to use but it can have "hidden" side-effects if the put function does something other than a straight assignment. As I understand it, the two are equivalent, just different syntaxes.

Jason S
This is what I'm talking about.
Oliver N.
As much as I appreciate getting this answer accepted, @crashmstr's answer points out a more important subtlety, namely the exception vs. HRESULT return value.
Jason S
+3  A: 

If I remember correctly, using the property assignment will throw an exception vs. a HRESULT returned in the setter if there is a problem.

Same thing is true of the getter method calls vs. property.

A "benefit" of using the property is that you can use the prop-get values directly instead of having to declare a variable and getting it before using.

crashmstr
Good point re: the HRESULT vs. exception.
Jason S