Re: Problem with IAddrBook::Address method in C++
- From: Dan Mitchell <djmitchella@xxxxxxxxx>
- Date: Tue, 24 Jan 2006 16:15:58 -0800
"=?Utf-8?B?TGVpZ2g=?=" <Leigh@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
news:DCDAE9A8-B535-4F8E-88B1-F43DFD8EB0FE@xxxxxxxxxxxxx:
> if(FAILED(hResult = lpAdrBook->Address(&hWnd, &adrparm, &lpadrlist)))
Well, if you look up the definition of FAILED, it's
#define FAILED(Status) ((HRESULT)(Status)<0)
> My problem is that if the user just decides to cancel the addressbook
> dialog then S_OK is not returned. In fact it returns a value of
> -2147221229!
which would be a failure code; it's 0x80040113, which is
MAPI_E_USER_CANCEL, which makes perfect sense.
> In essense I don't want to continue if the user cancels
> the dialog, but I also don't want to handle it as an error which it
> would currently do.
And so the dialog is doing the right thing -- if it returned S_OK when
the user pressed "cancel", you'd have no way of knowing that had
happened.
You probably want something along the lines of:
if (FAILED(hr))
{
// something went wrong. Is it a safe error?
if (hr == MAPI_E_USER_CANCEL)
{
// okay, not a fatal error, don't continue but don't die either
}
else
{
// more critical problem, warn the user? exit? something..
}
}
else
{
// it didn't fail, so on we go.
}
Note that that's not quite valid; removing the FAILED() macro to make
it a bit clearer:
if (hr == S_OK)
{
// okay, keep going
}
else if (hr == MAPI_E_USER_CANCEL)
{
// cancelled, fail gently
}
else
{
// some other non S_OK code, fail hard
}
because, for instance, GetProps() can return MAPI_W_ERRORS_RETURNED,
which is 0x40380 -- that will _not_ trigger FAILED(), because it's
"mostly" successful. On the other hand, it's also not S_OK, so code
needs to be aware of this as well. I don't know the complete list of
things that Address() can return, but hopefully you get the basic idea.
Generally speaking, S_OK means "total success" -- anything else means
there was a problem, and it's then up to your code to pick and choose
how much it cares about exactly what went wrong.
-- dan
.
- Follow-Ups:
- Re: Problem with IAddrBook::Address method in C++
- From: Stephen Griffin [MSFT]
- Re: Problem with IAddrBook::Address method in C++
- Prev by Date: Re: Is it possible to subscribe Outlook to Internet Calendar ?
- Next by Date: Re: QueryRows failing when retrieving addresses
- Previous by thread: Re: Is it possible to subscribe Outlook to Internet Calendar ?
- Next by thread: Re: Problem with IAddrBook::Address method in C++
- Index(es):
Relevant Pages
|