Devin Jeanpierre wrote: >> Hmm. Does the API return anything in those cases? >> > It returns None in all cases, so for now to cover that I check > GetLastError, and if it's non-zero (0 being ERROR_SUCCESS, meaning > there was no error-- another constant I don't know where to find), use > FormatMessage to create an exception message and raise WindowsError. > The problem here is that I now have my error-handling code in two > places where I would prefer it to be in only one. >
Unfortunately, that's not safe. GetLastError is not set to 0 when an API succeeds. The "last error" value is only updated when an error actually occurs. When a boolean API returns success, GetLastError might still have a number left over from the last actual error. I'm looking at the source code for the win32file module[1], and it looks to me like it's doing exactly the right thing. If the API returns false ("fail"), it raises an exception, otherwise it returns None. If you are so inclined, perhaps you should try a test case in C to see if this is actually some generic failure in the API. -- [1] - http://pywin32.cvs.sourceforge.net/viewvc/pywin32/pywin32/win32/src/win32file.i?revision=1.107&view=markup -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32