python ctypes

windows API
from ctypes import windll
kernel32 = windll.kernel32

https://docs.python.org/2/library/ctypes.html
http://www.ibm.com/developerworks/cn/linux/l-cn-pythonandc/
官方说法:允许python去调用DLLs和共享库中的c函数。
ctypes is a foreign function library for Python. It provides C compatible data types, and allows calling functions in DLLs or shared libraries. It can be used to wrap these libraries in pure Python

linux
python中如何使用c的动态链接库
from ctypes import *
libc = CDLL(“libc.so.6”)
libc

windows
libc = cdll.msvcrt

Structures and unions must derive from the Structure and Union base classes which are defined in the ctypes module. Each subclass must define a fields attribute. fields must be a list of 2-tuples, containing a field name and a field type

from ctypes import *
class POINT(Structure):
fields = [(“x”, c_int),
… (“y”, c_int)]

point = POINT(10, 20)
print point.x, point.y
10 20
point = POINT(y=5)
print point.x, point.y
0 5

from ctypes import pointer

i = c_int(42)
pi = pointer(i)
print pi.contents

Note that ctypes does not have OOR (original object return), it constructs a new, equivalent object each time you retrieve an attribute:

这里写图片描述

转载于:https://www.cnblogs.com/lineuman/p/6775999.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值