关于这个问题我做了很多研究。。但是没有地方我也找不到。我试图通过调用c dll来调用双c结构。你知道吗
我的问题是,我用python声明“类结构”的方法正确吗?我没想到我就在路上。因为即使我想从dll调用的函数没有输出任何东西。你知道吗
VisualC++/C]
我试过写C语法代码
typedef sturct {
int nBoardNum;
struct{
char pBoardName[16];
int nBoardID;
}BOARDINDEX[8];
}AAPBOARDINFO, *PAAPBOARDINFO;
HANDLE AcapOpen(char* cpBoardName, int nBoardNo, int nCh)
[Python]
我这样修改了Python语法。你知道吗
import ctypes as c
class BOARDINDEX(c.Structure):
_field_ = [("nBoardName", c.c_char_p * 16),("nBoardID", c.c_int)]
class AAPBOARDINFO(c.Structure):
_field_ = [("nBoardNum", c.c_int), ("BOARDINDEX", BOARDINDEX * 8)]
AapLib2 = c.WinDLL("AapLib2.dll")
BoardName = ["ABC","FWD","HGW"]
BoardNo = 0
ch = 1
output = Open(BoardName, BoardNo, ch)
def Open(BoardName, BoardNo, ch)
func = AapLib2.AcapOpen
func.argtypes = [c.POINTER(BOARDINDEX),c.c_int, c.c_int]
func.restype = c.c_int
ref = BOARDINDEX()
res = func(c.byref(ref.nBoardName),BoardNo, ch)
return res
调用Open()函数时没有结果。。。你知道吗
请考虑我的要求和任何答复将是伟大的。。。你知道吗
你需要知道的一切,都可以在[Python 3.Docs]: ctypes - A foreign function library for Python中找到。你知道吗
代码有几个问题:
char pBoardName[16]
映射到ctypes.c_char * 16
(不c\u char p)wintypes.HANDLE
。这种不匹配会(而且很可能会)产生:这是您的代码的修改版本。不用说,我实际上没有测试它,因为我没有.dll: 你知道吗
告诉我这对你有什么好处。你知道吗
相关问题 更多 >
编程相关推荐