self._handle = _dlopen(self._name, mode) OSError: [WinError126] The specified module could not found

When doing the project, due to the need to do DLL to speed up, but often burst out error

File "C:\Users\32373\AppData\Local\Programs\Python\Python37\lib\ctypes\__init__.py", line 434, in LoadLibrary
    return self._dlltype(name)
  File "C:\Users\32373\AppData\Local\Programs\Python\Python37\lib\ctypes\__init__.py", line 356, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

The example code is as follows

from ctypes import cdll
class Demo():
	def __init__(self):
		self.__path = "ZeissControl2.dll"
		self.__Library = cdll.LoadLibrary(self.__path)

It’s also a bug that has been bothering me for a long time.
for this problem, I summarize two reasons:

    the first thing is to check whether the path of the DLL file is correct. If it is correct, that is the second reason. When we generate a custom DLL, we usually rely on a variety of other DLL files, so we need to add other DLL files that the DLL calls depends on to the program running directory. In this case, the program can run perfectly in general

    However, in general, in addition to the specified DLL files, user-defined DLL files may also rely on the DLL files of the system environment
    in the latter case, we generally do not know which DLL files we rely on

    Fortunately, Visual Studio provides dumpbin/dependencies tool to get the list of DLL files that the specified DLL depends on
    specific operation
    Start Menu = & gt& gt; visual studio 2017 or 2019 ===>& gt; Developer Command Prompt for VS 2017 or 2019

    After opening the terminal and entering the dumpbin command, you can see that

    we want to view the list of other DLL files that the specified DLL file depends on. The command is as follows

    dumpbin /dependents your_ dll_ path

    For example,

Read More: