我正在尝试使用comtypes 1.1.0包来访问python 2.7.6.1中的COM对象,并且由于返回VARIANT类型,我有一个从COM对象方法获取正确数据的基本问题
>>> from comtypes.client import CreateObject
>>> fm1 = CreateObject("MCB.PCM")
>>> fm1.ReadVariable("dwt")
(<comtypes.automation.LP_tagVARIANT object at 0x06A541C0>,<comtypes.automation.LP_tagVARIANT object at 0x06A54210>, <comtypes.automation.LP_tagVARIANT object at 0x06A54260>, True)
如何在python中转换VARIANT(VARIANT指针)?
通过OLEViewer我有
[id(0x60020002)]
VARIANT ReadVariable(
[in] VARIANT bsVar,
[out, optional] VARIANT* vValue,
[out, optional] VARIANT* tValue,
[out, optional] VARIANT* bsRetMsg);
您是否有任何想法转换它并从COM方法更正日期?
我应该使用pywin32(win32com包)吗?
非常感谢。
彼得
答案 0 :(得分:0)
我不是蟒蛇专家,但也处理VARIANTS。这个&#34; PSEUDO&#34;代码片可能会帮助你
from ctypes import *
from comtypes import automation
if __name__ == '__main__':
...
bsVar = automation.VARIANT("dwt")
vValue = automation.VARIANT(0)
tValue = automation.VARIANT(0)
bsRetMsg = automation.VARIANT(0)
ReadVariable(bsVar, addressof(vValue), addressof(tValue), addressof(bsRetMsg))
...
<强> PS:强>
我想,继续学习Python的工作原理,但未经过测试,以下内容可能有效:
...
vValue,tValue,bsRetMsg = ReadVariable(automation.VARIANT("dwt"))
...