dllimport - How can I use a DLL from Python -
i trying load dll in python, want use econnect() function using ctypes
what know source code of dll:
- from *.cpp source code:
bool econnect( const char *host, uint port, int clientid=0);
- from dependency walker tool: function ordinal 6 , undecorated name is
?econnect@eclientsocket@@uae_npbdih@z
i tried access econnect 2 ways myfunction , myfunction2, wrong. here code:
from ctypes import * def main(): ip = c_char_p('127.0.0.1') port = c_uint(7496) client_id = c_int(0) myfunction = getattr(cdll.twssocketclient, "?econnect@eclientsocket@@uae_npbdih@z") myfunction2= cdll.twssocketclient[6] print myfunction print myfunction2 print myfunction(ip, port, client_id,ip) if __name__ == "__main__": main()
i below error:
"windowserror: exception: access violation reading 0x0000002d"
i badly need here (i not know c++). thanks!
to make things easier, more pythonic, might want ctypesgen:
http://code.google.com/p/ctypesgen/
it generate proper wrapper functions, data types , such you. if want know how use ctypes, might start tutorial:
http://docs.python.org/library/ctypes.html
anything more specific , i'll have read api dll you're attempting use.
Comments
Post a Comment