我正在使用 UPnP 对象方法IUPnPDeviceFinder
::[CreateAsyncFind][1]
并且第三个参数是回调函数。
我试图创建自己的 COM 对象,但该方法不会回调我的函数。这是我的代码:
class Callback():
_public_methods_ = ['DeviceAdded','DeviceRemoved', 'SearchComplete']
_reg_progid_ = "UPnP.PythonCallback"
_reg_clsid_ = pythoncom.CreateGuid()
def DeviceAdded (device, UDN, calltype):
print (device, ": ", calltype, " UDN: ", UDN)
return
win32com.server.register.UseCommandLine(Callback)
callserver = Dispatch("UPnP.PythonCallback")
deviceType = "urn:schemas-upnp-org:device:MediaServer:1"
devices = finder.CreateAsyncFind(deviceType,0, callserver)
finder.StartAsyncFind(devices)
实际上,我只需要这样的东西:
def DeviceAdded (device, UDN, calltype):
print (device, ": ", calltype, " UDN: ", UDN)
return
deviceType = "urn:schemas-upnp-org:device:MediaServer:1"
devices = finder.CreateAsyncFind(deviceType,0, DeviceAdded)
finder.StartAsyncFind(devices)
微软在 VBScript 上做了一个例子。这正是我想在 Python 上做的事情(http://msdn.microsoft.com/en-us/library/windows/desktop/aa381078(v=VS.85).aspx)如何将函数作为参数传递在 COM 对象上?