NT specific change for nicer error message (Mark H)

This commit is contained in:
Guido van Rossum 1995-07-18 14:40:09 +00:00
parent 2271bf7187
commit 11a3f0c2bc
1 changed files with 32 additions and 3 deletions

View File

@ -336,9 +336,38 @@ load_dynamic_module(name, pathname, fp)
HINSTANCE hDLL; HINSTANCE hDLL;
hDLL = LoadLibrary(pathname); hDLL = LoadLibrary(pathname);
if (hDLL==NULL){ if (hDLL==NULL){
char errBuf[64]; char errBuf[256];
sprintf(errBuf, "DLL load failed with error code %d", unsigned int errorCode;
GetLastError());
/* 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); err_setstr(ImportError, errBuf);
return NULL; return NULL;
} }