[Help] python ctypes to process C pointer!

Korobase boyee118 at gmail.com
Sun Oct 30 10:49:16 EDT 2011


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.10円")
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111030/faf55c67/attachment.html>


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /