CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Jul 2021
    Posts
    6

    How to get COM function return value

    I am using COM function in my code,I have only tli file of the the com project so how will I be able to get the return value of the COM function as in tli file it's not present,where can I see the return value.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to get COM function return value

    And how does your function from .tli file look like?
    For example some functions from my msadox.tli look like
    Code:
    //
    // interface _Collection wrapper method implementations
    //
    
    inline long _Collection::GetCount ( ) {
        long _result;
        HRESULT _hr = get_Count(&_result);
        if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
        return _result;
    }
    
    inline IUnknownPtr _Collection::_NewEnum ( ) {
        IUnknown * _result;
        HRESULT _hr = raw__NewEnum(&_result);
        if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
        return IUnknownPtr(_result, false);
    }
    ...
    Additional info: https://forums.codeguru.com/showthre...-and-tli-files
    Victor Nijegorodov

  3. #3
    Join Date
    Jul 2021
    Posts
    6

    Re: How to get COM function return value

    For me also tli file looks as yours but return value is not present.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to get COM function return value

    Quote Originally Posted by Bhabesh5194 View Post
    For me also tli file looks as yours but return value is not present.

    Please, provide the definition (that looks as my one) of the function from your .tli
    Victor Nijegorodov

  5. #5
    Join Date
    Jul 2021
    Posts
    6

    Re: How to get COM function return value

    inline HRESULT INotifierWrapper::func(){
    HRESULT _hr=raw_func();
    if(FAILED(_hr)) _com_issue_errorex(_hr,this,_uuidof(this));
    return _hr;
    }

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to get COM function return value

    Quote Originally Posted by Bhabesh5194 View Post
    inline HRESULT INotifierWrapper::func(){
    HRESULT _hr=raw_func();
    if(FAILED(_hr)) _com_issue_errorex(_hr,this,_uuidof(this));
    return _hr;
    }
    As you can see the function is of type HRESULT . In its code implementation it is very clear:
    Code:
    HRESULT _hr=raw_func();
    ...
    return _hr;
    Note, however, that is case of some failure the exception _com_issue_errorex is thrown. To catch such an exception you must use try/catch(_com_error& e) blocks. See the example here.
    Victor Nijegorodov

  7. #7
    Join Date
    Jul 2021
    Posts
    6

    Re: How to get COM function return value

    Yes some functions having HRESULT type but some returns E_FAIL and some return S_OK ,I want to check that which functions are returning failure cases.

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to get COM function return value

    Quote Originally Posted by Bhabesh5194 View Post
    Yes some functions having HRESULT type but some returns E_FAIL and some return S_OK ,I want to check that which functions are returning failure cases.
    Both E_FAIL and S_OK are possible values of HRESULT. The most of functions do not "return" anything in "failure cases": instead (as I already mentioned in my precious post) they throw the exceptions!
    Victor Nijegorodov

  9. #9
    Join Date
    Jul 2021
    Posts
    6

    Re: How to get COM function return value

    Both are possible values of HRESULT but let's say in function definition its return value is S_OK only ,it will never return other than S_OK or the exception,can I detect that from tli file.

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to get COM function return value

    Quote Originally Posted by Bhabesh5194 View Post
    Both are possible values of HRESULT but let's say in function definition its return value is S_OK only ,it will never return other than S_OK or the exception,can I detect that from tli file.
    Why do you guess rather than read the documentation?
    FAILED macro
    And the exact HRESULT value in the case of "FAILED" you can obtain from the _com_error& e reference:
    https://docs.microsoft.com/en-us/cpp...?view=msvc-160
    https://docs.microsoft.com/en-us/cpp...?view=msvc-160
    Victor Nijegorodov

  11. #11
    Join Date
    Jul 2021
    Posts
    6

    Re: How to get COM function return value

    Thanks VictorN,is there any way I can goto cpp file from tli file or can I see the actual definition of function

  12. #12
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to get COM function return value

    Place cursor over the function you are interesting in, then right mouse click/context menu -> choose the Peek Definition (or Go to Definition or Go to Declaration). It works also my macros, typedefs and so on...
    Victor Nijegorodov

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured