Create DLL in Python ?

Georges Bernier mistericeberg at hotmail.com
Tue Nov 12 03:31:33 EST 2002


"dsavitsk" <dsavitsk at e-coli.net> wrote in message news:<4bZz9.5692
> 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


dsavitsk,

Thanks a lot for your clear answer. Actually the current DLL I have to
replace is not a COM server but that sounds like a good idea.
I've seen the Win32 book on Safari that's definitely one that should
be on my shopping list.

Cheers,

Philippe.



More information about the Python-list mailing list