First you should check the registry that the object has indeed been registered correctly via the name you expect, and points at your generated DLL. 


If that is all OK, it is likely that some other error is happening as the object is loaded.  You will probably need to arrange for your script to be registered in "debug" mode (which means passing "debug=1" as a keyword arg to win32com.server.RegisterClasses()), then starting win32traceutil to view debug output.  You should see some output as regsvr32 runs, and also as VB attempts, but fails, to load your object.




From: [] On Behalf Of Tejovathi P
Sent: Wednesday, 9 January 2008 7:05 PM
To: Mark Hammond
Subject: Re: [Py2exe-users] Regarding COM server and py2exe


Hi Mark,


Thanks for your reply. I changed the py2exe script as per your suggestion an was able to generate the dll instead of exe.

I was also able to register it using regsvr32 command at command prompt.


Any idea , now how should start using the functionalities in this dll in a VB/C# application?


Because CreateObject("Sample.lib") is throwing errors in the same old manner, even after the dll is registered


On 1/9/08, Mark Hammond <> wrote:

The lines:

   com_server = ["win32com.servers.interp"],
   console = [" "])

are incorrect.  the 'console=' line is creating an executable, but you
probably just need a .dll.  The com_server line indicates which module
should be turned into a COM DLL, but you are still specifying the pywin32
sample object.

Try just:

com_server = ['testCOM']

and remove the 'console=' line.  After running py2exe, execute 'regsvr32
testCOM.dll' to register the object in that DLL.




[mailto:] On Behalf Of Tejovathi P
Sent: Tuesday, 8 January 2008 10:10 PM
Subject: [Py2exe-users] Regarding COM server and py2exe

Hi All,
I have a Python COM server. I need to deploy it on various sytems. When I
run the COM server from
python its showing an output " Registered : sample.lib"
If I try to use the COM obj from a VB client like:
obj = CreateObject("sample.lib")
Its working fine without any errors
Now I am trying to convert this COM server to an exe through py2exe and
after I run the exe, I am
getting the same output " Registered : sample.lib"
But If I try to use the COM obj from a VB client like
obj = CreateObject("sample.lib")
A console pops up saying " Registered : sample.lib" and VB application
hangs there. Its throwing a VB error that "ActiveX object cannot be
created......etc etc"
Here is my sample COM server and py2exe setup file
import win32com.client
import os.path
import shutil
from win32api import Sleep
import string
import os
import sys
import pythoncom
class FirstEx:
  _reg_clsid_ = "{A6DE9DF8-5EBF-48E6-889E-C71CB84CFF2C}"
  pythoncom.frozen = 1
  if hasattr(sys, 'importers'):
  # In the py2exe-packed version, specify the module.class
  # to use. In the python script version, python is able
  # to figure it out itself.
  _reg_class_spec_ = "__main__.FirstEx"
  _reg_desc_ = "My first COM server"
  _reg_progid_ = " SAMPLE.Lib"
  _public_methods_ = ['init', 'Version']
  _public_attrs_ = ['softspace', 'noCalls']
  _readonly_attrs_ = ['noCalls']
  _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER
  def __init__(self):
  self.softspace = 1
  self.noCalls = 0
  def Version(self):
  self.noCalls = self.noCalls + 1
  # insert "softspace" number of spaces
  return "Version: 0.0.1"
if __name__=='__main__':
  import sys
  if hasattr(sys, 'importers'):
  # running as packed executable.
  if '--register' in sys.argv[1:] or '--unregister' in
  # --register and --unregister work as usual
  import win32com.server.register
  # start the server.
  from win32com.server import localserver
  import win32com.server.register
Here is my setup file:
#Start here
from distutils.core import setup
import py2exe
setup(options = {"py2exe": {"compressed": 1,
  "optimize": 2,
  "ascii": 1,
  "bundle_files": 1}},
  zipfile = None,
  com_server = ["win32com.servers.interp "],
  console = [""])
#End here
Here is my VB code:
Sub subRoutine()
Dim connection As Object
Dim returnvalue1 As String
Dim returnvalue2 As String
Dim flag3 As Boolean
Set connection = CreateObject("SAMPLE.Lib")
returnvalue1 = connection.Version()
MsgBox (returnvalue1)
End Sub
The non exe version of the COM server ie. directlly running the registers the library properly and
in the VB application, the message box displays the version as 0.0.1.
But, after I create the EXE file using the file and run it,
it registers the library.
When I run the VB application, it hangs at the line
Set connection = CreateObject("SAMPLE.Lib")
and displays. " ACTIVEX cannot create the object"
Any suggestions please....