summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1995-07-18 14:40:09 (GMT)
committerGuido van Rossum <guido@python.org>1995-07-18 14:40:09 (GMT)
commit11a3f0c2bca1a8fdea396b989559f25fbc6fe65e (patch)
tree4365b92fa847379e5ac3810d35c3901c4b70c603 /Python
parent2271bf718734625dd19202d752a67b5f54cf2000 (diff)
downloadcpython-11a3f0c2bca1a8fdea396b989559f25fbc6fe65e.zip
cpython-11a3f0c2bca1a8fdea396b989559f25fbc6fe65e.tar.gz
cpython-11a3f0c2bca1a8fdea396b989559f25fbc6fe65e.tar.bz2
NT specific change for nicer error message (Mark H)
Diffstat (limited to 'Python')
-rw-r--r--Python/importdl.c35
1 files changed, 32 insertions, 3 deletions
diff --git a/Python/importdl.c b/Python/importdl.c
index 16b50af..65f2f72 100644
--- a/Python/importdl.c
+++ b/Python/importdl.c
@@ -336,9 +336,38 @@ load_dynamic_module(name, pathname, fp)
HINSTANCE hDLL;
hDLL = LoadLibrary(pathname);
if (hDLL==NULL){
- char errBuf[64];
- sprintf(errBuf, "DLL load failed with error code %d",
- GetLastError());
+ char errBuf[256];
+ unsigned int errorCode;
+
+ /* Get an error string from Win32 error code */
+ char theInfo[256]; /* Pointer to error text from system */
+ int theLength; /* Length of error text */
+
+ errorCode = GetLastError();
+
+ theLength = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, /* flags */
+ NULL, /* message source */
+ errorCode, /* the message (error) ID */
+ 0, /* default language environment */
+ (LPTSTR) theInfo, /* the buffer */
+ sizeof(theInfo), /* the buffer size */
+ NULL); /* no additional format args. */
+
+ /* Problem: could not get the error message. This should not happen if called correctly. */
+ if (theLength == 0) {
+ sprintf(errBuf, "DLL load failed with error code %d", errorCode);
+ } else {
+ int len;
+ /* For some reason a \r\n is appended to the text */
+ if (theLength >= 2 && theInfo[theLength-2] == '\r' && theInfo[theLength-1] == '\n') {
+ theLength -= 2;
+ theInfo[theLength] = '\0';
+ }
+ strcpy(errBuf, "DLL load failed: ");
+ len = strlen(errBuf);
+ strncpy(errBuf+len, theInfo, sizeof(errBuf)-len);
+ errBuf[sizeof(errBuf)-1] = '\0';
+ }
err_setstr(ImportError, errBuf);
return NULL;
}