I am trying to call functions from a DLL which seems to be created in Delphi. An example of a some functions supported by the DLL are:
function oziDeleteWpByName(var name:pansichar):integer;stdcall
The Python code I have written to access the above functions is not working.
from ctypes import *
libc = cdll.OziAPI
name ='test'
pi = pointer(name)
delname = libc.oziDeleteWpByName
delname(name)
It seems I am passing the wrong data type to the function. Any ideas on how to do it right?
Thanks it worked. Now please help with this function:
function oziGetOziVersion(var Version:pansichar;var DataLength:integer):integer;stdcall; The version of OziExplorer is returned in the Version variable.
Now how do I pass 'var version' when it the one which will also be returned.
from ctypes import *
# Not strictly needed but it's good to be explicit.
windll.OziAPI.oziDeleteWpByName.argtypes = [POINTER(c_char_p)]
windll.OziAPI.oziDeleteWpByName.restype = c_int
p = c_char_p('test')
retval = windll.OziAPI.oziDeleteWpByName(byref(p))
In Delphi, a var
parameter is passed by reference. So what you have there is a pointer to a PAnsiChar
(aka C-style string pointer). If you're passing it a string pointer, instead of a pointer to a string pointer, it won't work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With