A c code snippet,the c file compiled to a dll file named libxxx.dll:<div><br></div><div>typedef void* HND;</div><div>typedef unsigned char UCHAR;</div><div>typedef short int SWORD;</div><div>.......</div><div>int Connect(</div>
<div> HND* hnd,</div><div> UCHAR* ipaddr,</div><div><div> SWORD port){</div><div>......</div><div>return 1;</div><div>}</div><div><br></div><div>then How to handle function Connect using python and ctypes. especially the parameter hnd?</div>
<div><br></div><div>My python code:</div><div><br></div><div>from ctypes import *</div><div>xxx = cdll.libxxx</div><div>xxx.Connect.restype=c_int</div><div>xxx.Connect.argstype=[c_wchar_p,c_wchar_p,c_int]</div><div><br></div>
<div>hnd=c_char_p()</div><div><br></div><div><div>buf=create_string_buffer("127.0.0.1\0")</div><div>ipaddr=cast(buf,POINTER(c_char))</div></div><div><br></div><div>xxx.Connect(byref(hnd),ipaddr,8000)</div><div>
<br>
</div><div>But I always result a error:</div><div>WindowsError: exception: access violation writing 0x00000000</div><div><br></div><div>How to fix this problem?</div><div><br></div><div>Thanks.</div><div><br></div>
</div>