I'm trying to call a function from dll in python 3.4 with the following signature (more: http://www.lawlabs.ru/parser_address.htm):
function GetAddressFields(
AddressStr: String;
var FullStr: String;
var QualifiedStr: String;
Separator: ShortString = #13#10;
IsRussia: Boolean = True;
WithDescription: Boolean = True;
WithExceptions: Boolean = True;
LastIsHome: Boolean = True;
Subject: Boolean = True;
WithUnrecognized: Boolean = True): String;
I think syntax is Delphi and get an error when using ctypes for this signature.
My expected match for delphi and ctypes types:
String -> c_char_p
ShortString -> c_char_p
var String -> POINTER(c_char_p)
boolean -> c_bool
Therefore the function signature in Python (where dll = windll.LoadLibrary(...)):
dll.GetAddressFields.argtypes = (
c_char_p,
POINTER (c_char_p),
POINTER (c_char_p),
c_char_p,
c_bool,
c_bool,
c_bool,
c_bool,
c_bool,
c_bool)
dll.GetAddressFields.restype = c_char_p
However, an error occurs with this signature.
Attempt to pass parameters:
param_1 = c_char_p("".encode("ascii"))
param_2 = c_char_p("".encode("ascii"))
result = dll.GetAddressFields(
c_char_p('test'.encode("ascii")),
byref(param_1),
byref(param_2),
c_char_p("\r\n".encode("ascii")),
True,
True,
True,
True,
True,
True)
The complete error code is:
OSError: exception: access violation reading 0x00000001
Interestingly, when replacing the first boolean parameter with False, we have
OSError error: exception: access violation reading 0x00000000
When you try to pass boolean parameters by reference, an error occurs with random addresses
How solve this problem?