Catch COM events generated by a Python COM server with Visual Basic

Marc ENGEL marc.engel at recif.com
Wed Feb 6 04:07:49 EST 2002


I am trying for more than one week to use a Python COM server I made
inside Visual Basic. I encounter a problem with Connection Points

Here are the step I already tried:

a - I made a python com server deriving from ConnectableServer.

b - I tested my python com server with a python client. Everything is
working fine including Events. The callback are called correctly.

c - I used typelibutil to generate a Type library for this COM server.
Then I testes my server from VB. As typelibutil does not manage
Connection Points, I was only able to call the methods exposed by my
COM server.

d - I extracted the IDL from this TLB and manually added support for
Connection Points. I created the Event interface:
[.....]
interface IMyServer_Event
{
  [id(1), helpstring("method MyEvent")] HRESULT MyEvent();
};

and added in the coclass the line:

[default, source] interface IMyServer_Event;

e - I recompiled this IDL with MIDL and get a new TLB.

f - From VB, I added a reference to this new TLB. The object viewer
shows me correctly the methods and the event

g - I declared in VB my COM object using the syntax:
Dim WithEvents MyServInstance As MyServComponent
Then VB automatically created the handler for my event:
MyServInstance_MyEvent where I just added a message box

The problem occurs here: I can still call the methods but the event is
never called!

I have tested several things including:

When I call in the server:
interface.Invoke(1, 0, pythoncom.DISPATCH_METHOD, 0, arg)
nothing happens.

I know the VB client call the Advise method of ConnectableServer
because I traced it.

If I call:
id = interface.GetIDsOfNames('MyEvent')
I got a unexpected result: id = 0x60030005

Then if I call invoke on this id nothing happens on the client

I have generated the python stub class for early-binding using makepy
on the TLB generated. I needed to change my interface to a
dispinterface. It worked properly

I managed also to receive event in VB using a small C++ server.

Now I don't know what to do.

If someone has any idea, he is very welcome. The best would be a
working example

Thanks in advance,

--
Marc



More information about the Python-list mailing list