"Python" References C's DLL

Source: Internet
Author: User

1. Reference methods

There are two kinds of loading methods on the net, introduce many, no longer repeat

StdCall calling convention

Ctypes.windll.LoadLibrary ("DllPath")

cTYPES. Windll ("DllPath")

CDECL calling convention

Ctypes.cdll.LoadLibrary ("DllPath")

cTYPES. Cdll ("DllPath")

cTYPES data Type C data type
C_char Char
C_short Short
C_int int
C_long Long
C_ulong Unsign Long
C_float float
C_double Double
c_void_p void
The corresponding pointer type is appended with "_p", such as int* is c_int_p and so on.
In Python to implement the structure in C, you need to use classes.

2. Error

The call reported the following error
Enter Q to Quit:dll
Traceback (most recent):
File "G:\000 WORK\10 license plate number \query\test.py", line A, in <module>
Yzm ()
File "G:\000 WORK\10 license plate number \query\test.py", line series, in Yzm
Lm_dll = cTYPES. Windll ("./lm.dll")
File "C:\Python27\lib\ctypes\__init__.py", line 365, in __init__
Self._handle = _dlopen (self._name, mode)
Windowserror: [Error 193]%1 is not a valid Win32

Python is found to be installed in 64 bits, while DLLs are 32 bits. Install 32-bit Python problem resolution

"Python" References C's DLL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.