Help with COM and Type Library

Jeff Winkelman jwinkelman at movaz.com
Tue Apr 2 09:38:54 EST 2002


I need some help with creating a type library for a Python COM Server
I am trying to implement.

I've read through previous postings on comp.lang.python regarding
creating type libraries and Python COM Servers, and have made some
progress.

I followed Alex Martelli's suggestion (Jan. 2001) to perform the
following steps:

1.  Create and IDL file
2.  Generate a type library using MIDL.
3.  Run makepy.py on the type library which generates a module with
some useful code.

My problem now is that I don't know what to do with this generated
file.

Here is my generated file:

# Created by makepy.py version 0.4.0
# By python version 2.1.1 (#20, Jul 26 2001, 11:38:51) [MSC 32 bit
(Intel)]
# From type library 'HelloWorld.tlb'
# On Mon Apr 01 16:02:09 2002
"""HelloWorld 1.0 Type Library"""
makepy_version = '0.4.0'
python_version = 0x20101f0

import win32com.client.CLSIDToClass, pythoncom

# The following 3 lines may need tweaking for the particular server
# Candidates are pythoncom.Missing and pythoncom.Empty
defaultNamedOptArg=pythoncom.Missing
defaultNamedNotOptArg=pythoncom.Missing
defaultUnnamedArg=pythoncom.Missing

CLSID = pythoncom.MakeIID('{D71160DA-3B79-49A5-9E6E-FA23F458FBFB}')
MajorVersion = 1
MinorVersion = 0
LibraryFlags = 8
LCID = 0x0

from win32com.client import DispatchBaseClass
class IHelloWorld(DispatchBaseClass):
	"""IHelloWorld Interface"""
	CLSID = pythoncom.MakeIID('{DA3F71EA-ADFA-44F0-A890-1F88120C8309}')

	def Hello(self, who=defaultNamedNotOptArg):
		"""method Hello"""
		return self._oleobj_.InvokeTypes(0x1, LCID, 1, (24, 0), ((12,
0),),who)

	_prop_map_get_ = {
	}
	_prop_map_put_ = {
	}

class CoClassBaseClass:
	def __init__(self, oobj=None):
		if oobj is None: oobj = pythoncom.new(self.CLSID)
		self.__dict__["_dispobj_"] = self.default_interface(oobj)
	def __repr__(self):
		return "<win32com.gen_py.%s.%s>" % (__doc__,
self.__class__.__name__)

	def __getattr__(self, attr):
		d=self.__dict__["_dispobj_"]
		if d is not None: return getattr(d, attr)
		raise AttributeError, attr
	def __setattr__(self, attr, value):
		if self.__dict__.has_key(attr): self.__dict__[attr] = value; return
		try:
			d=self.__dict__["_dispobj_"]
			if d is not None:
				d.__setattr__(attr, value)
				return
		except AttributeError:
			pass
		self.__dict__[attr] = value

class HelloWorld(CoClassBaseClass): # A CoClass
	# HelloWorld Class
	CLSID = pythoncom.MakeIID("{35B9B525-B4E8-4953-A0E9-680B99FAF11C}")
	coclass_sources = [
	]
	coclass_interfaces = [
		IHelloWorld,
	]
	default_interface = IHelloWorld

IHelloWorld_vtables_dispatch_ = 1
IHelloWorld_vtables_ =  [('Hello', 1, ((12, 0, None),), (3, 0, None),
('who',))]

RecordMap = {
}

CLSIDToClassMap = {
	'{DA3F71EA-ADFA-44F0-A890-1F88120C8309}' : IHelloWorld,
	'{35B9B525-B4E8-4953-A0E9-680B99FAF11C}' : HelloWorld,
}
CLSIDToPackageMap = {}
win32com.client.CLSIDToClass.RegisterCLSIDsFromDict( CLSIDToClassMap )
VTablesToPackageMap = {}
VTablesToClassMap = {
}


VTablesNamesToCLSIDMap = {
	'IHelloWorld' : '{DA3F71EA-ADFA-44F0-A890-1F88120C8309}',
}


At this point, I'm stuck.  I really don't even know where to start
modifying this generated file and pulling out the stuff I don't need. 
If I look at example COM Servers implemented in Python, several of the
things I need are missing from this file.

Here is my COM Server all by itself.

class HelloWorld:
	# HelloWorld Class
	_public_methods_ = ['Hello']
	_public_attrs_ = ['softspace', 'noCalls']
	_readonly_attrs_ = ['noCalls']
	# All registration stuff to support fully automatic
register/unregister
	_reg_verprogid_ = "PYTHONLib.HelloWorld.1"
	_reg_progid_ = "PYTHONLib.HelloWorld"
	_reg_desc_ = "Hello World Example"
	_reg_clsid_ = "{35B9B525-B4E8-4953-A0E9-680B99FAF11C}"
	_reg_class_spec_ = "HelloWorld"

	def __init__(self):
		self.softspace = 1
		self.noCalls = 0
	def Hello(self, who):
		self.noCalls += 1
		return "Hello" + " "*self.softspace + who

Do I even need the CoClassBaseClass and IHelloWorld classes?

What significance does the vtable stuff have?  It seems to me that I
would not need this either since I am not wrapping up an existing
server, but rather implementing my own.

Can anyone give me some pointers on where to go from here?

Thanks in advance for any help.

Jeff



More information about the Python-list mailing list