Pythoncom接口cas

2024-09-29 20:27:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我想附加到一个远程进程,该进程使用pythoncom和Microsoft开发环境提供的COM对象运行Visual Studio实例。 到目前为止,我能够从DTE object获取实现Debugger接口的调试器对象。但是,我需要访问调试器的Transports属性。它由Debugger2类实现。所以我需要Debugger2实例而不是Debugger。在VB或C++中,这可以通过简单的CAST(^ {A4})来完成。 但是在Python中如何做到这一点呢?在

查询接口

方法异常结束

IID_DTE2 = IID("{2EE1E9FA-0AFE-4348-A89F-ED9CB45C99CF}")

def get_vs_instances():
    rot = pythoncom.GetRunningObjectTable()
    running_objects = rot.EnumRunning()

    while True:
        moniker = running_objects.Next()

        if not moniker:
            break

        ctx = pythoncom.CreateBindCtx(0)
        name = moniker[0].GetDisplayName(ctx, None)

        if name.startswith("!VisualStudio.DTE."):
            obj = rot.GetObject(moniker[0])
            dte = win32com.client.Dispatch(
                obj.QueryInterface(pythoncom.IID_IDispatch))
            dte2 = dte._oleobj_.QueryInterface(IID_DTE2)

TypeError: There is no interface object registered that supports this IID

调用

(我从Python对象浏览器获取Transports属性的DISPID 1101。)

^{pr2}$

pywintypes.com_error: (-2147352573, 'Member not found.', None, None)

CastTo也没有帮助,因为错误接口没有帮助 显示在与对象相同的库中。(similar problem)

有什么建议吗?在


Tags: 对象实例none属性object进程debugger调试器

热门问题