import comtypes.client as cc import comtypes tlb_id = comtypes.GUID("{E1A39F48-A3F9-4334-8CC5-05FCF27262F4}") #Type Lib GUID cc.GetModule((tlb_id, 1, 0)) # 1 and 0 are major number and minor number of our Type Lib import comtypes.gen.AutomationServerWithRegFileLib2 as AutomationServer #AutomationServerWithRegFileLib2 is Type lib name specified in IDL file pIMyMath = cc.CreateObject("{C23FCCA0-33C8-49E5-9D79-38AF6347D4F1}", None, None, AutomationServer.IMyMath) #Passed CoClass ID(clsid) and Interface name result=pIMyMath.SumOfTwoIntegers(25,20) print "Sum of 25 and 20 is:"+ str(result) print "Requesting IMyMath using pIMyMath" pIMyMath2=pIMyMath.QueryInterface(AutomationServer.IMyMath) result2=pIMyMath.SubtractionOfTwoIntegers(250,100) print "Subtraction of 250 and 100 is:"+ str(result2)