[python-win32] com object in python

Tim Roberts timr at probo.com
Tue Nov 24 01:49:12 CET 2009


Jisun lee wrote:
>
>  
>
> Then I executed “MILD” in VC98 and got some files names “xx.h” and
> “xx_i.c” and tlb etc.
>
> So, I generated a VC++ project to call the instance with those.
>
> Even I succeed to compile but when I execute the result, it shows
> “interface error” which called by hr==E_NOINSTANCE after queryinterface().
>

Right.  The issue here is early vs late binding.  Did you notice that
nowhere, in your code, did you ever say that it should USE the interface
ID you created?  Your code doesn't actually implement your interface. 
Pythoncom uses "late" binding, which means it only implements
IDispatch.  Applications use the IDispatch interface to call the
services that you provide.  Pythoncom does not actually create a
complete C++ object that implements all of your interfaces -- that would
be too hard.

Applications like Excel and VB expect to use late binding to access
objects, so they would work.  With C++, you have to write specific code
to use IDispatch.

What you expected can be done, using a lower-level interface like
"comtypes", but it's a lot more work.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list