P
Podi
Hi,
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
mydll.dll_foo(POINTER(data), byref(size))
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python24\Lib\site-packages\ctypes\__init__.py", line 197, in
POINTER
return _pointer_type_cache[cls]
TypeError: unhashable type
out = c_char_p(data.raw)
mydll.dll_foo(byref(out), byref(size))
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
ValueError: Procedure probably called with too many arguments (8 bytes
in excess)
mydll..dll_foo(out, byref(size))
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
WindowsError: exception: access violation writing 0x6C6C6568
temp = create_string_buffer('\000' * 32)
mydll.dll_foo(temp, byref(size))
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
WindowsError: exception: access violation writing 0x00000000
mydll.dll_foo(byref(temp), byref(size))
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
WindowsError: exception: access violation writing 0x00000000
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
mydll.dll_foo(POINTER(data), byref(size))
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python24\Lib\site-packages\ctypes\__init__.py", line 197, in
POINTER
return _pointer_type_cache[cls]
TypeError: unhashable type
out = c_char_p(data.raw)
mydll.dll_foo(byref(out), byref(size))
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
ValueError: Procedure probably called with too many arguments (8 bytes
in excess)
mydll..dll_foo(out, byref(size))
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
WindowsError: exception: access violation writing 0x6C6C6568
temp = create_string_buffer('\000' * 32)
mydll.dll_foo(temp, byref(size))
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
WindowsError: exception: access violation writing 0x00000000
mydll.dll_foo(byref(temp), byref(size))
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
WindowsError: exception: access violation writing 0x00000000