As a note, I have read that I should be using ctypes instead of calldll, but am not sure how to implement that change.
________________________________________ From: python-win32-bounces+aellis02=syr....@python.org [python-win32-bounces+aellis02=syr....@python.org] on behalf of Alexis Ellis [aelli...@syr.edu] Sent: Friday, May 04, 2012 11:07 AM To: Tim Roberts; Python-Win32 List Subject: Re: [python-win32] Accessing methods from python-based COM DLL generated using py2exe Tim, Thank you for your help. I was obviously headed down the wrong path. As per your suggestion, I am now using comtypes to create a com server. I have generated a tlb and am trying to use comtypes.client.GetModule to generate a wrapper and register the COM (see myserver.py below). However, when I try do to this using the following command: >>python myserver.py /regserver I get the following error: Traceback (most recent call last): File "myserver.py", line 23, in <module> import win32com.server.register File "c:\python26\arcgis10.0\lib\site-packages\win32com\server\register.py", l ine 13, in <module> import winerror File "c:\python26\arcgis10.0\winerror.py", line 3, in <module> from nterror import * File "c:\python26\arcgis10.0\nterror.py", line 4, in <module> import windll File "c:\python26\arcgis10.0\windll.py", line 20, in <module> import calldll ImportError: No module named calldll I do not have a module named calldll and can not find one online (other than for python2.4 - I am using 2.6.5). Not sure how to address this. Any help would be greatly appreciated! Thanks, Alexis The following is my wrapper/registration code: myserver.py ///////////////////////////////// import comtypes import comtypes.server.localserver from comtypes.client import GetModule # generate wrapper code for the type library, this needs # to be done only once (but also each time the IDL file changes) GetModule("comcreate.tlb") from comtypes.gen.MyTypeLib import MyObject class MyObjectImpl(MyObject): # registry entries _reg_threading_ = "Both" _reg_progid_ = "MyTypeLib.MyObject.1" _reg_novers_progid_ = "MyTypeLib.MyObject" _reg_desc_ = "Simple COM server for testing" _reg_clsctx_ = comtypes.CLSCTX_INPROC_SERVER | comtypes.CLSCTX_LOCAL_SERVER _regcls_ = comtypes.server.localserver.REGCLS_MULTIPLEUSE #register is a module-level function def register(): import win32com.server.register win32com.server.register.UseCommandLine(MyObjectImpl) if __name__ == "__main__": register() ////////////////////////////////////////////// ________________________________________ From: python-win32-bounces+aellis02=syr....@python.org [python-win32-bounces+aellis02=syr....@python.org] on behalf of Tim Roberts [t...@probo.com] Sent: Thursday, May 03, 2012 1:19 PM To: Python-Win32 List Subject: Re: [python-win32] Accessing methods from python-based COM DLL generated using py2exe Ellis, Alexis -FS wrote: > > > > am trying to generate a DLL from a python script that can be accessed > from a variety other programming platforms. > > I am generating the python-based COM DLL using a distutils setup > script that is called using py2exe. > > The DLL is successfully generated and I can register it using > regsvr32, but now I am not sure how to access the function within the dll. > Well, you have not actually created a COM server here. What you have registered is an empty COM server that defines no methods. You haven't actually used any methods from comtypes or comtypes.client at all. You need to read the documentation for comtypes.server. You have to create an IDL file (Interface Description Language) that defines the methods you expect to expose. You compile that IDL to a type library (TLB). Then, you use comtypes.client.GetModule to generate a wrapper for that IDL. Then, your "testscript" module must derive from that class, and implement the methods you declared. comtypes creates an "early binding" COM server. Depending on the languages you want to use, you might find it easier to create a "late binding" server using Pythoncom, as described here: http://showmedo.com/videotutorials/video?name=2190050&fromSeriesID=219 No IDL is required with this method. -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32