C DLL is loaded into C ++ program, not python Ctypes

Question about loading python / ctypes and dll.

I have created a C Dll (extern C declarations) using VSExpress 2010. I can load and execute this DLL using the CPP test program. However, when I try to load the dll in python via ctypes, I get the old "WindowsError: [Errno 126] The specified module could not be found" error message.

So far I have done the following:

1.) The troika checked the DLL path on the python side and tried the absolute path to make sure the DLL was found completely.

2.) A DLL appeared in the depends.exe file and it was checked that there is nothing in the dependency tree that can be seen in the dependency tree (on Win 7, so the result depends a bit flaky, but from research nothing seems out of place, everyone knows the dependent tool. compatible with Win7?)

3.) I have a .bat file that sets all my environment variables and also takes other actions (depending on localization) to make sure all dependencies are resolved. Again, it all depends on whether it demonstrates clean, except for typical Win7 OS glitches.

Does anyone know of a good way to debug this type of problem? Does this determine the best option? A way to see which symbol / module failed to load from python?

Again, the CPP test program loads and runs the dlls perfectly. Not really sure what's going on on the Python side. Any help with debugging is appreciated.

Thank.

+2


source to share


1 answer


Use Sysinternals Process Monitor . Configure it to control the process python.exe

for operations CreateFile

:

Process Monitor Filter dialog

Then run your script. In the example below, I ran:



>>> from ctypes import *
>>> CDLL('x')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\dev\Python33x64\lib\ctypes\__init__.py", line 353, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

      

x.dll

does not exist with the following result at the bottom of the trace, but note that any missing dependent DLL will display similarly:

Process Monitor trace

+1


source







All Articles