Проблемы вызова переменной с помощью модуля ctypes
Подключил dll программа корректно ее читает,
datserdll = ctypes.CDLL("C:\I_NP_10\Serv1.dll")
datserdll.func_ret_int.restype = ctypes.c_int
datserdll.func_ret_int.argtypes = [ctypes.c_int, ]
LF = ctypes.c_int.in_dll(datserdll, "LF")
print('ret LF: ', LF.value)
но при попытке выдает ошибку
File "C:\I_NP_10\app_24_project\DLLread.py", line 5, in <module>
datserdll.func_ret_int.restype = ctypes.c_int
File "C:\Python32\lib\ctypes\__init__.py", line 387, in __getattr__
func = self.__getitem__(name)
File "C:\Python32\lib\ctypes\__init__.py", line 392, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'func_ret_int' not found
Process finished with exit code 1
Прошу подскажите в чем проблема.
Ответы (1 шт):
Автор решения: Sergey Tatarincev
→ Ссылка
А зачем вообще указывать restype учитывая что
By default functions are assumed to return the C int type
Ну и далее
return types can be specified by setting the restype attribute of the function object.
Т.е.
datserdll = ctypes.CDLL("C:\I_NP_10\Serv1.dll")
my_func = datserdll.func_ret_int
my_func.restype = ctypes.c_int