diff options
author | apnadkarni <apnmbx-wits@yahoo.com> | 2017-09-21 19:05:11 (GMT) |
---|---|---|
committer | apnadkarni <apnmbx-wits@yahoo.com> | 2017-09-21 19:05:11 (GMT) |
commit | 4bf8f43b3a8029883f5c5f566ff9afaaecc33e6f (patch) | |
tree | dca086ebc8844a5972ab239522744676af500591 /win | |
parent | 1b28405773771365e5ad486b41fe5f2c43703d27 (diff) | |
download | tcl-4bf8f43b3a8029883f5c5f566ff9afaaecc33e6f.zip tcl-4bf8f43b3a8029883f5c5f566ff9afaaecc33e6f.tar.gz tcl-4bf8f43b3a8029883f5c5f566ff9afaaecc33e6f.tar.bz2 |
RFE [566a999189] - better error message for 32/64 bit mismatch on load.
Diffstat (limited to 'win')
-rw-r--r-- | win/tclWinLoad.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/win/tclWinLoad.c b/win/tclWinLoad.c index 26512b1..3ad6328 100644 --- a/win/tclWinLoad.c +++ b/win/tclWinLoad.c @@ -66,6 +66,7 @@ TclpDlopen( HINSTANCE hInstance; const TCHAR *nativeName; Tcl_LoadHandle handlePtr; + DWORD firstError; /* * First try the full path the user gave us. This is particularly @@ -84,6 +85,12 @@ TclpDlopen( Tcl_DString ds; + /* + * Remember the first error on load attempt to be used if the + * second load attempt below also fails. + */ + firstError = GetLastError(); + nativeName = Tcl_WinUtfToTChar(Tcl_GetString(pathPtr), -1, &ds); hInstance = LoadLibraryEx(nativeName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); @@ -91,8 +98,21 @@ TclpDlopen( } if (hInstance == NULL) { - DWORD lastError = GetLastError(); - Tcl_Obj *errMsg = Tcl_ObjPrintf("couldn't load library \"%s\": ", + DWORD lastError; + Tcl_Obj *errMsg; + + /* + * We choose to only use the error from the second call if the first + * call failed due to the file not being found. Else stick to the + * first error for reporting purposes. + */ + if (firstError == ERROR_MOD_NOT_FOUND || + firstError == ERROR_DLL_NOT_FOUND) + lastError = GetLastError(); + else + lastError = firstError; + + errMsg = Tcl_ObjPrintf("couldn't load library \"%s\": ", Tcl_GetString(pathPtr)); /* @@ -129,7 +149,11 @@ TclpDlopen( Tcl_AppendToObj(errMsg, "the library initialization" " routine failed", -1); break; - default: + case ERROR_BAD_EXE_FORMAT: + Tcl_SetErrorCode(interp, "WIN_LOAD", "BAD_EXE_FORMAT", NULL); + Tcl_AppendToObj(errMsg, "Bad exe format. Possibly a 32/64-bit mismatch.", -1); + break; + default: TclWinConvertError(lastError); Tcl_AppendToObj(errMsg, Tcl_PosixError(interp), -1); } |