Python COM Server with C++

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andre Bernemann

    Python COM Server with C++

    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
  • John J. Lee

    #2
    Re: Python COM Server with C++

    andre.bernemann @gmx.de (Andre Bernemann) writes:[color=blue]
    > 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[/color]

    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).

    [color=blue]
    > binding within VB with the NEW operator. I've googled around alot, but
    > I still have not the complete picture of what to do.[/color]

    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.

    [color=blue]
    > 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?[/color]

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

    [color=blue]
    > 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?[/color]

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

    [color=blue]
    > 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)[/color]
    [...]

    ditto


    John

    Comment

    • John J. Lee

      #3
      Re: Python COM Server with C++

      andre.bernemann @gmx.de (Andre Bernemann) writes:
      [color=blue]
      > 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[/color]
      [...]

      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

      Comment

      • Thomas Heller

        #4
        Re: Python COM Server with C++

        andre.bernemann @gmx.de (Andre Bernemann) writes:
        [color=blue]
        > 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?[/color]

        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

        Comment

        • John J. Lee

          #5
          Re: Python COM Server with C++

          Thomas Heller <theller@python .net> writes:
          [color=blue]
          > andre.bernemann @gmx.de (Andre Bernemann) writes:[/color]
          [...][color=blue]
          > 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.[/color]

          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

          Comment

          • Andre Bernemann

            #6
            Re: Python COM Server with C++

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

            Cheers
            André


            Comment

            Working...