This project has moved and is read-only. For the latest updates, please go here.

Type Library Intellisense for COM Objects

Sep 11, 2014 at 12:27 AM
Edited Sep 11, 2014 at 12:28 AM
When I add TLB reference for COM Objects in Excel, then I can see the arguments of methods even in limited Excel VBA tooltips.
However using comtypes.client.createobject() PTVS does not show the parameters of methods, although it shows the available properties and methods of the loaded COM object.
Any way to get similar (or better!) intellisense experience like in Excel?
Sep 11, 2014 at 3:55 AM
There's no way to make it work like that immediately.

It's doable in principle - the code analysis engine would need to acquire some special knowledge about comtypes for that to work (and ditto for pythondotnet) - but it is a fairly major feature in its own right, and something that we're not likely to get to in near future.

If you're interested in hacking on the analyzer code to add this (and we take pull requests!), you can look at some of the existing specializations for an example. E.g. there is a specialization for WPF LoadComponent, so that named XAML elements are properly shown as attributes on self within a window or a control. Look for LoadComponent here:
Sep 21, 2014 at 11:21 PM
Edited Sep 21, 2014 at 11:23 PM
Before I was using comtypes for working with COM objects, which does not show arguments of methods.
Then I switch to pywin32 and it works!

from win32com.client import Dispatch as comDispatch
xl = comDispatch('Excel.Application')

See this picture:

Sep 22, 2014 at 12:16 AM
The interactive window is a completely different beast to the editor - they use completely different methods for finding completions.

In the interactive windows, we will show you whatever Python knows about (with dir(), etc.) and so the Python library (pywin32 in this case) is responsible for getting those right. If comtypes is lacking support for proper function signatures and doc strings, we can't do anything to help. You should suggest that they implement support for that to them

PMinaev's more complicated answer applies to our editor, where we try and figure out the same info but without actually executing the code. If you need support for COM types here, then by all means suggest it to us, but be aware that it'll probably be a relatively low priority. It is possible to extend this support without our help, but it's not easy and I don't think anyone has ever attempted it.