ctypes是Python的一个外部库,提供和C语言兼容的数据类型,可以很方便地调用CDLL中的函数。ctypes的官方文档在这里。
1. ctypes基本数据类型映射表
参数类型预先设定好,或者在调用函数时再把参数转成相应的c_***类型。ctypes的类型对应如下:
ctypes type
C type
Python Type
c_char
char
1-character string
c_wchar
wchar_t
1-character unicode string
c_byte
char
int/long
c_ubyte
unsigned char
int/long
c_bool
bool
bool
c_short
short
int/long
c_ushort
unsigned short
int/long
c_int
int
int/long
c_uint
unsigned int
int/long
c_long
long
int/long
c_ulong
unsigned long
int/long
c_longlong
__int64 or longlong
int/long
c_ulonglong
unsigned __int64 or unsigned long long<