Article View: borland.public.cppbuilder.internet.socket
Article #3045Re: Timeout Issues [Indy 9]
From: Remy Lebeau (TeamB)
Date: Mon, 28 Nov 2005 18:12
Date: Mon, 28 Nov 2005 18:12
94 lines
4316 bytes
4316 bytes
"Darlington ADIBE" <bcb@triative.com> wrote in message
news:43878392@newsgroups.borland.com...
> Using this code means that the calling application have to test
> the returned String (*pVal) for NULL (or empty string), if it
> NULL or empty it mean then that an error occured.
No, it does not. That is not how you are supposed to be handling COM errors
in the first place. You need to check the HRESULT that the method actually
returns. When everything is ok, the HRESULT is set to either S_OK or some
other positive number. A negative number indicates an error. That is how
COM determines whether an error actually occured or not. For example:
WideString result;
if( pEesemesAPI->sendSMS(WideString("some text here"), WideString("some
number here"), &result) >= 0 )
// ok, use result as needed...
else
// failed, do something else...
Or, using standard COM macros:
WideString result;
if( SUCCEEDED(pEesemesAPI->sendSMS(WideString("some text here"),
WideString("some number here"), &result)) )
// ok, use result as needed...
else
// failed, do something else...
Or:
WideString result;
if( FAILED(pEesemesAPI->sendSMS(WideString("some text here"),
WideString("some number here"), &result)) )
// failed, do something else...
else
// ok, use result as needed...
In these examples, I am using the WideString class to manage all of the BSTR
memory management automatically. Otherwise, you have to call
SysAllocString...() and SysFreeString() manually every time.
> Can he retrive the error details and how?
To get extended error information beyond the HRESULT value, he would have to
call COM's GetErrorInfo() function to retreive an IErrorInfo interface. The
Error() method inside your COM object creates an IErrorInfo interface
internally that GetErrorInfo() can then retreive later. For example:
WideString result;
HRESULT hRes = pEesemesAPI->sendSMS(WideString("some text here"),
WideString("some number here"), &result);
if( SUCCEEDED(hRes) )
// ok, use result as needed...
else
{
// failed, do something else...
TComInterface<ISupportErrorInfo> Intf;
if( SUCCEEDED(pEesemesAPI->QueryInterface(IID_ISupportErrorInfo,
(LPVOID*)&Intf)) )
{
if( Intf->InterfaceSupportsErrorInto(IID_IesemesAPI) == S_OK )
{
TComInterface<IErrorInfo> Err;
if( GetErrorInfo(0, &Err) == S_OK )
{
WideString ErrMsg;
Err->GetDescription(&ErrMsg);
// use ErrMsg as needed...
}
else
// no error info is available...
}
}
else
// use hRes as needed...
}
> For BCB programmer GetLastError() i assume
No. GetLastError() has no meaning in COM. It is a Win32 API error
mechanism, not a COM one.
> how about other platforms (VB) do they have such facility?
VB uses GetErrorInfo() and the IErrorInfo interface. However, VB is very
tightly integrated with COM, so a lot of these details are hidden from VB
users, as VB handles all of the error handling and error reporting
automatically.
Gambit
Technical Details
Message-ID:
<438b485b$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news.moat.net!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<43864c38@newsgroups.borland.com> <4386ba83$1@newsgroups.borland.com> <43878392@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,83a059fbd8c24375 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.internet.socket References: <43864c38@newsgroups.borland.com> <4386ba83$1@newsgroups.borland.com> <43878392@newsgroups.borland.com> Subject: Re: Timeout Issues [Indy 9] Date: Mon, 28 Nov 2005 10:12:05 -0800 Lines: 96 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <438b485b$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1133201499 68.69.17.41 (28 Nov 2005 10:11:39 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news.moat.net!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail