The calling code
Note: C++ files (CPP) : (Add extern “C” modifiers to function declarations) otherwise the method name will not be recognized by Python
Load it depending on what convention the function you’re going to call conforms to. Windll and CDLL are objects of the windll and CDLL classes, respectively
Stdcall calling convention:
Objdll = ctypes. Windll. LoadLibrary (” dllpath “)
Objdll = ctypes. Windll (” dllpath “)
Cdecl calling convention:
Objdll = ctypes.cdl. LoadLibrary(“dllpath”)
Objdll = ctypes.cdll (“dllpath”)
After the call, you can use the functions in the DLL
print Objdll.Add(1, 102)
Objdll = ctypes.cdl.loadlibrary (“D:\\ DLL \\ \PosterDetector. DLL “)
An error
USES python to call C++ DLL to report an error
Traceback (most recent call last):
File “E:/work/proc/video_web/application.py”, line 157, in < module>
Objdll = ctypes.cdl.loadlibrary (os.path.join(APP_ROOT,” DLL “,”PosterDetector. DLL “)
File “d:\python27\Lib\ctypes\ init__. Py “, line 444, In LoadLibrary
return self._dlltype(name)
File “d:\ Lib\ctypes\ ___, init__ “, line 366, in ___
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126]
To solve
The reason is that PosterDetector also relies on other DLLS,
Simply putting the two DLL files in the same directory doesn’t work, because the Python process didn’t start on the same directory as PosterDetector.
put the other DLLS and the current PosterDetector. DLL in the same folder and add the code:
os.chdir(D:\\ DLL “))
Note: C++ files (CPP) : (Add extern “C” modifiers to function declarations) otherwise the method name will not be recognized by Python
Load it depending on what convention the function you’re going to call conforms to. Windll and CDLL are objects of the windll and CDLL classes, respectively
Stdcall calling convention:
Objdll = ctypes. Windll. LoadLibrary (” dllpath “)
Objdll = ctypes. Windll (” dllpath “)
Cdecl calling convention:
Objdll = ctypes.cdl. LoadLibrary(“dllpath”)
Objdll = ctypes.cdll (“dllpath”)
After the call, you can use the functions in the DLL
print Objdll.Add(1, 102)
Objdll = ctypes.cdl.loadlibrary (“D:\\ DLL \\ \PosterDetector. DLL “)
An error
USES python to call C++ DLL to report an error
Traceback (most recent call last):
File “E:/work/proc/video_web/application.py”, line 157, in < module>
Objdll = ctypes.cdl.loadlibrary (os.path.join(APP_ROOT,” DLL “,”PosterDetector. DLL “)
File “d:\python27\Lib\ctypes\ init__. Py “, line 444, In LoadLibrary
return self._dlltype(name)
File “d:\ Lib\ctypes\ ___, init__ “, line 366, in ___
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126]
To solve
The reason is that PosterDetector also relies on other DLLS,
Simply putting the two DLL files in the same directory doesn’t work, because the Python process didn’t start on the same directory as PosterDetector.
put the other DLLS and the current PosterDetector. DLL in the same folder and add the code:
os.chdir(D:\\ DLL “))
Read More:
- Python calls C to generate so library and reports an error: undefined symbol
- The springboot integration CXF calls WebService and reports an error: cannot create a secure xmlinputfactory
- Hadoop reports an error. Cannot access scala.serializable and python MapReduce reports an error
- Error loading Python DLL ‘python36.dll’. LoadLibrary: The specified module could not be found.
- Windowserror: [error 183] error and in Python os.raname () detailed explanation
- The python script tool of ArcGIS reports an error: indentationerror: unexpected indent solution
- Start Tomcat and report an error: tcnative-1.dll: can’t load ia 32-bit. DLL on a amd 64 bit platform
- Running Django (2.2) project in Python 3.7.9 reports an error
- The echots in Vue reports an error. After obtaining the DOM element, the chart can be displayed. The console still reports an error
- HTML method IE8 reports an error, IE8 jQuery Ajax obtains static resources reports an error, typeerror denies access
- The file server reports an error of 413, and the file uploaded by nginx reports an error of 413 request entity too large
- Lamdba in the studio part reports an error. Observe lamdba reports an error but can run
- Python3 reports an error [errno 5] input / output error. Print is used when there is no stdout
- Python call DLL pointer parameter
- SSM project controller layer calls static method to report an error
- The remote server returned an error: notfound when Silverlight calls WCF service
- Eclipse reports Failed to load the JNI shared library jvm.dll error solution
- CentOS solves the problem of modulenotfounderror when salt calls python3 script remotely, and solves the problem that PIP3 module cannot be shared by different users
- Solution: windowserror: [error 2]
- Workaround: windowserror: [error 193]% 1 is not a valid Win32 Application