Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PYthon ctypes';类型错误';LP_LP_c_long实例而不是_ctypes.PyCPointerType 我尝试使用一个用C++编写的DLL。它具有以下功能: bool PMDllWrapperClass::GetDeviceList(DEVICE** pDeviceArray, int* nDeviceCount, LAN_DEVICE** pLanDeviceArray, int LanDeviceCount, int InterfaceTypeToSearch)_Python_Dll_Arguments_Ctypes - Fatal编程技术网

PYthon ctypes';类型错误';LP_LP_c_long实例而不是_ctypes.PyCPointerType 我尝试使用一个用C++编写的DLL。它具有以下功能: bool PMDllWrapperClass::GetDeviceList(DEVICE** pDeviceArray, int* nDeviceCount, LAN_DEVICE** pLanDeviceArray, int LanDeviceCount, int InterfaceTypeToSearch)

PYthon ctypes';类型错误';LP_LP_c_long实例而不是_ctypes.PyCPointerType 我尝试使用一个用C++编写的DLL。它具有以下功能: bool PMDllWrapperClass::GetDeviceList(DEVICE** pDeviceArray, int* nDeviceCount, LAN_DEVICE** pLanDeviceArray, int LanDeviceCount, int InterfaceTypeToSearch),python,dll,arguments,ctypes,Python,Dll,Arguments,Ctypes,我试过: cP = ctypes.POINTER(ctypes.POINTER(ctypes.c_int64)) cIP = ctypes.POINTER(ctypes.c_int32) cLP = ctypes.POINTER(ctypes.c_int32) cDC = ctypes.c_int32() cIS = ctypes.c_int32() resultgetdev = PMDll.GetDeviceList(cP, cIP, cLP, cDC, cIS) 但它说: ctypes

我试过:

cP = ctypes.POINTER(ctypes.POINTER(ctypes.c_int64))
cIP = ctypes.POINTER(ctypes.c_int32)
cLP = ctypes.POINTER(ctypes.c_int32)
cDC = ctypes.c_int32()
cIS = ctypes.c_int32()


resultgetdev = PMDll.GetDeviceList(cP, cIP, cLP, cDC, cIS)
但它说:

ctypes.ArgumentError: argument 1: <class 'TypeError'>: expected LP_LP_c_long instance instead of _ctypes.PyCPointerType
ctypes.ArgumentError:参数1::应为LP_LP_c_long实例,而不是_ctypes.PyCPointerType

我还尝试使用双指针,但没有成功。我可以用ctypes解决它吗?还是不可能?

错误消息是由于传递类型而不是实例。您应该声明参数类型和返回类型,以便ctypes可以仔细检查传递的值是否正确

这需要更多信息才能准确,但您至少需要:

test.cpp

\ifdef\u WIN32
#定义API_uudeclspec(dllexport)
#否则
#定义API
#恩迪夫
结构设备;
结构局域网设备;
外部“C”\u declspec(dllexport)
bool GetDeviceList(设备**pDeviceArray,int*nDeviceCount,局域网设备**pLanDeviceArray,int LanDeviceCount,int InterfaceTypeToSearch){
返回true;
}
test.py:

从ctypes导入*
类设备(结构):
_字段=()成员??
LAN_类设备(结构):
_字段=()成员??
dll=CDLL('./测试')
dll.GetDeviceList.argtypes=指针(指针(设备)),指针(c_int),指针(指针(LAN_设备)),c_int,c_int
dll.GetDeviceList.restype=c_bool
device_list=指针(device)(#创建实例以通过引用传递输出(?)参数
landev_列表=指针(LAN_设备)()
dev_count=c_int()
lan#u计数=5#??
搜索类型=1#??
结果=dll.GetDeviceList(byref(设备列表)、byref(开发计数)、byref(landev列表)、lan计数、搜索类型)

设备和局域网设备的定义是什么?您还需要传递类型而不是类型的实例,并且应该声明
.argtypes
.restype
ctypes
也只理解C接口,因此
GetDeviceList
函数必须是
extern“C”