Re: [python-win32] Dynamic dispatching and AttributeErrors,

2010-11-17 Thread Mark Hammond

On 16/11/2010 5:14 AM, Brian Merrell wrote:

I am using Windows 7, 32-bit python 2.6, 2.7 and the latest win32 release.

* makepy seems to work, I find what appears to be the one and only
  appropriate library and it places an early binding skeleton file
  in the expected gen_py directory.  Anticipated classes and methods
  are observed.
* Whenever I call win32com.client.Dispatch on the "common name" (as
  derived from the skeleton file) it seems to return the dynamic
  dispatched version (even after using the EnsureModule method)


The above can happen for some objects which don't correctly report their 
type information at runtime - in which case you can often trick things 
using code similar to:


mod = win32com.gencache.EnsureModule(...)
ob = win32com.client.Dispatch(...)
# convert from dynamic to makepy supported.
ob = mod.GeneratedClassName(ob)



* When I try calling a known method on the returned COM object I get
  an AttributeError
* I've also tried using every CLSID I can find in my skeleton file c
  = Dispatch(CLSID) which results in either a "Class not registered"
  or an object that also gives an AttributeError for a known method.


A traceback would be useful here - if the object really is a dynamic 
object, an AttributeError implies that the object itself also doesn't 
think the attribute exists (as dynamic objects ask the object for the 
attribute before raising an AttributeError).


HTH,

Mark
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Dynamic dispatching and AttributeErrors,

2010-11-17 Thread Brian Merrell
Thanks for the response Mark.  My results inline below:

 mod = win32com.gencache.EnsureModule(...)
>
>>print mod


> ob = win32com.client.Dispatch(...)
>
>>ob

>>print ob
Traceback (most recent call last):
  File "", line 1, in 
  File "c:\python26\lib\site-packages\win32com\client\dynamic.py", line 197,
in __str__
return str(self.__call__())
  File "c:\python26\lib\site-packages\win32com\client\dynamic.py", line 182,
in __call__
return
self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.defaultDispatchName,None)
pywintypes.com_error: (-2147319779, 'Library not registered.', None, None)
 # convert from dynamic to makepy supported.

> ob = mod.GeneratedClassName(ob)
>
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'module' object has no attribute 'GeneratedClassName'

   * When I try calling a known method on the returned COM object I get

>
>>  an AttributeError
>>* I've also tried using every CLSID I can find in my skeleton file c
>>  = Dispatch(CLSID) which results in either a "Class not registered"
>>  or an object that also gives an AttributeError for a known method.
>>
>
> A traceback would be useful here - if the object really is a dynamic
> object, an AttributeError implies that the object itself also doesn't think
> the attribute exists (as dynamic objects ask the object for the attribute
> before raising an AttributeError).
>
I am calling a method listed in the gen_py file so I am not sure how the
attribute could not exist (I was careful about capitalization.  I can
post/send a very abbreviated version of this file (just the wrapper stuff
and a single method) if it would help.

Thanks!

-brian
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32