Create DLL in Python ?

dsavitsk dsavitsk at e-coli.net
Mon Nov 11 20:54:08 EST 2002


"Georges Bernier" <mistericeberg at hotmail.com> wrote in message
news:1b318b70.0211111607.74ace07 at posting.google.com...
> Hello,
>
> We have a legacy application at work written in Visual C which makes
> use of a DLL for specific communication functions. Now I have to
> replace this DLL (whose API is well documented) with an enhanced
> version which will make use of TCP/IP instead of older protocols
> without changing the original C application (or at least changing the
> minimum possible).
>
> So does anybody have experience in such a thing, is it a bad idea (as
> I'm starting to think is is) and would it better be done in C/C++ ?
> I would appreciate comments from the Python community on this.

The easiest thing to do is to create a COM server which is what a dll is, or
rather can be. The simplest way to do this is as follows ...

class MY_COM_SERVER:

    # change this next line.  a new id can be generated with
    # >>> import pythoncom
    # >>> print pythoncom.CreateGuid()
    _reg_clsid_ = '{F69D8FCD-97BF-4D60-B5E5-199FC3C63172}'

    # list the public methods
    _public_methods_ = ['COM_SERVER_METHOD']

    # the server's name in the registry
    _reg_progid_ = 'PythonCOMServer.FirstServer'

    def COM_SERVER_METHOD(self):
        return 'Hello, World!'

if __name__ == '__main__':
    import win32com.server.register
    win32com.server.register.UseCommandLine(MY_COM_SERVER)

Register it by running it in an ide, or by double clicking the file.  It
would be accessed from VBScript as
Set x = CreateObject('PythonCOMServer.FirstServer')
x.COM_SERVER_METHOD

This creates a late bound COM server accessed like any other dll. There are
many more details, and you should look in the book Python Programming on
Win32 for more.

if, however, the original dll is not a COM object, then I can't help.

-d





More information about the Python-list mailing list