472,139 Members | 1,371 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Cannot register dll created using "py2exe --com-dll"

I'm feeling quite dumb this morning.

I'm trying to build a COM server DLL using py2exe and it ain't working.

Here's what ain't working...

setup_dll.py based on py2exe sample:
"""from distutils.core import setup
import py2exe

setup(name="MadeUpName Object Model",
scripts=['madeupname.application'],
output_base='madeupname')
"""

Command line for building dll (N.B. python 2.3 as instructed):
"""c:\python23\python madeupname/setup_dll.py py2exe --com-dll --excludes Tkinter"""

Command line for registering dll:
regsvr32 c:\pvcs\madeupname\model\dist\application.dll

Result when I try to register dll:
"""DllRegisterServer in c:\pvcs\madeupname\model\dist\application.dll failed.
Return code was: 0x80040201
"""

The winerror.h entry for this says:
"""//
// MessageId: CO_E_FAILEDTOGETSECCTX
//
// MessageText:
//
// Unable to obtain server's security context
//
#define CO_E_FAILEDTOGETSECCTX _HRESULT_TYPEDEF_(0x80040201L)
"""

But I'm guessing that this is simply a way of saying the I haven't told
pythoncom (via py2exe) which classes to register. I'm looking at the
source and I am trying to work it out but failing :-(

I have tried an exe server, but this does not register either.

Any suggestions?

Also does anyone know what argument to use to get py2exe to build something
other than "application.[dll/exe]". I thought 'output_base' as an argument
to setup() would do it, but no joy.

If you folks can make me feel even more stupid by pointing out my
obvious mistake, that would make me happy. :-)

Thanks for reading,
Giles Brown
Jul 18 '05 #1
5 8871
Giles Brown wrote:
I'm feeling quite dumb this morning.

I'm trying to build a COM server DLL using py2exe and it ain't working.
Not too surprising seeing as it was checked in just days ago :)

Command line for registering dll:
regsvr32 c:\pvcs\madeupname\model\dist\application.dll

Result when I try to register dll:
"""DllRegisterServer in c:\pvcs\madeupname\model\dist\application.dll failed.
Return code was: 0x80040201
"""
This generally just means that there was a Python exception. As regsvr
is a GUI app, the exception is lost. You may like to add "import
win32traceutil" at the top of your script (see win32traceutil.py for
details) - or if that fails, at the top of boot_com_servers.py.
I have tried an exe server, but this does not register either.
Try an EXE server build with the console flag set. This should allow
you to see the exception without redirecting error output.
Also does anyone know what argument to use to get py2exe to build something
other than "application.[dll/exe]". I thought 'output_base' as an argument
to setup() would do it, but no joy.


Can't recall - sorry.

Mark.

Jul 18 '05 #2
Err, I meant argv just isn't getting set :) It's early.
Jul 18 '05 #3

A fix that seems to work (at least it lets DllRegisterServer succeed) is inserting
the following before the aforementioned line:

scriptDir = None
if hasattr(sys, 'argv'):
scriptDir = os.path.split(sys.argv[0])[0]

This allows registration, but now when I try to instantiate one of the objects
defined in my dll from the interpreter, I get the following error:

Fatal Python error: PyThreadState_Get: no current thread

This also happens with the server example included. Do I have to use something
other than win32com.client.Dispatch to connect to an inproc server from a
dll? I think I've used it before to do the same thing with non-py2exe dlls.

Jordan
Jul 18 '05 #4
gi*********@hotmail.com (Giles Brown) wrote in message news:<57**************************@posting.google. com>...
I'm feeling quite dumb this morning.


Next morning not quite so dumb. Finally got the dll to register so
I thought I'd post my findings for the record.

Mark was spot on (of course!) about the lost python exception. I
added
"import win32traceutil" into boot_com_server and low the traceback
showed in pythonwin.

I had omitted to mention that I am using win32com client inside the
dll,
so I added the necessary '--progids' (only "ADODB.Connection.2.1" as
it happens).

<aside>
Inside one of my modules I use the gencache.EnsureModule function.
"""#Microsoft ActiveX Data Objects 2.1 Library
# {00000201-0000-0010-8000-00AA006D2EA4}, lcid=0, major=2, minor=1
gencache.EnsureModule('{00000201-0000-0010-8000-00AA006D2EA4}', 0, 2,
1)
"""
This function takes a CLSID (? I think). If I want to use this
specific
typelib based module, how do I determine what progid to give to py2exe
to ensure that this module is picked up? Or am I doing the wrong
thing?
</aside>

