-
July 12th, 2021, 10:44 PM
#1
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.
-
July 13th, 2021, 01:32 AM
#2
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
-
July 13th, 2021, 02:21 PM
#3
Re: How to get COM function return value
For me also tli file looks as yours but return value is not present.
-
July 13th, 2021, 02:37 PM
#4
Re: How to get COM function return value
Victor Nijegorodov
-
July 13th, 2021, 11:24 PM
#5
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;
}
-
July 14th, 2021, 01:36 AM
#6
Re: How to get COM function return value
Originally Posted by Bhabesh5194
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
-
July 14th, 2021, 01:44 AM
#7
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.
-
July 14th, 2021, 01:50 AM
#8
Re: How to get COM function return value
Originally Posted by Bhabesh5194
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
-
July 14th, 2021, 01:58 AM
#9
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.
-
July 14th, 2021, 02:50 AM
#10
Re: How to get COM function return value
Originally Posted by Bhabesh5194
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
-
July 14th, 2021, 09:18 PM
#11
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
-
July 15th, 2021, 12:59 AM
#12
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|