2

我尝试将 win32com.client.DispatchWithEvents 用于 TAPI COM 对象

import win32com.client
class TapiEvents:
    pass

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

但它给出了一个错误:这个 COM 对象不支持事件。

4

1 回答 1

2

一个工作示例看起来像(使用 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()

用于拨打电话

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)
于 2013-10-17T12:27:37.477 回答