Creating COM server Events?

D

Dan

I have need to create a com server that will fire events back to
clients. I have looked at some of the documentation and I am new to
Python so cant quite get it. I have created an IDL file of the
interfaces. Can someone tell me approximately what needs to be done
here. I have seen examples of implementing the regular interfaces but
don't know what to do about the events interfaces.The vid...Events
interface is the main question here. In regular com development you
would implement something along the lines of Fire_OnNewData(). My Com
developement has mostly been with Borland tools and they do quite a bit
for you, As I hope Python will. Heres the IDL:

[
uuid(B0ADD4E1-1793-4089-8298-20B5A2DB0E82),
version(1.0),
helpstring("vidVisPython Library")

]
library vidVisPython
{

importlib("stdole2.tlb");

[
uuid(E26E3023-4F65-4E3D-A900-56C6302CD4E0),
version(1.0),
dual,
oleautomation
]
interface IVideoVisitationPython: IDispatch
{
[
id(0x00000001)
]
HRESULT _stdcall AdviseNewData( void );
};

[
uuid(50A02634-215F-47C6-9749-CDD02DC99B13),
version(1.0)
]
dispinterface IVideoVisitationPythonEvents
{
properties:
methods:
[
id(0x00000001)
]
HRESULT OnNewData( void );
};

[
uuid(134821F5-35B9-4917-B6EE-EF5C508BE949),
version(1.0)
]
coclass CoVideoVisitationPython
{
[default] interface IVideoVisitationPython;
[default, source] dispinterface IVideoVisitationPythonEvents;
};

};
 
D

Dan

Here is what little I have so far. I can use clients to call the advise
method and store in the mylist set (should be named myset i guess).
Now, I want the client to have to implement a callback and register the
interface in the AdviseChange method.

glcount=0
mylist= set()
class TestTTechPycom:
_public_methods_= ["AdviseChange","ShowTheList"]
_reg_progid_ = "TestTTechPycom"
_reg_clsid_ = "{D5BA19AA-0F4D-4022-A811-40C087FE089A}"

def AdviseChange(self):
if not self in mylist:
mylist.add(self)
print "added"
else:
print "already added"

def ShowTheList(self):
print mylist


if __name__=='__main__':
print "Registering TestTTechPycom server"
import win32com.server.register
win32com.server.register.UseCommandLine(TestTTechPycom)

So, when I call the AdviseChange now, a unique ID is placed into
mylist. If you run ShowTheList()
it will give a different instance ID for each registered client. Great!
So given something like;

def AdviseChange(self,interfacepointer)
mylist.add(interfacepointer)
How do I define what the interface for the interfacepointer should look
like. I mean in my typelib listed in my previous post, the interface
for the events were marked as Source so that COM knows that the client
must implement them. How do you do that in Python? Dan
 
R

Roger Upole

You'll need to implement the IConnectionPoint and
IConnectionPointContainer interfaces with your server.
See \win32com\demos\connect.py and
\win32com\server\connect.py for some sample code.

Roger

Dan said:
I have need to create a com server that will fire events back to
clients. I have looked at some of the documentation and I am new to
Python so cant quite get it. I have created an IDL file of the
interfaces. Can someone tell me approximately what needs to be done
here. I have seen examples of implementing the regular interfaces but
don't know what to do about the events interfaces.The vid...Events
interface is the main question here. In regular com development you
would implement something along the lines of Fire_OnNewData(). My Com
developement has mostly been with Borland tools and they do quite a bit
for you, As I hope Python will. Heres the IDL:

[
uuid(B0ADD4E1-1793-4089-8298-20B5A2DB0E82),
version(1.0),
helpstring("vidVisPython Library")

]
library vidVisPython
{

importlib("stdole2.tlb");

[
uuid(E26E3023-4F65-4E3D-A900-56C6302CD4E0),
version(1.0),
dual,
oleautomation
]
interface IVideoVisitationPython: IDispatch
{
[
id(0x00000001)
]
HRESULT _stdcall AdviseNewData( void );
};

[
uuid(50A02634-215F-47C6-9749-CDD02DC99B13),
version(1.0)
]
dispinterface IVideoVisitationPythonEvents
{
properties:
methods:
[
id(0x00000001)
]
HRESULT OnNewData( void );
};

[
uuid(134821F5-35B9-4917-B6EE-EF5C508BE949),
version(1.0)
]
coclass CoVideoVisitationPython
{
[default] interface IVideoVisitationPython;
[default, source] dispinterface IVideoVisitationPythonEvents;
};

};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top