471,354 Members | 1,505 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

COM server and EXE

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"

Any suggestions please.......

Regards,
Tejovathi
Jan 8 '08 #1
2 2150
On Jan 8, 3:33*pm, Teja <tejovath...@gmail.comwrote:
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"

Any suggestions please.......

Regards,
Tejovathi
Here is my sample COM server and py2exe setup file

testCOM.py

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
sys.argv[1:]:
# --register and --unregister work as usual
import win32com.server.register
win32com.server.register.UseCommandLine(FirstEx)
else:
# start the server.
from win32com.server import localserver
localserver.main()
else:
import win32com.server.register
win32com.server.register.UseCommandLine(FirstEx)

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 = ["testCOM.py"])
#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
testCOM.py 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 setup.py 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....
Jan 8 '08 #2
On 8 Jan, 11:04, Teja <tejovath...@gmail.comwrote:
On Jan 8, 3:33 pm, Teja <tejovath...@gmail.comwrote:
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"
Any suggestions please.......
Regards,
Tejovathi

Here is my sample COM server and py2exe setup file

testCOM.py

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
sys.argv[1:]:
# --register and --unregister work as usual
import win32com.server.register
win32com.server.register.UseCommandLine(FirstEx)
else:
# start the server.
from win32com.server import localserver
localserver.main()
else:
import win32com.server.register
win32com.server.register.UseCommandLine(FirstEx)

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 = ["testCOM.py"])
#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
testCOM.py 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 setup.py 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....
A quick suggestion (didn't read very carefully sorry).
Make sure you register it with --debug and use the pythonwin tools-
>trace collector debugging tool.
See if you get any joy. It may be you missed some vital library in
your py2exe
that causes a start-up time failure.

Giles
Jan 8 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Nathan Sokalski | last post: by
9 posts views Thread by Grim Reaper | last post: by
14 posts views Thread by Developer | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.