Python调用C++

来源:互联网 发布:方维源码下载 编辑:程序博客网 时间:2024/06/11 22:45

1. Python只能调用C函数接口,所有想被调用的C++函数需要用extern "C"定义。

2. 示例

import osimport os.pathimport shutilimport statimport sysfrom ctypes import *def main():    dllLoder = cdll.LoadLibrary      dll = dllLoder("hellodll.dll")      fun = dll.funPython      fun.restype = c_double # 这里可以设置返回类型,默认的返回类型是int      retVal = fun(c_double(1.0), c_double(2))     print(retVal)if __name__ == '__main__':try :main()except Exception as e:print(e)os.system('pause')