I am trying to create a simple COM server using Python 2.7 on 64-bit Windows 7, but I cannot get the DLL registered successfully. I can do this successfully using Python 2.6 on 32-bit Windows XP. I can also register my class directly from Python.
This is my heikki.py module based on the pywin32 COM tutorial :
class Heikki:
_reg_clsid_ = '{F4C7D945-BF6B-4BF8-BCBB-EA021FCCE623}'
_reg_desc_ = "Heikki"
_reg_progid_ = "Heikki.TestServer"
_public_methods_ = ['Hello']
def __init__(self):
pass
def Hello(self):
return 1
if __name__=='__main__':
from win32com.server import register
register.UseCommandLine(Heikki)
I can successfully register it from the command line (I have 64-bit Python 2.7.1, pywin32 214, py2exe 0.6.9, c: \ python27 is in PATH):
C:\temp> python heikki.py
Registered : Heikki.TestServer
C:\temp> python heikki.py --unregister
Unregistered : Heikki.TestServer
Then I created the setup.py file based on the py2exe COM server in c: \ temp:
from distutils.core import setup
import py2exe
class Target:
def __init__(self, **kw):
self.__dict__.update(kw)
self.version = "1.0"
self.company_name = "My name"
self.copyright = "(C) 2011, My company"
self.name = "heikki"
heikki_target = Target(
description = "my com server desc",
modules = ["heikki"],
create_exe = False,
create_dll = True
)
setup(
version = "1.0",
zipfile=None,
description = "my com server",
name = "heikki",
author="Heikki",
com_server = [heikki_target],
)
Then I create a DLL:
c:\temp> python setup.py py2exe
However, this caused an error message:
The following modules appear to be missing
['win32com.gen_py', 'win32com.shell', 'win32com.shell.shell']
Which I partially fixed by adding the following to my script setup:
import sys
if 1:
try:
import py2exe.mf as modulefinder
except ImportError:
import modulefinder
import win32com
for p in win32com.__path__[1:]:
modulefinder.AddPackagePath("win32com", p)
for extra in ["win32com.shell"]:
__import__(extra)
m = sys.modules[extra]
for p in m.__path__[1:]:
modulefinder.AddPackagePath(extra, p)
:
The following modules appear to be missing
['win32com.gen_py']
, , . :
07/13/2009 05:24 PM 3,072 API-MS-Win-Core-ErrorHandling-L1-1-0.dll
07/13/2009 05:24 PM 3,584 API-MS-Win-Core-LibraryLoader-L1-1-0.dll
07/13/2009 05:24 PM 4,096 API-MS-Win-Core-LocalRegistry-L1-1-0.dll
07/13/2009 05:24 PM 3,584 API-MS-Win-Core-Misc-L1-1-0.dll
07/13/2009 05:24 PM 4,608 API-MS-Win-Core-ProcessThreads-L1-1-0.dll
07/13/2009 05:24 PM 3,072 API-MS-Win-Core-Profile-L1-1-0.dll
07/13/2009 05:24 PM 4,096 API-MS-Win-Core-Synch-L1-1-0.dll
07/13/2009 05:24 PM 4,096 API-MS-Win-Core-SysInfo-L1-1-0.dll
07/13/2009 05:24 PM 6,144 API-MS-Win-Security-Base-L1-1-0.dll
11/27/2010 05:19 PM 80,384 bz2.pyd
07/13/2009 05:40 PM 207,360 CFGMGR32.dll
07/13/2009 05:40 PM 93,184 DEVOBJ.dll
01/06/2011 12:07 PM 2,363,665 heikki.dll
07/13/2009 05:41 PM 421,376 KERNELBASE.dll
11/06/2007 03:02 PM 1,671,160 mfc90.dll
07/13/2009 05:41 PM 167,424 POWRPROF.dll
11/27/2010 05:19 PM 2,978,816 python27.dll
07/05/2009 04:56 AM 489,984 pythoncom27.dll
07/05/2009 04:54 AM 138,240 pywintypes27.dll
11/27/2010 05:19 PM 10,752 select.pyd
07/13/2009 05:41 PM 1,899,520 SETUPAPI.dll
11/27/2010 05:19 PM 689,664 unicodedata.pyd
07/05/2009 04:55 AM 125,440 win32api.pyd
07/05/2009 04:58 AM 354,816 win32com.shell.shell.pyd
07/05/2009 04:54 AM 21,504 win32event.pyd
07/05/2009 04:54 AM 44,032 win32process.pyd
07/05/2009 04:54 AM 18,432 win32trace.pyd
07/05/2009 05:00 AM 1,034,752 win32ui.pyd
07/05/2009 04:55 AM 236,544 winxpgui.pyd
11/27/2010 05:22 PM 471,552 _hashlib.pyd
07/05/2009 04:54 AM 9,216 _win32sysloader.pyd
, DLL:
c:\temp\dist> regsvr32 heikki.dll
, :
The module "heikki.dll" was loaded but the call to
DllRegisterServer failed with error code 0x80040201
MS KB:
There was an error when regsvr32.exe invoked the entrypoint in the module specified in the command line.
Dependency Walker, 2 heikki.dll:
IEFRAME.DLL
SHLWAPI.DLL
, , , :
Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module.
Dependency Walker regsrv32; regsvr32 . heikki.dll :
<empty string>
ZLIB.PYD
ieshims.dll, Internet Explorer PATH DLL . < empty string > :
which means GetProcAddress was called with an empty string
, zlib.pyd , zlib.pyd, , AFAIK. zlib1.dll zlib.pyd , DDL, pyd, (initzlib -, ).
gen_py py2exe . setup.py, heikki.py, .
.