1. Python只能调用C函数接口,所有想被调用的C++函数需要用extern "C"定义。
2. 示例
import os
import os.path
import shutil
import stat
import sys
from 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')