Python TAPI COM object with events

元气小坏坏 提交于 2020-08-09 09:39:21

问题


I try use win32com.client.DispatchWithEvents for TAPI COM object

import win32com.client
class TapiEvents:
    pass

tapi = win32com.client.DispatchWithEvents("{21D6D48E-A88B-11D0-83DD-00AA003CCABD}",TapiEvents)

But it gives an error: This COM object does not support events.


回答1:


A working example looks like (working with CiscoTSP)

import win32com.client
cls="TAPI.TAPI.1"
# need for gen_py
ti = win32com.client.Dispatch(cls)._oleobj_.GetTypeInfo()
tlb, index = ti.GetContainingTypeLib()
tla = tlb.GetLibAttr()
win32com.client.gencache.EnsureModule(tla[0], tla[1], tla[3], tla[4], bValidateFile=0)

class TapiEvents(win32com.client.getevents(cls)):
    def OnEvent(self, ev1,ev2): 
        print "OnEvent"

tapi=win32com.client.Dispatch(cls)
tapi.Initialize() # must run after Dispatch and before TapiEvents
events=TapiEvents(tapi)
tapi.EventFilter = 0x1FFFF

for addr in tapi.Addresses: 
    try:
        tapi.RegisterCallNotifications(addr,True,True,8,0)
    except:
        pass

import Tix
r=Tix.Tk()
r.mainloop()

For making call use

import win32com.client,time
tapi = win32com.client.Dispatch("TAPI.TAPI.1")
tapi.Initialize()
for item in tapi.Addresses: print item.AddressName
objCrtAddress = [item for item in tapi.Addresses if 'SEP' in item.AddressName][0]
sNumber='323'
gobjCall = objCrtAddress.CreateCall(sNumber, 1, 0x8)
gobjCall.Connect (False)


来源:https://stackoverflow.com/questions/19426759/python-tapi-com-object-with-events

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!