2017-05-14 1 views
0

J'essaie de charger un fichier .dll à partir de Python. J'utilise Python 3.0.17114.1 avec Visual Studio 2017 Preview. Je reçois une erreur disant "NameError: nom LoadLibrary n'est pas défini".Python LoadLibrary non trouvé

est ici un petit bout de code (notez que theDll sort parfait):

import ctypes 
from ctypes.util import find_library 
from ctypes import LibraryLoader 
from ctypes.util import find_library  
theDll = find_library('DsiLibrary_dll') 
dsi_lib = LoadLibrary(theDll) 

Alors je lis sur LoadLibrary et il y a plusieurs façons de le faire. J'ai essayé tout ce que je pouvais trouver:

cdll.LoadLibrary(theDll) 
CDLL.LoadLibrary(theDll) 
ctypes.CDLL.LoadLibrary(theDll) 
ctypes.LoadLibrary(theDll) 

Je suis très nouveau à Python afin que je puisse avoir fait une erreur stupide. Quelqu'un peut-il faire une suggestion?

Répondre

1

Vous pouvez accéder à LoadLibrary comme ceci:

import ctypes 
from ctypes import cdll 
from ctypes.util import find_library  
theDll = find_library('DsiLibrary_dll') 
lib = cdll.LoadLibrary(theDll) 
# do stuff with lib 

Ctypes documentation:

On Linux, it is required to specify the filename including the extension to load a library, so attribute access can not be used to load libraries. Either the LoadLibrary() method of the dll loaders should be used, or you should load the library by creating an instance of CDLL by calling the constructor:

>>> from ctypes import * 
>>> cdll.LoadLibrary("libc.so.6") 
<CDLL 'libc.so.6', handle ... at ...> 
>>> libc = CDLL("libc.so.6")  
>>> libc 
<CDLL 'libc.so.6', handle ... at ...> 
>>> 
+0

J'utilisé votre méthode Windows, mais qui donne la même erreur non définie. – Eddy

+0

Aucune erreur pour moi, qu'avez-vous fait? – abccd

+0

J'ai fait un copier-coller de votre message. ctypes à l'importation de ctypes importation CDLL de ctypes.util importation find_library theDll = find_library ('DsiLibrary_dll') dsi_lib = cdll.LoadLibrary (theDll) – Eddy