Python
  Home arrow Python arrow Windows Programming in Python: Creating COM Servers
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PYTHON

Windows Programming in Python: Creating COM Servers
By: A.P.Rajshekhar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 6
    2007-01-22


    Table of Contents:
  • Windows Programming in Python: Creating COM Servers
  • Developing COM Servers Step by Step
  • Annotating the Class with Attributes
  • Creating COM Servers in the Real World

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Windows Programming in Python: Creating COM Servers
    ( Page 1 of 4 )

    In an earlier article I discussed accessing COM components from within Python programs. However, I left a question dangling, namely, can COM servers be created in Python, and can they be accessed by applications created in other languages or platforms such as Visual Basic? The answer is an emphatic yes.

    In this discussion I will be tackling the whys and wherefores of creating COM servers in Python. In the first section the focus will be on COM servers. In the second section and third sections, I will detail the necessary steps for creating a COM server in Python. The fourth section will provide a real world example of developing a COM server and calling it from Visual Basic. That's the outline for this discussion.

    More About COM

    In the world of COM there is a clear line of separation between accessing COM components and implementing COM objects. While accessing COM objects, method calls are made on them, provided externally using the interfaces exposed by the COM object. When implementing COM objects, which are also known as COM servers, the object has to publish or expose its interfaces so that external clients can use them.

    This difference is evident from the way the interfaces and methods implemented are utilized either to access a COM component or expose the functionalities of a COM component. The interface under consideration is IDispatch. Programs that use an IDispatch object must call the GetIDsOfNames() and Invoke() methods to perform method calls or property reference, whereas the objects that wish expose their functionalities via IDispatch must implement the GetIDsOfNames() and Invoke() methods, providing the logic for translating between names and IDs, and so on. In the world of PythonCOM, the former is called client-side COM and the latter is server-side COM.

    The next topic I will cover is the types of server-side COM objects. There are three types of server-side COM objects:

    1. In-Proc Server
    2. Local Server
    3. Remote Server

    The difference in the types is based on where the COM server is executing. The COM server could be executing in the process space of the client, in its own separate process space, or on a different system. Here are the details.

    In-Proc Server

    When the COM server is loaded into the process space of the client, it is known as an In-Proc server. In other words, "A Component Object Model (COM) object that is executing in the same process space as the user of that object is called an In Process object (InProc for short)." An In-Proc server is implemented as a DLL in other languages.

    Local Server

    When the COM server is loaded and executed in its own process space, it is called a Local Server. By definition, "When the user code is executing in the process space of Application A, and the COM object is executing in the process space of Application B, interface method invocations by A on interfaces implemented on B clearly must cross process boundaries, then the COM objects in Application B are cross-process objects, or Local Servers." A Local Server is implemented in the form of an EXE.

    Remote Server

    When the COM server is implemented as an EXE but executed on a remote machine, it is known as a Remote Server. Remote Servers come under the heading of Distributed COM or DCOM.

    The important aspect of these differences is that they are mutually inclusive. That means a COM component can be registered as a combination of any of the above three types. Now that the types of COM servers have been introduced, let's see how to develop COM servers in Python step-by-step.



     
     
    >>> More Python Articles          >>> More By A.P.Rajshekhar
     

       

    PYTHON ARTICLES

    - Tuples and Other Python Object Types
    - The Dictionary Python Object Type
    - String and List Python Object Types
    - Introducing Python Object Types
    - Mobile Programming using PyS60: Advanced UI ...
    - Nested Functions in Python
    - Python Parameters, Functions and Arguments
    - Python Statements and Functions
    - Statements and Iterators in Python
    - Sequences and Sets in Python
    - Python Expressions and Operators
    - Dictionaries, Variables and Statements in Py...
    - Data Types in Python
    - The Python Language
    - SSH with Twisted





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT