Re: Problem with IAddrBook::Address method in C++

Tech-Archive recommends: Fix windows errors by optimizing your registry



"=?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
.



Relevant Pages

  • Re: Problem with IAddrBook::Address method in C++
    ... that code that blindly fails when GetProps returns ... MAPI_W_ERRORS_RETURNED is going to assume failure states that don't actually ... >> My problem is that if the user just decides to cancel the addressbook ... > // it didn't fail, ...
    (microsoft.public.win32.programmer.messaging)
  • Losing control
    ... After my desk top loads, when I click onto explorer, or even control panel, ... the action will cancel or fail (not execute). ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: Yoruba Shrine
    ... sachen asked the original question. ... cancel it then you could do it again, but since it makes it fail you ... That's why I'm seeking LSJ clarification. ...
    (rec.games.trading-cards.jyhad)
  • Re: Yoruba Shrine
    ... cardlist and was going with the wording in your question. ... cancel it then you could do it again, but since it makes it fail you ... That's why I'm seeking LSJ clarification. ...
    (rec.games.trading-cards.jyhad)
  • Re: pushing parallel and constraint programming
    ... that A succeeds does not allow you to cancel B, since might ... fail, so that finally will only succeed. ... Okay we need to be more careful about this. ...
    (comp.lang.prolog)