1

I have a DLL with a function of the following form:

void Foo ( int * i, char ** s )
{
   if ( *i > (int)(strlen(date_string) + strlen(time_string) + 2) )
       sprintf ( *s, "%s %s", time_string, date_string );
}

where

char date_string[] = { __DATE__ };
char time_string[] = { __TIME__ };

But adapting the method used here:

Python and ctypes: how to correctly pass "pointer-to-pointer" into DLL?

by using:

i = c_int(22)
s = POINTER(c_byte)()
Foo(byref(i),byref(s))

just results in the interpreter not producing any output. Does anyone know what I'm doing wrong?

5
  • What is the size of s? Commented Feb 26, 2015 at 10:25
  • Check the ctypes documentation on create_string_buffer: docs.python.org/2/library/ctypes.html. That's what you should be using for passing a mutable **char. Commented Feb 26, 2015 at 13:14
  • As you can see in the post you linked the dll alloc the space for the string s: * ppMem = malloc( * pSize ); Commented Feb 26, 2015 at 13:33
  • @sebastian How do I go about passing s=create_string_buffer(22)? Using a variety of combinations of byref and pointer either results in an write access violation, or a warning that I've passed too many arguments (8 bytes excess). Commented Feb 26, 2015 at 13:45
  • Pass a reference to a pointer to the first element of array s, i.e. byref(POINTER(c_char)(s)). This uses POINTER(c_char)(s) to match a declaration of Foo.argtypes = (POINTER(c_int), POINTER(POINTER(c_char))). Given the latter, using pointer(s) instead would raise an exception because it creates a pointer to a c_char array instead of to a single c_char. Commented Feb 26, 2015 at 16:06

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.