2011-01-06 133 views
1

我想創建一個簡單的COM服務器在64位Windows 7上使用Python 2.7,但我無法獲得DLL註冊成功。我能夠在32位Windows XP上使用Python 2.6成功完成此操作。我也可以直接從Python註冊我的課程。Python 64位DLL COM服務器註冊問題在64位Windows 7

這是我的模塊,heikki.py,基於所述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有64位的Python 2.7.1,pywin32 214,py2exe 0.6.9,C:\ python27是在PATH):

C:\temp> python heikki.py 
Registered : Heikki.TestServer 

C:\temp> python heikki.py --unregister 
Unregistered : Heikki.TestServer 

我然後創建基於一個py2exe COM server sample一個setup.py文件在C:\ TEMP:

from distutils.core import setup 
import py2exe 

class Target: 
    def __init__(self, **kw): 
     self.__dict__.update(kw) 
     # for the version info resources (Properties -- Version) 
     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", 
    # use module name for win32com exe/dll server 
    modules = ["heikki"], 
    # specify which type of com server you want (exe and/or dll) 
    create_exe = False, 
    create_dll = True 
    ) 

setup(
    version = "1.0", 
    zipfile=None, 
    description = "my com server", 
    name = "heikki", 
    author="Heikki", 
    com_server = [heikki_target], 
    ) 

我然後創建DLL:

c:\temp> python setup.py py2exe 

然而,這引起了錯誤消息:

The following modules appear to be missing 
['win32com.gen_py', 'win32com.shell', 'win32com.shell.shell'] 

這一點我部分地通過預先下面的安裝腳本固定:

進口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) 

但我還是g et:

The following modules appear to be missing 
['win32com.gen_py'] 

我讀過,在某些情況下,這個錯誤可以忽略,所以我按下了。在這一點上我DIST目錄看起來是這樣的:

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. 

然後我在regsrv32上使用Dependency Walker;只是打開regsvr32給相同的文件發出警告。剖析heikki.dll給了錯誤的:

<empty string> 
ZLIB.PYD 

在某些attemps我也得到了ieshims.dll錯誤,但我加入了Internet Explorer的目錄到PATH和複製的DLL到dist,掠走了這個錯誤。依賴沃克說,這對<空字符串>error

which means GetProcAddress was called with an empty string 

我也希望zlib.pyd錯誤是無害的,因爲應該有zlib.pyd不再需要考慮到它應該內置據我所知。我嘗試將zlib1.dll作爲zlib.pyd放入我的遠程目錄中,但是當它擺脫DDL導入錯誤時,還有另一個關於沒有預期入口點的pyd文件(initzlib或其他東西,忘記了)的錯誤。

我還沒有能夠擺脫py2exe中的gen_py警告在我嘗試。我已經嘗試過對setup.py文件以及heikki.py模塊的各種調整,但沒有成功。

在這一點上,我已經沒有什麼想法了。

回答

2

這看起來像是Com server build using Python on 64-bit Windows 7 machine的副本。

將「import win32traceutil」添加到heikki.py的頂部,並在第二個Python進程中運行C:\ Python27 \ Lib \ site-packages \ win32 \ lib \ win32traceutil.py,以查看heikki.dll的回溯:

Traceback (most recent call last): 
    File "boot_com_servers.py", line 37, in <module> 
pywintypes.error: (126, 'GetModuleFileName', 'The specified module could not be found.') 
Traceback (most recent call last): 
    File "<string>", line 1, in <module> 
NameError: name 'DllRegisterServer' is not defined 

更新:

有64位的Python在py2exe的錯誤。由py2exe初始化的sys.frozendllhandle無效,導致win32api.GetModuleFileName(sys.frozendllhandle)失敗。

你可能想嘗試修補py2exe安裝在http://www.lfd.uci.edu/~gohlke/pythonlibs/#py2exe

+0

嗯,是的。更簡單的設置,但最終同樣的問題。但仍然沒有解決方案... – 2011-01-06 22:06:59