Skip to content

win32com servers

COM servers are built by passing a com_server keyword argument to the setup function, the value must be a list of Python module names containing one or more COM server classes (identified by their _reg_progid_ attribute):

# setup.py
from distutils.core import setup
import py2exe

setup(com_server=["win32com.server.interp"])

By default, both an exe and a dll com server get generated.

The following two pages show how to do the same thing using ctypes.com: ctypes EXE servers & ctypes DLL servers

You can define and instantiate a Target class to explicitly state whether you want an exe or dll com server (or both) and to add version info resources that get attached to the file as metadata.

file setup.py would look something like this:

# This is the distutils script for creating a Python-based com (exe or dll)
# server using win32com.  This script should be run like this:
#
#  % python setup.py py2exe
#
# After you run this (from this directory) you will find two directories here:
# "build" and "dist".  The .dll or .exe in dist is what you are looking for.
##############################################################################

from distutils.core import setup
import py2exe
import sys

class Target:
    def __init__(self, **kw):
        self.__dict__.update(kw)
        # for the version info resources (Properties -- Version)
        self.version = "0.0.1"
        self.company_name = "my company"
        self.copyright = "© 2006, my company"
        self.name = "my com server name"

my_com_server_target = Target(
    description = "my com server",
    # use module name for win32com exe/dll server
    modules = ["dir.my_com_server"],
    # specify which type of com server you want (exe and/or dll)
    create_exe = True,
    create_dll = False
    )

setup(
    name="my_com_server",
    # the following two parameters embed support files within exe/dll file
    options={"py2exe": {"bundle_files": 1, }},
    zipfile=None,
    version="0.0.1",
    description="my com server",
    # author, maintainer, contact go here:
    author="First Last",
    author_email="some_name@some_company.com",
    packages=["dir"],
    com_server=[my_com_server_target]
    )