Python COM Server with C++

A

Andre Bernemann

Hi,

I have written a Python COM Server with the help of Mark Hammond's
Book Programming Python on Win32. I used the CreateObjects method in
VB to access the COM Methods and all worked fine. Unfortunately, that
is not what i really want. First I'd like to make the COM Server
accessible from C++ and as a beside product I want to use early
binding within VB with the NEW operator. I've googled around alot, but
I still have not the complete picture of what to do.

So far I think I have to create an IDL file to describe the interface
and compile it with the MIDL Compiler. There ist my first question.
What do I have to create first, the IDL file or the Python COM Server?
I'm a little bit confused about dispid's, the GUID's and naming
conventions. Do i need to make use of the makepy Utility in any way?

Do I have to modify the Python COM Server Source Code in any way or
can I use it as it is? (I can post the code here on request)

It would be great if anybody can give me information about the things
i have to do in order to make this work. Documentation links and
sample code would also be fantastic.

(I'm programming on Python 2.2 with the appropriate Windows Extensions
and Visual C++ 6.0)

Thx in advance

Andre
 
J

John J. Lee

I have written a Python COM Server with the help of Mark Hammond's
Book Programming Python on Win32. I used the CreateObjects method in
VB to access the COM Methods and all worked fine. Unfortunately, that
is not what i really want. First I'd like to make the COM Server
accessible from C++ and as a beside product I want to use early

I'd do this in ctypes, although its COM support is still quite new.
win32com (from win32all, aka Python for Windows Extensions, which is
what you're probably using ATM) has recently grown support for
implementing vtable interfaces (but not calling them, IIRC), but I
suspect one is less likely to get stuck when using ctypes, since
everything is pretty close to the way you'd do in in C (COM makes that
quite complicated, of course, but I think the ctypes COM support is
fairly 'thin' -- probably a good thing, IMHO -- but also elegant).

binding within VB with the NEW operator. I've googled around alot, but
I still have not the complete picture of what to do.

Take at look at win32/com/samples/server in the ctypes package -- an
example of implementing a dual interface. I haven't tried a dual
interface myself, but, as COM goes, it all looks very simple and
elegant.

So far I think I have to create an IDL file to describe the interface
and compile it with the MIDL Compiler. There ist my first question.
What do I have to create first, the IDL file or the Python COM Server?

IDL first. This is explained in the little comment at the top of the
sample.

I'm a little bit confused about dispid's, the GUID's and naming
conventions. Do i need to make use of the makepy Utility in any way?

I don't know how one implements vtable/dual interfaces in win32com.

Do I have to modify the Python COM Server Source Code in any way or
can I use it as it is? (I can post the code here on request)
[...]

ditto


John
 
J

John J. Lee

I have written a Python COM Server with the help of Mark Hammond's
Book Programming Python on Win32. I used the CreateObjects method in
VB to access the COM Methods and all worked fine. Unfortunately, that
[...]

Hmm, sorry, I didn't really read the question properly!

If you've started with win32all, you probably want to stick with it.
I'd guess the python-win32 list is more likely to yield answers
(though Mark has been posting here recently, so you might be
lucky...). Make sure to search the list archive first, of course.


John
 
T

Thomas Heller

Hi,

I have written a Python COM Server with the help of Mark Hammond's
Book Programming Python on Win32. I used the CreateObjects method in
VB to access the COM Methods and all worked fine. Unfortunately, that
is not what i really want. First I'd like to make the COM Server
accessible from C++ and as a beside product I want to use early
binding within VB with the NEW operator. I've googled around alot, but
I still have not the complete picture of what to do.

So far I think I have to create an IDL file to describe the interface
and compile it with the MIDL Compiler. There ist my first question.
What do I have to create first, the IDL file or the Python COM Server?
I'm a little bit confused about dispid's, the GUID's and naming
conventions. Do i need to make use of the makepy Utility in any way?

I think you should create the typelib first, and then write a com object
implementing the interfaces.

I don't have done it myself, but I suggest to look into the spambayes
project. It contains an outlook plugin, written by Mark Hammond.
Most certainly a bag full of ideas.

Thomas
 
J

John J. Lee

Thomas Heller said:
(e-mail address removed) (Andre Bernemann) writes: [...]
I think you should create the typelib first, and then write a com object
implementing the interfaces.

I don't have done it myself, but I suggest to look into the spambayes
project. It contains an outlook plugin, written by Mark Hammond.
Most certainly a bag full of ideas.

There's a cut down to bare-bones version of this in the win32all
package.

I wasn't able to get it working with the problem I tried, though (in
contrast to ctypes). I didn't try too hard, though, I admit ;-)


John
 
A

Andre Bernemann

Thank you very much for the help, I got it working with ctypes.

Cheers
André
 

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

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top