Home arrow Python arrow Windows Programming in Python: Creating COM Servers

Windows Programming in Python: Creating COM Servers

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.

TABLE OF CONTENTS:
  1. Windows Programming in Python: Creating COM Servers
  2. Developing COM Servers Step by Step
  3. Annotating the Class with Attributes
  4. Creating COM Servers in the Real World
By: A.P.Rajshekhar
Rating: starstarstarstarstar / 8
January 22, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PYTHON ARTICLES

- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- 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

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: