EQuestionAnswers.com Computer/Electronics Questions and Answers
C, C++, VC++, COM/DCOM, DLL and more
#Login #Sign up  Facebook Twitter TGoogle+
 

#Previous question #Index of COM/DCOM Questions #Next question

COM physical return value

All COM/DCOM functions written in IDL should return a result code as raw result value. This return is of type HRESULT. A HRESULT code of S_OK/zero means that the function returns a success. This is however not the actual return value of the function. This return value is called physical or raw return value. This is used to know if the fuction has encountered any error. This return value is not considered as actual return in client. Client can check error condition and process error handing. Below are some of very common result codes returned by IDL functions.

NameDescriptionValue
S_OKOperation successful0x00000000
E_ABORTOperation aborted0x80004004
E_ACCESSDENIEDGeneral access denied error0x80070005
E_FAILUnspecified failure0x80004005
E_HANDLEHandle that is not valid0x80070006
E_INVALIDARGOne or more arguments are not valid0x80070057
E_NOINTERFACENo such interface supported0x80004002
E_NOTIMPLNot implemented0x80004001
E_OUTOFMEMORYFailed to allocate necessary memory0x8007000E
E_POINTERPointer that is not valid0x80004003
E_UNEXPECTEDUnexpected failure0x8000FFFF

IDL functions and HRESULT

  interface ICalculate : IDispatch
  {
    [propget, id(1), helpstring("Operand1 of calculator")]
    HRESULT Operand1([out, retval] long *pVal);
    
    [propput, id(1), helpstring("Operand1 of calculator")]
    HRESULT Operand1([in] long newVal);
    
    [propget, id(2), helpstring("Operand2 of calculator")]
    HRESULT Operand2([out, retval] long *pVal);
    
    [propput, id(2), helpstring("Operand2 of calculator")]
    HRESULT Operand2([in] long newVal);
    
    [id(3), helpstring("calculator main Operation method")]
    HRESULT DoOperation([in] char operation);
    
    [propget, id(4), helpstring("Result of calculator")]
    HRESULT Result([out, retval] long *pVal);
  };

C++ functions and HRESULT

    virtual HRESULT __stdcall get_Operand1 (long * pVal ) = 0;
    virtual HRESULT __stdcall put_Operand1 (long pVal ) = 0;
    virtual HRESULT __stdcall get_Operand2 (long * pVal ) = 0;
    virtual HRESULT __stdcall put_Operand2 (long pVal ) = 0;
    virtual HRESULT __stdcall raw_DoOperation (char operation ) = 0;
    virtual HRESULT __stdcall get_Result (long * pVal ) = 0;

COM logical return value

COM function can optionally have a return value to the client. Return arguments are marked as [out,retval] in IDL. A function with void return type will not have any [out,retval]. These return arguments are called logical return to client. We have equivalent wrapped functions as below and we see the logical returns values of each "GET" functions. "PUT" functions being a void return will never have any logical return. Client should check the HRESULT code for S_OK / success before processing the logical return value.

Wrapped fucntions

long GetOperand1 ( );
void PutOperand1 (long pVal);
long GetOperand2 ( );
void PutOperand2 (long pVal);
HRESULT DoOperation (char operation);
long GetResult ( );

HRESULT and error handling

  
inline long ICalculate::GetOperand1 ( ) {
    long _result;
    HRESULT _hr = get_Operand1(&_result);
    if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
    return _result;
}

inline void ICalculate::PutOperand1 ( long pVal ) {
    HRESULT _hr = put_Operand1(pVal);
    if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
}
inline long ICalculate::GetResult ( ) {
    long _result;
    HRESULT _hr = get_Result(&_result);
    if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
    return _result;
}

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

 Vote 1

Similar topics related to this section

# COM DCOM Interview Questions and Answers :: ALL Interview .com
# COM DCOM - COM DCOM Interview Questions
# COM interview questions | TechInterviews
# COM Interview Questions - CodeProject
# Com Dcom Interview Questions - Com and Dcom in Asp Net
# ATL Interview Questions and Answers :: ALL Interview .com
# ActiveX Interview Questions and Answers :: ALL Interview .com

* #1 webmaster Mon 28 Apr/2014 01:33:15(GMT)  Like 0 Unlike 0

Dear Users,

We are pleased to inform you that a forum/blog has been incorporated with www.mybestnotes.co.in. You are welcomed to add your comments, requests, codes, solutions and feedback to it. Please login(if already a member) or signup(for free) to avail to this facility.

Regards,
Webmaster

Your message goes here:

Name:Guest
Email:anonymous@unknown.com
My Post:*
Secutiry Code: ******  *
Preview this compose before posting this in discussion forum.
 
Note:
  1. Use [Sxx] code to show smiles. Example [S02]
  2. Use [URL ], example [URL http://www.google.com/]
  3. To display code or un formatted text use [CODE] [/CODE]. Example: [CODE] printf("Hello world"); [/CODE]
 [S01]   [S02]   [S03]   [S04]   [S05]   [S06]   [S07]   [S08] 
 [S09]   [S10]   [S11]   [S12]   [S13]   [S14]   [S15]   [S16] 
 [S17]   [S18]   [S19]   [S20]   [S21]   [S22]   [S23]   [S24] 

Note: Only members are allowed, * fields are mandatory.