我正在寻找有关调用函数的问题的2天解决方案:
int HG_GetProgList (sHG_ProgSlot** list)
从DLL与python。 sHG_ProgSlot在这里是一个结构:
typedef struct //---- data set of a 'program slot' in the RDS-coder
{
char strname [9];
int slot;
int bytes;
int groups;
int times;
int next_slot;
} sHG_ProgSlot;
dll中函数的描述如下:
RDSHG81300B_API int __stdcall HG_GetProgList (sHG_ProgSlot** list);
// DLL包含一个sHG_ProgSlot数组,其中包含所有占用的“程序槽”。
//条目按其插槽编号按升序排序。
//此函数将指向此数组的指针复制到函数参数。
//(使用HG_GetNumberOfProgs()获取数组的长度。)
//输入:list - 要设置的指针
//输出:0 =无错误
我写下了以下代码:
class RDSCoderService(object):
def GetProgramList(self, programList):
getProgListFunction = self.RDS_Lib['HG_GetProgList]
getProgListFunction.argtypes = [ctypes.POINTER(ctypes.POINTER(sHG_ProgSlot*60))]
getProgListFunction.restype = ctypes.c_int
return getProgListFunction(programList)
class sHG_ProgSlot(ctypes.Structure):
_fields_ = [("strname", ctypes.c_char*9),
("slot", ctypes.c_int),
("bytes", ctypes.c_int),
("groups", ctypes.c_int),
("times", ctypes.c_int),
("next_slot", ctypes.c_int)]
调用函数:
rds=RDSCoderService()
struct_p=ctypes.POINTER(sHG_ProgSlot) #pointer to a structure type
arr_of_struct_pointer=struct_p*60 #array of pointers to a struct type of size 60
instance_array=arr_of_struct_pointer() # instance array
p_inst_array=ctypes.pointer(instance_array)# pointer to array
Message=rds.GetProgramList(p_inst_array) #calling of function
谢谢你的帮助!