OUT parameters

[OUT] parameters are always returned as reference and thus they are pointers. Caller should provide the address of the variable and called function should write the value of the variable in the address.

HRESULT ReturnChar(char *pchVal);
HRESULT ReturnInt(int *pnVal);
HRESULT ReturnLong(long *plVal);
HRESULT ReturnFloat(float *pfVal);
HRESULT ReturnDouple(int *pdVal);

HRESULT hr;
<type> variable;

hr = ReturnType(&variable);
if(hr == S_OK)
{
  cout << "Returned value is << variable;

} else {
  cout << "error: " << hr;
}

dynamic OUT parameters

There could be string and malloc buffer or dynamic array for out variable. In those cases parameter has to be pointer to a pointer. Caller has to pass the address of the pointer variable. Calle or function should allocate a pointer or array buffer and this address value should be written to the caller provided address.

void ReturnString(char **pdVal);
void ReturnPointer(void **pvVal);
void ReturnBSTR(BSTR *pvVal);

HRESULT hr;
BSTR* varString; /* BSTR * or OLECHAR ** */

hr = ReturnType(&varString);
if(hr == S_OK)
{ 
  cout << "Returned value is << varString;
  /* Now free this sting, else memory leak */
  SysFreeString (varString);
}
else
{
  cout << "error: " << hr;
}

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

#