Skip to content

Instantly share code, notes, and snippets.

@WindfallLabs
Created November 5, 2015 22:00
Show Gist options
  • Save WindfallLabs/d7a97c05b9527bf70cf7 to your computer and use it in GitHub Desktop.
Save WindfallLabs/d7a97c05b9527bf70cf7 to your computer and use it in GitHub Desktop.
A short gist derrived from dlsw on how to test if a DLL is on your PATH
# A short gist derrived from dlsw on how to test if a DLL is on your PATH. (Best with try/except blocks)
import os
from ctypes import WinDLL
from _ctypes import FreeLibrary # DON'T FORGET THE '_'
dll = "mod_spatialite.dll" # or whatever DLL your heart desires
assert not dll in os.listdir(os.getcwd()) # Ensures that the DLL will not false-positive load because it's in the current working dir
loaded_dll = WinDLL(dll) # Attempt to load DLL. If the DLL is not on PATH or in os.getcwd() it will raise a WindowsError
FreeLibrary(loaded_dll._handle) # if successful, we should be good neigbors and unload it
del loaded_dll # completely rid of the memory instance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment