I'm using ctypes to call functions in a DLL file according to a description file that describe the DLL functions' parameters and returns. Here is one function in this DLL called InitNetwork. Below is its description:
Function:BOOL InitNetwork(char LocalIP[],char ServerIP[],int LocalDeviceID);
Arguments:LocalIP
ServerIP
LocalDeviceID
Return:Success:TRUE;
Faile:FALSE;
What I'm doing in Python is like this:
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]
After this, I try:
initnetwork("192.168.1.103", "192.168.1.103", 1111)
Get an Error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type
If I try this:
initnetwork(LocalIP = "192.168.1.103", ServerIP = "192.168.1.103", LocalDeviceID = 1111)
I will get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: this function takes at least 3 arguments (0 given)
Why these errors comes out? How can I call this function successfully? Any suggestion is appreciated. Thank you for your attention!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…