COM server and EXE

T

Teja

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
 
T

Teja

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....
 
G

Giles Brown

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top