[python-win32] IActiveScript::AddNamedItem fails with exception

David Manns davidm at pulsonix.com
Tue Apr 10 10:20:32 CEST 2012


I had to make that suggested change in two places in framework.py, plus a
change at around line 408 where FindBuildSubItemEvents tries to call
GetFuncDesc on the defaultType returned from GetDefaultSourceTypeInfo:

	defaultType = self.GetDefaultSourceTypeInfo(typeinfo)
	#***** WESTDEV EDIT ****************************
	if defaultType != None:
            	index = 0
                        while 1:

This finally allows our tiny test script (just creates a text file in
c:\temp) to run successfully, so I will now pass a copy of the amended
framework.py to our customer to see if this allows him to make some progress
with his own 'real' scripts.
Best regards,

-----Original Message-----
From: Mark Hammond [mailto:mhammond at skippinet.com.au] 
Sent: 05 April 2012 00:17
To: David Manns
Cc: python-win32 at python.org
Subject: Re: [python-win32] IActiveScript::AddNamedItem fails with exception

On 4/04/2012 8:20 PM, David Manns wrote:
> Mark,
> Thanks, that's better!
> Now I get this trace output:
> Collecting Python Trace Output...
> Object with win32trace dispatcher created (object=None)
>   in <win32com.axscript.client.pyscript.PyScript instance at
> 0x058BF300>._InvokeEx_-SetScriptSite(<PyIActiveScriptSite at 
> 0x058BF300>0x05806F58 with
> obj at 0x043F
> F22C>,) [1,0,None]
> Debugging interfaces not available - debugging is disabled..
> in <win32com.axscript.client.pyscript.PyScript instance at
> 0x058BF300>._InvokeEx_-InitNew() [1,0,None]
> in <win32com.axscript.client.pyscript.PyScript instance at
> 0x058BF300>._InvokeEx_-AddNamedItem(u'application', 14) [1,0,None]
> **************** ASSERTION FAILED ******************* The typeKind of 
> the object is unexpected in 
> <win32com.axscript.client.pyscript.PyScript instance at
> 0x058BF300>._InvokeEx_-Close() [1,0,None]
> Hopefully that means more to you than it does to me!

FWIW, the implementation is all in python in the win32comext\axscript\client
directory.  Grepping for this message shows it as appearing in framework.py
in the function GetSourceTypeInfo(). 
This function is attempting to locate the possible events for an item, but
it is only expecting the typeinfo to be one of TKIND_COCLASS or
TKIND_INTERFACE - sadly it doesn't report what was actually found, but you
might be able to determine that as it is your typeinfo being examined.
Assuming your objects don't actually have events, the simplest fix would be
to just change:

		if typeKind not in [pythoncom.TKIND_COCLASS,
			RaiseAssert(winerror.E_UNEXPECTED, "The typeKind of
the object is


		if typeKind not in [pythoncom.TKIND_COCLASS,
                         return None

[Sadly there is also a bug in that RaiseAssert function - it has the args
wrong when creating the exception - it should read 'raise Exception(desc,
scode)', hence the E_UNEXPECTED is coming out as E_FAIL
- but that's not really a big deal...]

Let me know if that works for you and I'll make that change for the next



More information about the python-win32 mailing list