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!
I loaded the DLL
UdfManagerPython.dllinto Dependency Walker, and it pointed out that this DLL has a dependency onpython22.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: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
ctypeswith Python 2.2, becausectypesis 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.