[python-win32] DDE AddTopic after server started

Rickey, Kyle W Kyle.Rickey at bakerhughes.com
Tue May 6 16:25:50 CEST 2008


I've got a simple DDE Server running that I would like to add/remove
topics to on the fly.

The reason for doing this is my application uses subprocess to open
other programs which will then communicate back to mine using DDE. The
topic will never be exactly the same though, because the subprocess
expects the topic to be process_name+process_id

For example,

pid = subprocess.Popen(process_name).pid
server = dde.CreateServer()
server.AddTopic(DDE_Topic("wafieldsetup"+str(pid)))

Now, I would like to create one DDE server when I start my application
and as I launch these subprocesses, add/remove topics from the server.
Is this possible? In the code below I've got my DDE server running in a
separate thread. The whole thing will go inside of a wxpython
application.

import win32ui
from pywin.mfc import object
import dde
import threading, pythoncom, time


class DDETopic(object.Object):
	def __init__(self, topicName):
		object.Object.__init__(self, dde.CreateTopic(topicName))

	def Exec(self, cmd):
		print "Other Topic asked to exec", cmd

def test():
	pythoncom.CoInitialize()
	server = dde.CreateServer()
	server.AddTopic(DDETopic("testprocess1234"))
	server.Create('MyServer')
	print "Pumping Messages"
	while 1:
		time.sleep(0.1)
		win32ui.PumpWaitingMessages(0, -1)
		
threading.Thread(target=test).start()

#Launch a subprocess
#Add new topic to server


Is this going to work or do I need to create a new DDE Server for each
subprocess (seems clunky)?

-Kyle Rickey


More information about the python-win32 mailing list