A c code snippet,the c file compiled to a dll file named libxxx.dll:

typedef void* HND;
typedef unsigned char UCHAR;
typedef short int  SWORD;
.......
int Connect(
       HND* hnd,
       UCHAR* ipaddr,
       SWORD port){
......
return 1;
}

then How to handle function Connect using python and ctypes. especially the
parameter hnd?

My python code:

from ctypes import *
xxx = cdll.libxxx
xxx.Connect.restype=c_int
xxx.Connect.argstype=[c_wchar_p,c_wchar_p,c_int]

hnd=c_char_p()

buf=create_string_buffer("127.0.0.1\0")
ipaddr=cast(buf,POINTER(c_char))

xxx.Connect(byref(hnd),ipaddr,8000)

But I always result a error:
WindowsError: exception: access violation writing 0x00000000

How to fix this problem?

Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to