[Tutor] creating a non-COM DLL
Bob Gailer
ramrom@earthling.net
Sat Nov 16 06:41:02 2002
--=====================_2203899==.ALT
Content-Type: text/plain; charset="us-ascii"; format=flowed
> > >I want to create a simple non-COM dll that I will call from a third
> party program.
> >
> > How timely. I have the same need. I've wandered around in various
> > documentation, but have yet to fine a sample python program for this
> purpose.
> >
> > It's my intention to call the dll from MS Visual FoxPro. Why, you ask? I
> > have an intention of converting a large VFP application to Python, with
> > some GUI yet to be determined. I want to convert chunks of VFP code that
> > run behind the scenes to python; eventually VFP will just manage the GUI;
> > then I can redo the GUI.
I've done more research; found help in ActiveState's ActivePython
distribution documentation and its win32com/servers sample code. I realize
that this creates a COM object rather than a non-COM dll, but that's OK for
my purposes. Article
Quick Start to Server Side COM and Python provides a simple program (which
I've modified), with a good discussion of the various components
:
----------------------------------------------------------------------------------------------
class HelloWorld:
_reg_clsid_ = '{BEA1AA48-1D0A-4D19-8E98-03C54F195B59}'
_reg_desc_ = "Python Test COM Server"
_reg_progid_ = "Python.TestServer"
_public_methods_ = ['Hello']
_public_attrs_ = ['softspace', 'noCalls']
_readonly_attrs_ = ['noCalls']
def __init__(self):
self.softspace = 1
self.noCalls = 0
def Hello(self, arg1):
return arg1 * 5
if __name__=='__main__':
import win32com.server.register
win32com.server.register.UseCommandLine(HelloWorld)
----------------------------------------------------------------------------------------
To obtain a unique clsid:
>>> import pythoncom
>>> print pythoncom.CreateGuid() # different each time
{7CC9F362-486D-11D1-BB48-0000E838A65F}
----------------------------------------------------------------------------------------
In Visual FoxPro:
o = createobject("Python.TestServer")
with o
?.hello(5) && displays 25
?.softspace && displays 1
.softspace = 2 && updates attribute
endwith
I discovered that VFP seems to cache the COM object; editing and
re-registering the Python program has no effect until one closes and
re-opens VFP. WIFNI Python had a "with" statement. I know its been
discussed a lot, but I still like it.
In VB:
set o = createobject("Python.TestServer")
Other languages??
Bob Gailer
170 Forsythe Rd
Nederland CO 80466
303-442-2625
--=====================_2203899==.ALT
Content-Type: text/html; charset="us-ascii"
<html>
<body>
<blockquote type=cite class=cite cite>> >I want to create a simple
non-COM dll that I will call from a third party program.<br>
><br>
> How timely. I have the same need. I've wandered around in
various<br>
> documentation, but have yet to fine a sample python program for this
purpose.<br>
><br>
> It's my intention to call the dll from MS Visual FoxPro. Why, you
ask? I<br>
> have an intention of converting a large VFP application to Python,
with<br>
> some GUI yet to be determined. I want to convert chunks of VFP code
that<br>
> run behind the scenes to python; eventually VFP will just manage the
GUI;<br>
> then I can redo the GUI.</blockquote><br>
I've done more research; found help in ActiveState's ActivePython
distribution documentation and its win32com/servers sample code. I
realize that this creates a COM object rather than a non-COM dll, but
that's OK for my purposes. Article <h1><b>Quick Start to Server Side COM
and Python </b>provides a simple program (which I've modified), with a
good discussion of the various components</h1>:<br>
----------------------------------------------------------------------------------------------<br>
class HelloWorld:<br>
_reg_clsid_ = '{BEA1AA48-1D0A-4D19-8E98-03C54F195B59}'<br>
_reg_desc_ = "Python Test COM Server"<br>
_reg_progid_ = "Python.TestServer"<br>
_public_methods_ = ['Hello']<br>
_public_attrs_ = ['softspace', 'noCalls']<br>
_readonly_attrs_ = ['noCalls']<br>
<br>
def __init__(self):<br>
self.softspace = 1<br>
self.noCalls = 0<br><br>
def Hello(self, arg1):<br>
return arg1 * 5<br><br>
if __name__=='__main__':<br>
import win32com.server.register <br>
win32com.server.register.UseCommandLine(HelloWorld)<br>
----------------------------------------------------------------------------------------<br>
To obtain a unique clsid:<br>
>>> import pythoncom<br>
>>> print pythoncom.CreateGuid() # different each time<br>
{7CC9F362-486D-11D1-BB48-0000E838A65F}<br>
----------------------------------------------------------------------------------------<br>
In Visual FoxPro:<br>
o = createobject("Python.TestServer")<br>
with o<br>
?.hello(5) && displays 25<br>
?.softspace && displays 1<br>
.softspace = 2 && updates
attribute<br>
endwith<br>
I discovered that VFP seems to cache the COM object; editing and
re-registering the Python program has no effect until one closes and
re-opens VFP. WIFNI Python had a "with" statement. I know its
been discussed a lot, but I still like it.<br><br>
In VB:<br>
set o =
createobject("Python.TestServer")<br><br>
Other languages??<br>
<x-sigsep><p></x-sigsep>
Bob Gailer<br>
170 Forsythe Rd<br>
Nederland CO 80466<br>
303-442-2625</body>
</html>
--=====================_2203899==.ALT--