ctypes pointer to pointer

Gabriel Genellina gagsl-py at yahoo.com.ar
Thu Sep 28 02:43:20 EDT 2006


At Wednesday 27/9/2006 22:58, Podi wrote:

>I have a C function in the dll does the following:
>
>DLL_API int dll_foo(char **data, size_t *size)
>{
>     strcpy(*data, "hello");
>     *size = strlen(*data);
>
>     return 0;
>}
>
>
>So I would call the function as such,
>
>char data[8];
>size_t size;
>
>int status = dll_foo(&data, &size);
>
>I have tried the following in Python but not able to get it working...
>Any help would be appreciated!
>
>from ctypes import *
>mydll = windll.mydll
>array = c_char * 8
>data = array()
>size = c_long()
>status = mydll.dll_foo(byref(data), byref(size))
>Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
>WindowsError: exception: access violation writing 0x00000000

I'd use your last try. But since it didnt work, use a prototype and 
see what happens:

data = create_string_buffer('\000' * 8)
size = c_long()
dll_foo = mydll.dll_foo
dll_foo.argtypes = [POINTER(c_char_p), POINTER(c_long)]
status = dll_foo(byref(data), byref(size))

Are you sure your function is compiled using the stdcall calling 
convention? I'm not sure what means DLL_API.



Gabriel Genellina
Softlab SRL 


	
	
		
__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas




More information about the Python-list mailing list