changeset 4373:c601f48c7c80

Explicit error log if trying to load a 32bit (resp. 64bit) plugin into a 64bit (resp. 32bit) version of Orthanc
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 17 Dec 2020 10:46:11 +0100
parents bda867e036f3
children 79ef2b6d8e76
files NEWS OrthancFramework/Sources/SharedLibrary.cpp
diffstat 2 files changed, 19 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Mon Dec 14 17:33:17 2020 +0100
+++ b/NEWS	Thu Dec 17 10:46:11 2020 +0100
@@ -6,6 +6,8 @@
 
 * ZIP archives containing DICOM files can be uploaded using WebDAV
 * New config option "MallocArenaMax" to control memory usage on GNU/Linux
+* Explicit error log if trying to load a 32bit (resp. 64bit) plugin into
+  a 64bit (resp. 32bit) version of Orthanc
 
 REST API
 --------
--- a/OrthancFramework/Sources/SharedLibrary.cpp	Mon Dec 14 17:33:17 2020 +0100
+++ b/OrthancFramework/Sources/SharedLibrary.cpp	Thu Dec 17 10:46:11 2020 +0100
@@ -47,7 +47,23 @@
     if (handle_ == NULL)
     {
       LOG(ERROR) << "LoadLibrary(" << path_ << ") failed: Error " << ::GetLastError();
-      throw OrthancException(ErrorCode_SharedLibrary);
+
+      if (::GetLastError() == ERROR_BAD_EXE_FORMAT &&
+          sizeof(void*) == 4)
+      {
+        throw OrthancException(ErrorCode_SharedLibrary,
+                               "You are most probably trying to load a 64bit plugin into a 32bit version of Orthanc");
+      }
+      else if (::GetLastError() == ERROR_BAD_EXE_FORMAT &&
+               sizeof(void*) == 8)
+      {
+        throw OrthancException(ErrorCode_SharedLibrary,
+                               "You are most probably trying to load a 32bit plugin into a 64bit version of Orthanc");
+      }
+      else
+      {
+        throw OrthancException(ErrorCode_SharedLibrary);
+      }
     }
 
 #elif defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) || defined(__OpenBSD__)