[英]Python-passing object as an argument of function
There is a function from a DLL (C language) link("parameters", &connection);
有一个来自DLL(C语言)
link("parameters", &connection);
的函数link("parameters", &connection);
which takes a string parameter and initializes a connection. 它采用字符串参数并初始化连接。
There is a function connect(connection)
, where the connection - the object, initialized with a call to link()
. 有一个函数
connect(connection)
,其中连接-对象,通过调用link()
初始化。
Question: how to pass Python connection object function Connect () as an argument? 问题:如何通过Python连接对象函数Connect()作为参数?
from ctypes import *
mydll = CDLL (link.dll)
# How define the connection object?
top = link ("localhost: 5412", connection)
top = connect (connection)
I believe that winapi handle is 32 bits long, but you might need to ensure that it be that the true length. 我相信winapi句柄是32位长,但是您可能需要确保它是真实的长度。 If you are not using connection in any other way, maybe you can do this:
如果您没有以其他任何方式使用连接 ,则可以执行以下操作:
connection_t = ctypes.c_uint32
link = mydll.link
link.argtypes=(ctypes.c_char_p, ctypes.POINTER(connection_t) )
connect = mydll.connect
connect.argtypes=(connection_t,)
...
connection = connection_t()
link ("localhost: 5412", ctypes.byref(connection))
...
Note that: 注意:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.