Python ctypes and mutable strings calling Fortran DLL: Access Violation Error

2

I am trying call a subroutine in a Fortran DLL that requires 3 mutable strings passed to it. The subroutine is of the form:

Subroutine Getinfo(string_1, string_2, string_3, index)
char *60 string_1, string_2
char *30 string_3

string_1 = "String 1 return value"
string_2 = "String 2 return value"
string_3 = "String 3 return value"

end subroutine

Im calling the function in python as follows:

dll = ctypes.windll.LoadLibrary('library.dll')
funcprot = getattr(dll, 'Getinfo')
funcprot.argtypes = [ctypes.c_char_p, ctypes.c_long, ctypes.c_char_p, ctypes.c_long, 
     ctypes.c_char_p, ctypes.c_long, ctypes.c_long]

string_1 = ctypes.create_string_buffer(60)
string_2 = ctypes.create_string_buffer(60)
string_3 = ctypes.create_string_buffer(30)

funcprot(string_1, 60, string_2, 60, string_3, 30, 701)

I get the following error.

WindowsError: exception: access violation reading 0x000002BD

I tried suggestions from this post, but it didn't help.

What am I doing wrong? Thank you for your help.

python
fortran
ctypes
asked on Stack Overflow May 16, 2014 by d0m1n0 • edited May 23, 2017 by Community

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0