Methods and Properties

An interface can have three types of methods 1) Property Get methods, 2) Property Put Methods, 3) Class Functions. All of these methods have some common syntax -

interface I<Interface Name>: IDispatch
{
  [<property type>, id(<index>), helpstring(< >)]
  HRESULT <Method Name>([<in/out/retval>] <data type> <Argument name>, ..);
}

Method attributes

A method has some attributes which are enclosed in brackets [] and should be placed before the method prototype.

  • Property Method - Property GET or PUT are the options and denoted as propget and propput. This field is not applicable for normal functions
  • id() - Method identity is the index number starting from one.
  • helpstring - A help description string for the method for the developer

Method prototype

Method prototype is similar to C/C++ function prototype with additional fields.

  • Return Type - Return type of the method. HRESULT should be the return type for all methods.
  • Method Name - Like C/C++ function name with a meaningful name
  • Arguments types - Argument types are [in] input, [out] output, [in,out] both input & output and [retval] return.
  • Arguments data types - char, short, long, bstr_t etc
  • Arguments name - Like C/C++ function arguments with a meaningful names

Property Get methods

COM/DCOM class can have member variables or properties. The design does not allow client to access public members. All has to be through functions and methods. Property Get methods are functions to return the value of a specific property or member variable.

  • Property Method -[propget] attribute should used.
  • Arguments types -[out,retval] is used
  • Arguments data types - - depending on the type of the property and should be pointer or as passed as reference
[propget, id(1), helpstring("Operand1 of calculator")]
HRESULT Operand1([out, retval] long *pVal);

Property Put methods

Property Put methods are functions to set the value of a specific property or member variable.

  • Property/Method -[propput] attribute should used.
  • Arguments types - method with a single input argument denoted as [in]
  • Arguments data types - depending on the type of the property
[propput, id(1), helpstring("Operand1 of calculator")]
HRESULT Operand1([in] long newVal);

Class Functions/methods

Interface methods does not have propget/propput and it can have multiple input or output arguments and or one return arguments.

  • Property/Method -attribute is not applicable.
  • Arguments types Argument types are [in] input, [out] output, [in,out] both input & output and [retval] return.
  • Arguments data types - Depending on design
[id(3), helpstring(“example method")]
HRESULT DoOperation();

[id(3), helpstring(“example method")]
HRESULT DoOperation([in] char operation);

[id(3), helpstring(“example method")]
HRESULT DoOperation([in] char operation, [in,out] short *pVal);

[id(3), helpstring(“example method")]
HRESULT DoOperation([in] char operation, [out,retval] short *pVal);

About our authors: Team EQA

You have viewed 1 page out of 67. Your COM/DCOM learning is 0.00% complete. Login to check your learning progress.

Learn on Youtube

#