Reputation: 23
I'm a green hand in python and now facing a problem when importing dll in python. By refering some hints found online, i tried using ctypes as below with error prompt.
>>> import ctypes
>>> dl=ctypes.WinDll('C:\\Python27\\Lib\\site-packages\\UdfManagerPython.dll')
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
dl=ctypes.WinDll('C:\\Python27\\Lib\\site-packages\\UdfManagerPython.dll')
AttributeError: 'module' object has no attribute 'WinDll'
>>> dl=ctypes.cdll.LoadLibrary('C:\\Python27\\Lib\\site-packages\\UdfManagerPython.dll')
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
dl=ctypes.cdll.LoadLibrary('C:\\Python27\\Lib\\site-packages\\UdfManagerPython.dll')
File "C:\Python27\lib\ctypes\__init__.py", line 431, in LoadLibrary
return self._dlltype(name)
File "C:\Python27\lib\ctypes\__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126]
Am I doing something wrong or this dll was not scripted complied with python standard? I have uploaded to MediaFire for your analysis. Any help is highly appreciated!
Upvotes: 2
Views: 14040
Reputation: 64949
I loaded the DLL UdfManagerPython.dll
into Dependency Walker, and it pointed out that this DLL has a dependency on python22.dll
. When I tried to load this DLL in the Python (2.7) interpreter, I got a message box which more-or-less told me the same thing:
The program can't start because python22.dll is missing from your computer. Try reinstalling the program to fix this problem.
So it seems this DLL was intended to be used with Python 2.2, not Python 2.7 as you're using.
I don't have Python 2.2 installed. If you do, perhaps you get different error messages to me.
It's also worth pointing out that you can't use ctypes
with Python 2.2, because ctypes
is only supported for Python 2.3 onwards.
I have no idea where this DLL comes from. I Googled its name and got all of four results, one of which was this question.
Incidentally, I've seen an error of the form 'The specified module cannot be found' if the DLL itself can be found but a dependency of the DLL is missing. So if you get a message like this, and you're sure the DLL itself is present, check its dependencies.
EDIT: I tried installing Python 2.2 to see whether I could load this DLL. With Python 2.2 installed you can at least load this DLL, but Python crashes if you try to call either of the init...
methods. (I don't know what parameters to pass them, so I passed them none.)
Here's what happened when I tried calling one of these methods:
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from ctypes import * >>> l = CDLL("UdfManagerPython.dll") >>> l.initPyUdfNumber() Fatal Python error: Interpreter not initialized (version mismatch?) This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information.
I Googled the first line of this error message, and the recurring theme I got from most of the results was that this error indicates you're attempting to load an extension module linked against one version of Python with a different version of Python.
So in answer to your question in the comments, no, I don't believe there is a way to load this DLL in Python 2.7.
Upvotes: 1
Reputation: 76762
Try WinDLL
or CDLL
.
I never used LoadLibrary
directly in ctypes
, but it looks like it still might not be finding the DLL. Make sure it's on your system path. (Or in the same directory as your Python module.)
Upvotes: 0
Reputation: 11585
WinDll should be all lowercase.
dl = ctypes.windll('C:\\Python27\\Lib\\site-packages\\UdfManagerPython.dll')
Upvotes: 0