Skip to content

Commit

Permalink
Update mdi.py
Browse files Browse the repository at this point in the history
  • Loading branch information
taylor-a-barnes authored Jan 24, 2025
1 parent 804ef12 commit 7692b0c
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions MDI_Library/mdi.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
""" Python wrapper for MDI. """

import os
from pathlib import Path
dir_path = os.path.dirname(os.path.realpath(__file__))
os.environ["PATH"] += r";C:\Program Files (x86)\mdi\bin"

# Add the directory containing the DLL
#dll_directory = Path("C:\\Program Files (x86)\\mdi\\bin")
#os.add_dll_directory(str(dll_directory))
#print("AAAAAAAAAAAAAAAAAA: " + str(dll_directory))

for p in os.environ["PATH"].split( ';' ):
if os.path.isdir( p ):
os.add_dll_directory( p )

import ctypes
import sys
Expand Down Expand Up @@ -46,6 +35,14 @@
mdi = ctypes.CDLL(mdi_path, ctypes.RTLD_GLOBAL)
MDI_COMMAND_LENGTH = ctypes.c_int.in_dll(mdi, "MDI_COMMAND_LENGTH").value
except (ValueError, AttributeError, OSError) as e:

os.environ["PATH"] += r";C:\Program Files (x86)\mdi\bin"

# On Windows, every DLL directory must be added through "add_dll_directory", or Python will refuse to open them
for p in os.environ["PATH"].split( ';' ):
if os.path.isdir( p ):
os.add_dll_directory( p )

mdi = ctypes.WinDLL(mdi_path, ctypes.RTLD_GLOBAL)
MDI_COMMAND_LENGTH = ctypes.c_int.in_dll(mdi, "MDI_COMMAND_LENGTH").value

Expand Down

0 comments on commit 7692b0c

Please sign in to comment.