Then I found that my dll when run (for registration) was trying to
generate
an '__init__.py' in the equivalent of the gen_py folder. This was
failing
because it was looking for win32com.__gen_path__ which is not set for
frozen code. To overcome this I added (something like) the following
code
to my module that was included the EnsureModule call.

if getattr(pythoncom, 'frozen', False):

import os
import win32com
import tempfile

# Assign (temporary) directory for gencache
# (tempfile.tempdir is always 'None' so use TemporaryFile()) :-(
win32com.__gen_path__ = os.path.join(os.path.dirname(
tempfile.TemporaryFile().name), 'gencache')

Finally I was getting the "codec" problem. I tried '--packages
encodings' but
for some reason this did not seem to build encodings.__init__.pyc into
the
dll. This exhibited itself in the "no codec search functions
registered"
LookupError. Adding '--include encodings" fixed this. This lead (not
unreasonably) to a "unknown encoding: utf-8" LookupError which was
fixed by
added ",encodings.utf_8" to the command line.

The final working command line looked like this:
c:\python23\python madeupname/setup_dll.py py2exe --com-dll --include
encodings,encodings.utf_8 --excludes Tkinter --progids
ADODB.Connection.2.1

Now I need to test the DLL :-)

Cheers and thanks,
Giles
Jul 18 '05 #5
giles_brown@hotmail.com (Giles Brown) wrote in message news:<57de9986.0307290052.688e54c5@posting.google. com>...[color=blue]
> I'm feeling quite dumb this morning.[/color]

Next morning not quite so dumb. Finally got the dll to register so
I thought I'd post my findings for the record.

Mark was spot on (of course!) about the lost python exception. I
added
"import win32traceutil" into boot_com_server and low the traceback
showed in pythonwin.

I had omitted to mention that I am using win32com client inside the
dll,
so I added the necessary '--progids' (only "ADODB.Connection.2.1" as
it happens).

<aside>
Inside one of my modules I use the gencache.EnsureModule function.
"""#Microsoft ActiveX Data Objects 2.1 Library
# {00000201-0000-0010-8000-00AA006D2EA4}, lcid=0, major=2, minor=1
gencache.EnsureModule('{00000201-0000-0010-8000-00AA006D2EA4}', 0, 2,
1)
"""
This function takes a CLSID (? I think). If I want to use this
specific
typelib based module, how do I determine what progid to give to py2exe
to ensure that this module is picked up? Or am I doing the wrong
thing?
</aside>

Then I found that my dll when run (for registration) was trying to
generate
an '__init__.py' in the equivalent of the gen_py folder. This was
failing
because it was looking for win32com.__gen_path__ which is not set for
frozen code. To overcome this I added (something like) the following
code
to my module that was included the EnsureModule call.

if getattr(pythoncom, 'frozen', False):

import os
import win32com
import tempfile

# Assign (temporary) directory for gencache
# (tempfile.tempdir is always 'None' so use TemporaryFile()) :-(
win32com.__gen_path__ = os.path.join(os.path.dirname(
tempfile.TemporaryFile().name), 'gencache')

Finally I was getting the "codec" problem. I tried '--packages
encodings' but
for some reason this did not seem to build encodings.__init__.pyc into
the
dll. This exhibited itself in the "no codec search functions
registered"
LookupError. Adding '--include encodings" fixed this. This lead (not
unreasonably) to a "unknown encoding: utf-8" LookupError which was
fixed by
added ",encodings.utf_8" to the command line.

The final working command line looked like this:
c:\python23\python madeupname/setup_dll.py py2exe --com-dll --include
encodings,encodings.utf_8 --excludes Tkinter --progids
ADODB.Connection.2.1

Now I need to test the DLL :-)

Cheers and thanks,
Giles

Hi All,

I am having a similar problem as this thread suggests but I am not being able to solve my problem. I wrote a simple COM server DLL and registered it successfully on my machine. I tested this DLL using a simple EXCEL/VBA script and that was successful too.
Now the problem began. I tried to register this dll on a friend's machine(this machine did not have python or py2exe installed) and I was getting this error -

---------------------------
RegSvr32
---------------------------
DllRegisterServer in TestCOMServer2.dll failed.
Return code was: 0x80040201
---------------------------
OK
---------------------------

I tried to register this dll on another machine which had python and py2exe installed and there i successfully got it registered but when i tested the code using Excel/VBA i got the error "Catastrophic Failure".

Does anyone have any idea why i am getting these different errors on different machines (all Win XP professional machines).

regards,
Ranjit
Feb 27 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Andrew | last post: by
reply views Thread by =?Utf-8?B?QXR1bCBSYW5l?= | last post: by
reply views Thread by leo001 | 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.