【发布时间】:2011-11-07 13:10:51
【问题描述】:
我有一个调用 DLL 的工作 python 2.7 程序。我正在尝试将脚本移植到 python 3.2。 DLL 调用似乎有效(即调用时没有错误),但返回的数据没有意义。
以防万一它有用: - 调用需要三个参数:两个 int(输入)和一个指向 ushort 数组的指针(输出)。
我尝试同时使用 python 和 numpy 数组都没有成功。
谁能列举 Python 2.7 和 3.2 在 ctypes 方面的区别?
提前致谢
编辑
这是一些示例代码。 DLL 是专有的,所以我没有代码。但我确实有 C 标头:
void example (int width, int height, unsigned short* pointer)
python代码是:
width, height = 40, 100
imagearray = np.zeros((width,height), dtype=np.dtype(np.ushort))
image = np.ascontiguousarray(imagearray)
ptrimage = image.ctypes.data_as(ct.POINTER(ct.c_ushort))
DLL.example(width, height, ptrimage)
这在 python 2.7 中有效,但在 3.2 中无效。
编辑 2
如果ctypes中的变化只是Cedric指出的那些,那么python 3.2不能工作是没有意义的。所以再次查看代码,我发现在我提到的函数之前调用了一个准备函数。签名是:
void prepare(char *table)
在 python 中,我通过以下方式调用:
table = str(aNumber)
DLL.prepare(table)
有没有可能是因为 Python 字符串处理的改变造成的?
【问题讨论】:
-
我完全不知道有什么不同。我想我们需要看看一些代码。
标签: python dll numpy python-3.x ctypes