python通过ctypes调用c\c++编写的dll\so库
使用的python版本为2.7.14,64bit
使用vs2015编译dllso库,编译设置为release版本x64
压缩包中包括python调dll库的源码和vs2015生成dll的源码及工程
如果自己使用的以上任意版本不同,请自行调整,尽量保持使用的位数一致
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
..A..H. 31744 2018-01-18 11:48 20.Ctypescdll estdll.vs estdllv14.suo
文件 20447232 2018-01-17 16:26 20.Ctypescdll estdllipchTESTDLL-b1e78c37TESTDLL-613df006.ipch
文件 20447232 2018-01-17 16:06 20.Ctypescdll estdllipchTESTDLL-b1e78c37TESTDLL-7fe5ef40.ipch
文件 20250624 2018-01-17 16:05 20.Ctypescdll estdllipchTESTDLL-b1e78c37TESTDLL-a86811e2.ipch
文件 20250624 2018-01-17 13:14 20.Ctypescdll estdllipchTESTDLL-b1e78c37TESTDLL-f8330228.ipch
文件 9216 2018-01-17 16:05 20.Ctypescdll estdllRelease estdll.dll
文件 687 2018-01-17 16:05 20.Ctypescdll estdllRelease estdll.exp
文件 141635 2018-01-17 16:05 20.Ctypescdll estdllRelease estdll.iobj
文件 1984 2018-01-17 16:05 20.Ctypescdll estdllRelease estdll.ipdb
文件 1704 2018-01-17 16:05 20.Ctypescdll estdllRelease estdll.lib
文件 856064 2018-01-17 16:05 20.Ctypescdll estdllRelease estdll.pdb
文件 389 2018-01-17 13:14 20.Ctypescdll estdll estdlldllmain.cpp
文件 1488 2018-01-17 13:14 20.Ctypescdll estdll estdllReadMe.txt
文件 47980 2018-01-17 16:05 20.Ctypescdll estdll estdllReleasedllmain.obj
文件 289566 2018-01-17 16:05 20.Ctypescdll estdll estdllReleasestdafx.obj
文件 500 2018-01-17 16:05 20.Ctypescdll estdll estdllRelease estdll.log
文件 5968 2018-01-17 16:05 20.Ctypescdll estdll estdllRelease estdll.obj
文件 7667712 2018-01-17 16:05 20.Ctypescdll estdll estdllRelease estdll.pch
文件 2524 2018-01-17 16:05 20.Ctypescdll estdll estdllRelease estdll.tlogCL.command.1.tlog
文件 25998 2018-01-17 16:05 20.Ctypescdll estdll estdllRelease estdll.tlogCL.read.1.tlog
文件 1364 2018-01-17 16:05 20.Ctypescdll estdll estdllRelease estdll.tlogCL.write.1.tlog
文件 1684 2018-01-17 16:05 20.Ctypescdll estdll estdllRelease estdll.tloglink.command.1.tlog
文件 4004 2018-01-17 16:05 20.Ctypescdll estdll estdllRelease estdll.tloglink.read.1.tlog
文件 932 2018-01-17 16:05 20.Ctypescdll estdll estdllRelease estdll.tloglink.write.1.tlog
文件 210 2018-01-17 16:05 20.Ctypescdll estdll estdllRelease estdll.tlog estdll.lastbuildstate
文件 390 2018-01-17 16:05 20.Ctypescdll estdll estdllRelease estdll.tlog estdll.write.1u.tlog
文件 495616 2018-01-17 16:05 20.Ctypescdll estdll estdllReleasevc140.pdb
文件 211 2018-01-17 13:14 20.Ctypescdll estdll estdllstdafx.cpp
文件 315 2018-01-17 13:14 20.Ctypescdll estdll estdllstdafx.h
文件 240 2018-01-17 13:14 20.Ctypescdll estdll estdll argetver.h
............此处省略74个文件信息
#coding=utf-8
import os
import sys
from ctypes import *
def CallC():
dll = CDLL(r“cdll estdllx64Release estdll.dll“)
res = dll.fntestdll()
print res
#int add(int a int b)
res = dll.add(10 59)
print res
#double mulf(float a float b)
dll.mulf.restype = c_double
dll.mulf.argtypes = (c_float c_float)
res = dll.mulf(123.45 678.9)
print res
#double cmulf(float a char b)
dll.cmulf.restype = c_double
dll.cmulf.argtypes = (c_float c_byte)
res = dll.cmulf(123.45 100)
print res
#int stringcat(char *a char *b)
dll.stringcat.restype = c_int
dll.stringcat.argtypes = (c_char_p c_char_p)
a = c_char_p(“acd“)
b = c_char_p(“abd“)
res = dll.stringcat(a b)
if res > 0:
print “a > b“
elif res < 0:
print “a < b“
else:
print “a = b“
#void rs(int *a int *b)
dll.rs.restype = None
dll.rs.argtypes = (POINTER(c_int) POINTER(c_int))
a = c_int(12)
b = c_int(12)
dll.rs(byref(a) b)
print a.value
if __name__ == ‘__main__‘:
CallC()
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
..A..H. 31744 2018-01-18 11:48 20.Ctypescdll estdll.vs estdllv14.suo
文件 20447232 2018-01-17 16:26 20.Ctypescdll estdllipchTESTDLL-b1e78c37TESTDLL-613df006.ipch
文件 20447232 2018-01-17 16:06 20.Ctypescdll estdllipchTESTDLL-b1e78c37TESTDLL-7fe5ef40.ipch
文件 20250624 2018-01-17 16:05 20.Ctypescdll estdllipchTESTDLL-b1e78c37TESTDLL-a86811e2.ipch
文件 20250624 2018-01-17 13:14 20.Ctypescdll estdllipchTESTDLL-b1e78c37TESTDLL-f8330228.ipch
文件 9216 2018-01-17 16:05 20.Ctypescdll estdllRelease estdll.dll
文件 687 2018-01-17 16:05 20.Ctypescdll estdllRelease estdll.exp
文件 141635 2018-01-17 16:05 20.Ctypescdll estdllRelease estdll.iobj
文件 1984 2018-01-17 16:05 20.Ctypescdll estdllRelease estdll.ipdb
文件 1704 2018-01-17 16:05 20.Ctypescdll estdllRelease estdll.lib
文件 856064 2018-01-17 16:05 20.Ctypescdll estdllRelease estdll.pdb
文件 389 2018-01-17 13:14 20.Ctypescdll estdll estdlldllmain.cpp
文件 1488 2018-01-17 13:14 20.Ctypescdll estdll estdllReadMe.txt
文件 47980 2018-01-17 16:05 20.Ctypescdll estdll estdllReleasedllmain.obj
文件 289566 2018-01-17 16:05 20.Ctypescdll estdll estdllReleasestdafx.obj
文件 500 2018-01-17 16:05 20.Ctypescdll estdll estdllRelease estdll.log
文件 5968 2018-01-17 16:05 20.Ctypescdll estdll estdllRelease estdll.obj
文件 7667712 2018-01-17 16:05 20.Ctypescdll estdll estdllRelease estdll.pch
文件 2524 2018-01-17 16:05 20.Ctypescdll estdll estdllRelease estdll.tlogCL.command.1.tlog
文件 25998 2018-01-17 16:05 20.Ctypescdll estdll estdllRelease estdll.tlogCL.read.1.tlog
文件 1364 2018-01-17 16:05 20.Ctypescdll estdll estdllRelease estdll.tlogCL.write.1.tlog
文件 1684 2018-01-17 16:05 20.Ctypescdll estdll estdllRelease estdll.tlogli
文件 4004 2018-01-17 16:05 20.Ctypescdll estdll estdllRelease estdll.tlogli
文件 932 2018-01-17 16:05 20.Ctypescdll estdll estdllRelease estdll.tlogli
文件 210 2018-01-17 16:05 20.Ctypescdll estdll estdllRelease estdll.tlog estdll.lastbuildstate
文件 390 2018-01-17 16:05 20.Ctypescdll estdll estdllRelease estdll.tlog estdll.write.1u.tlog
文件 495616 2018-01-17 16:05 20.Ctypescdll estdll estdllReleasevc140.pdb
文件 211 2018-01-17 13:14 20.Ctypescdll estdll estdllstdafx.cpp
文件 315 2018-01-17 13:14 20.Ctypescdll estdll estdllstdafx.h
文件 240 2018-01-17 13:14 20.Ctypescdll estdll estdll argetver.h
............此处省略74个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)