[python-win32] Convert MAPI error code numbers into meaningful strings

Tim Roberts timr at probo.com
Tue Mar 20 17:45:23 CET 2012


Sriram ET. wrote:
>
> Are there any functions in pywin32 to convert, say, 0x8004010f
> into MAPI_E_NOT_FOUND?

Do you mean, convert that number into the string MAPI_E_NOT_FOUND?  In
general, no.  Even the C API does not do that, because in C the symbol
MAPI_E_NOT_FOUND is just a compile-time alias for the number
0x8004010f.  That is, the string "MAPI_E_NOT_FOUND" will not occur in
any C executable.

However, you can use the FormatMessage API to get a reasonable string
from that:
    win32api.FormatMessage(0x8004010f)

> In general, what is the common / recommended way to deal with MAPI
> errors in pywin32 code?

I'm not sure it's possible to answer that question.  You need to decide
that yourself.  There are some errors you can recover from gracefully,
and for those you can check the numeric values individually.  There are
other errors that you can't handle, and you shouldn't try.  Either show
them to the user or let the program expire.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list