天天看點

python com接口_Pythoncom接口cas

我想附加到一個遠端程序,該程序使用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)

有什麼建議嗎?在