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.

8
  • See my comment on your other question. Try it as funcprot(string_1, string_2, string_3, 2, 60, 60, 30), i.e. append the lengths. Commented May 16, 2014 at 21:54
  • @eryksun Thanks for the suggestion. I will try it out as an alternative. I think I figured out the reason for the error. It was because I passed the last parameter index by value and not as reference. Changing funcprot(string_1, 60, string_2, 60, string_3, 30, 2) to funcprot(string_1, 60, string_2, 60, string_3, 30, ctypes.byref(2)) fixed the issue. I keep forgetting that in Fortran, most everything is a pointer! Commented May 18, 2014 at 16:18
  • Right, but I don't see why it would access 0x2BD (701) in this case. Anyway, if possible you should export a platform C ABI. Otherwise these ABI issues will drive you bonkers. Commented May 18, 2014 at 18:26
  • Possibly because the index value that I was trying to pass was 701. And it got interpreted as the address. Commented May 18, 2014 at 18:41
  • Can you elaborate on what you mean by "export a platform C ABI? " Commented May 18, 2014 at 18:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.