在Python脚本中,我必须用win32com和pythoncom替换comtype的用法。实际上,我有这样的代码:
from comtypes.client import CreateObject, GetEvents
object_IXXObjManager = comtypes.client.CreateObject(xxxId)
connection_IXXObjManager = GetEvents(object_IXXObjManager, IXXObjManagerEventHandler())
object_IXXObjCommunications = object_IXXObjManager.QueryInterface(comtypes.gen.XXOBJLib.IXXObjCommunications)
connection_IXXObjCommunications = GetEvents(object_IXXObjCommunications, IXXObjCommunicationEventHandler(), interface=comtypes.gen.XXOBJLib.IXXObjCommunicationsEvents)目标是使用win32com获得类似的功能。据我理解,事件处理程序类不需要任何更改。第一部分很简单:
import win32com.client
object_IXXObjManager = win32com.client.Dispatch(xxxId)
event_IXXObjManager = win32com.client.WithEvents(object_IXXObjManager, IXXObjManagerEventHandler) 但是,当试图从查询接口将事件处理程序映射到对象时,我陷入了困境。
object_IXXObjManager._oleobj_.QueryInterface( ??? )你能帮我一下吗?我有一般的sw开发经验,但有限的COM知识。
发布于 2015-11-03 12:11:11
替代者
object_IXXObjCommunications = object_IXXObjManager.QueryInterface(comtypes.gen.XXOBJLib.IXXObjCommunications)可能是这样的:
iface = object_XXObjManager._oleobj_.QueryInterface(pythoncom.IID_IDispatch)
iface_Communications = win32com.client.CastTo(iface,"XXObjCommunications")
connection_XXObjCommunications = win32com.client.Dispatch(iface_Communications)https://stackoverflow.com/questions/33392063
复制相似问题