Skip to content

Commit 7145515

Browse files
committed
Extend PyWin_SetAPIError
1 parent e0fda45 commit 7145515

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

win32/src/PyWinTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ extern PYWINTYPES_EXPORT BOOL PyWin_RegisterErrorMessageModule(DWORD first, DWOR
101101
extern PYWINTYPES_EXPORT HINSTANCE PyWin_GetErrorMessageModule(DWORD err);
102102

103103
/* A global function that sets an API style error (ie, (code, fn, errTest)) */
104-
PYWINTYPES_EXPORT PyObject *PyWin_SetAPIError(char *fnName, long err = 0);
104+
PYWINTYPES_EXPORT PyObject *PyWin_SetAPIError(const char *fnName, long err = 0, bool returnNoneOnSuccess = false);
105105

106106
/* Basic COM Exception handling. The main COM exception object
107107
is actually defined here. However, the most useful functions

win32/src/PyWinTypesmodule.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,11 @@ HINSTANCE PyWin_GetErrorMessageModule(DWORD err)
275275
}
276276

277277
/* error helper - GetLastError() is provided, but this is for exceptions */
278-
PyObject *PyWin_SetAPIError(char *fnName, long err /*= 0*/)
278+
PyObject *PyWin_SetAPIError(const char *fnName, long err /*= 0*/, bool returnNoneOnSuccess /*= false*/)
279279
{
280280
DWORD errorCode = err == 0 ? GetLastError() : err;
281+
if ((returnNoneOnSuccess) && (!errorCode))
282+
Py_RETURN_NONE;
281283
DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS;
282284
// try and find the hmodule providing this error.
283285
HMODULE hmodule = PyWin_GetErrorMessageModule(errorCode);

0 commit comments

Comments
 (0)