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?

Community
  • 1
  • 1
Monty123
  • 103
  • 1
  • 7
  • What is the size of `s`? – David Ranieri Feb 26 '15 at 10:25
  • Check the ctypes documentation on `create_string_buffer`: https://docs.python.org/2/library/ctypes.html. That's what you should be using for passing a mutable `**char`. – sebastian Feb 26 '15 at 13:14
  • As you can see in the post you linked the dll alloc the space for the string s: `* ppMem = malloc( * pSize );` – LPs Feb 26 '15 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). – Monty123 Feb 26 '15 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`. – Eryk Sun Feb 26 '15 at 16:06

0 Answers0