如何使用ctypes封装带有多个参数的C函数? [英] How do I wrap this C function, with multiple arguments, with ctypes?

查看:175
本文介绍了如何使用ctypes封装带有多个参数的C函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有函数原型:

extern "C" void __stdcall__declspec(dllexport) ReturnPulse(double*,double*,double*,double*,double*);

我需要编写一些python来访问DLL中的此函数. 我已经加载了DLL,但是 每个double *实际上都指向可变数量的double(数组),并且 我无法使其正常运行.

I need to write some python to access this function that is in a DLL. I have loaded the DLL, but each of the double* is actually pointing to a variable number of doubles (an array), and I'm having trouble getting it to function properly.

谢谢!

推荐答案

使用n双打来制作数组:

arr7 = ctypes.c_double * `n` 
x = arr7()

,然后将x传递到需要double*的函数.或者,如果您需要在初始化时初始化x:

and pass x to your function where it wants a double*. Or if you need to initialize x as you make it:

x = arr7(i*0.1 for i in xrange(7))

之类的.您可以遍历x,对其进行索引等等.

and the like. You can loop over x, index it, and so on.

这篇关于如何使用ctypes封装带有多个参数的C函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