ctypes.ArgumentError ao chamar funções DLL com Python
Estou usando ctypes para chamar funções em um arquivo DLL de acordo com um arquivo de descrição que descreve os parâmetros e retornos das funções DLL. Aqui está uma função nesta DLL chamada InitNetwork. Abaixo está sua descrição:
Function:BOOL InitNetwork(char LocalIP[],char ServerIP[],int LocalDeviceID);
Arguments:LocalIP
ServerIP
LocalDeviceID
Return:Success:TRUE;
Faile:FALSE;
O que estou fazendo no Python é assim:
from ctypes import *
import os
#Load Dll:
cppdll = CDLL("C:\\VS_projects\\MusicServer_Flask\\NetServerInterface.dll")
#Get the function:
initnetwork = getattr(cppdll, "?InitNetwork@@YAHQAD0H@Z") # The function can be successfully accessed.
#specify arguments' types:
initnetwork.argtypes = [c_char_p,c_char_p,c_int]
Depois disso, tento:
initnetwork("192.168.1.103", "192.168.1.103", 1111)
Obter um erro:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type
Se eu tentar isso:
initnetwork(LocalIP = "192.168.1.103", ServerIP = "192.168.1.103", LocalDeviceID = 1111)
Eu vou receber:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: this function takes at least 3 arguments (0 given)
Por que esses erros aparecem? Como posso chamar esta função com sucesso? Qualquer sugestão é apreciada. Obrigado pela sua atenção!