Skip to content

gpib-32.dll fails to load with Keysight Instrument Control Bundle #7

Description

@TomasTollemark

I have found a bug in the gpib-ctypes loading of DLL’s. It will fail if gpib-32.dll contains dependencies to other DLL’s outside the system32 directory.

For example the “Keysight_Instrument_Control_Bundle” installs the following files:
C:\Windows\System32\gpib-32.dll
C:\Program Files\Keysight\IO Libraries Suite\bin\ioPersistedDataAccess.dll

But ctypes calls LoadLibraryEx with dwFlags=LOAD_LIBRARY_SEARCH_DEFAULT_DIRS causing it to fail to load the ioPersistedDataAccess.dll since it is not in the System32 folder.

One solution is to set winmode=0 in ctypes like this:
_lib = ctypes.WinDLL(libname, winmode = 0)

My code changes are:

diff --git "a/gpib_orig.py" "b/gpib.py"
index 64bb0e8..b822ebc 100644
--- "a/gpib_orig.py"
+++ "b/gpib.py"
@@ -32,15 +32,16 @@ def _load_lib(filename=None):
                     'c:\\windows\\system\\gpib-32.dll',
                     'c:\\gpib\\gpib-32.dll',
                     'gpib-32.so', 'libgpib.so.0']
-        loader = ctypes.windll.LoadLibrary
     else:
         # most likely Linux with linux-gpib
         libnames = [filename] if filename else ['libgpib.so.0', 'gpib-32.so']
-        loader = ctypes.cdll.LoadLibrary
     for libname in libnames:
         try:
-            _lib = loader(libname)
+            if platform.system() == "Windows":
+                _lib = ctypes.WinDLL(libname, winmode = 0)
+            else:
+                _lib = ctypes.cdll.LoadLibrary(libname)
             break
         except OSError:
             continue

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions