gpt4 book ai didi

来自 dll 问题的 Python Ctypes 函数调用

转载 作者:行者123 更新时间:2023-11-30 15:02:29 24 4
gpt4 key购买 nike

我需要使用python来计算dll函数。

功能是:

int cbGetConfigString(int InfoType, int BoardNum, int DevNum, int ConfigItem, char *ConfigVal, int* maxConfigLen)

参数

信息类型

The configuration information for each board is grouped into different categories. This argument specifies which category you want. Always set this argument to BOARDINFO.

板号

The number associated with the board when it was installed with InstaCal or created with cbCreateDaqDevice(). BoardNum may be 0 to 99.

DevNum

The purpose of the DevNum argument depends on the ConfigItem being passed. It can serve as a point at which to start the read, an index into the ConfigItem, or it can be ignored.

配置项

The type of information to read from the device. Set it to one of the constants listed in the "ConfigItem argument values" section below.

配置值

Pointer to a user-allocated buffer where the configuration string is copied.

ma​​xConfigLen

Pointer to the value holding the maximum number of bytes to be read from the device into ConfigVal.

请帮助我理解我的代码中有什么问题:

import ctypes

mccdaq=ctypes.WinDLL("C:\\Program Files (x86)\\Measurement Computing\\DAQ\\cbw32.dll")

Open=mccdaq.cbGetConfigString
Open.argtypes =[ctypes.c_int,ctypes.c_int,ctypes.c_int,ctypes.c_int,ctypes.POINTER(ctypes.c_char),ctypes.POINTER(ctypes.c_int)]

INTP=ctypes.POINTER(ctypes.c_int)
num=ctypes.c_int(8)
addr=ctypes.addressof(num)
ptr=ctypes.cast(addr,INTP)

mem=ctypes.c_char()

print Open(2,0,0,363,ctypes.byref(mem),ctypes.byref(num))
print mem
print num

输出:

0 - 没有错误

c_char('1') - 应为 125E737

c_long(7) - 看起来字符数正确..

最佳答案

好的,我发现了问题:)

import ctypes

mccdaq=ctypes.WinDLL("C:\\Program Files (x86)\\Measurement Computing\\DAQ\\cbw32.dll")

Open=mccdaq.cbGetConfigString
Open.argtypes =[ctypes.c_int,ctypes.c_int,ctypes.c_int,ctypes.c_int,ctypes.POINTER(ctypes.c_char*8),ctypes.POINTER(ctypes.c_int)]

num=ctypes.c_int(8)
mem=(ctypes.c_char*8)()

print Open(2,0,0,363,ctypes.byref(mem),ctypes.byref(num))
print mem.value
print num

现在的输出是:

0

125E737

c_long(7)

关于来自 dll 问题的 Python Ctypes 函数调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41041686/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com