def Test(): import win32com.server.util, win32com.server.policy # import win32dbg;win32dbg.brk() ob = win32com.server.util.wrap( VeryPermissive(), usePolicy=win32com.server.policy.DynamicPolicy) try: handle = pythoncom.RegisterActiveObject(ob, iid, 0) except pythoncom.com_error as details: print("Warning - could not register the object in the ROT:", details) handle = None try: import win32com.client.dynamic client = win32com.client.dynamic.Dispatch(iid) client.ANewAttr = "Hello" if client.ANewAttr != "Hello": raise error("Could not set dynamic property") v = ["Hello", "From", "Python", 1.4] client.TestSequence = v if v != list(client.TestSequence): raise error("Dynamic sequences not working! %r/%r" % (repr(v), repr(client.testSequence))) client.write("This", "output", "has", "come", "via", "testDynamic.py") # Check our new "_FlagAsMethod" works (kinda!) client._FlagAsMethod("NotReallyAMethod") if not callable(client.NotReallyAMethod): raise error("Method I flagged as callable isn't!") client = None finally: if handle is not None: pythoncom.RevokeActiveObject(handle) print("Test worked!")
def Test(): import win32com.server.util, win32com.server.policy # import win32dbg;win32dbg.brk() ob = win32com.server.util.wrap(VeryPermissive(),usePolicy=win32com.server.policy.DynamicPolicy) try: handle = pythoncom.RegisterActiveObject(ob, iid, 0) except pythoncom.com_error, details: print "Warning - could not register the object in the ROT:", details handle = None
def registerThisCOMObj(self): self.serverWrapper = win32com.server.util.wrap( self, usePolicy=win32com.server.policy.DynamicPolicy) try: handle = pythoncom.RegisterActiveObject(self.serverWrapper, self.IID, 0) except pythoncom.com_error, details: print "Warning - could not register the object in the ROT:", details handle = None return
return ret except KeyError: # Probably a method request. raise Exception(scode=winerror.DISP_E_MEMBERNOTFOUND) if wFlags & (pythoncom.DISPATCH_PROPERTYPUT | pythoncom.DISPATCH_PROPERTYPUTREF): setattr(self, name, args[0]) return raise Exception(scode=winerror.E_INVALIDARG, desc="invalid wFlags") def write(self, x): print x return 0 import win32com.server.util, win32com.server.policy child = VeryPermissive() ob = win32com.server.util.wrap(child, usePolicy=win32com.server.policy.DynamicPolicy) try: handle = pythoncom.RegisterActiveObject(ob, iid, 0) except pythoncom.com_error, details: print "Warning - could not register the object in the ROT:", details handle = None child.handle = handle ahk = win32com.client.Dispatch("ahkdemo.ahk") ahk.aRegisterIDs(clsid, appid) # autohotkey.exe ahkside.ahk # python /c/Python26/Scripts/ipython.py -wthread -i pythonside.py # must use -wthread otherwise calling com client hangs