引用动态库

1、引用so库:

from ctypes import *

>>>CDLL("libc.so.6").printf("12345\n")
12345

>>>cdll.LoadLibrary("libc.so.6").printf("12345\n")

12345

2、引用DLL库:

2.1、python2.7.13下的验证

>>>cdll.LoadLibrary("msvcrt.dll").printf("test\n")

test

>>>cdll.LoadLibrary("msvcrt").printf("test\n")

test

>>>cdll.msvcrt.printf("test\n")

test

>>>CDLL("msvcrt").printf("test\n")

test

>>>CDLL("msvcrt.dll").printf("test\n")

test

 

2.2、python3.5下的验证

>>>CDLL("libc.so.6").printf("test\n".encode("utf-8"))

test

>>>cdll.LoadLibrary("msvcrt.dll").printf("test\n".encode("utf-8"))

test

>>>CDLL("msvcrt").printf("test\n".encode("utf-8"))

test

>>>cdll.msvcrt.printf("test\n".encode("utf-8"))

test

说明:cdll.LoadLibrary和CDLL加载动态包效果一样,均可加载linux下的so和windows下的dll,但是windows下的dll后缀可省略,linux下的so后缀不可缺省,

python2可全量指定utf-8编码,python3用的是unicode,要在参数自行定义utf-8编码。

转载于:https://www.cnblogs.com/fushou/p/7275219.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值