1

64 ビット Windows 7 で Python 2.7 を使用して単純な COM サーバーを作成しようとしていますが、DLL を正常に登録できません。32 ビット Windows XP で Python 2.6 を使用すると、これを正常に実行できます。クラスを Python から直接登録することもできます。

これは、 pywin32 COM チュートリアルに基づいた私のモジュール heikki.py です。

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)

次のようにコマンドラインから正常に登録できます(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

次に、c:\tempにあるpy2exe COM サーバー サンプルに基づいて setup.py ファイルを作成しました。

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']

セットアップ スクリプトの先頭に以下を追加することで部分的に修正しました。

システムをインポート

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']

場合によってはこのエラーを無視できることを読んだので、先に進みました。この時点で、私の dist dir は次のようになります。

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.

次に、heikki.dll に対して 2 つの警告を表示するDependency Walkerに目を向けます。

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

いくつかの試行で、ieshims.dll のエラーも発生しましたが、Internet Explorer dir を PATH に追加し、DLL を dist にコピーして、そのエラーを回避しました。Dependency Walker は <empty string>エラーについて次のように述べています。

which means GetProcAddress was called with an empty string

zlib.pydエラーが無害であることも願っています.zlib.pydが組み込まれている必要があるため、zlib.pydはこれ以上必要ないはずです。zlib1.dll を zlib.pyd として dist dir にドロップしようとしましたが、これにより DDL インポート エラーが取り除かれますが、pyd ファイルに予期されるエントリ ポイントがないという別のエラーが発生します (initzlib など、忘れてしまいました)。

私の試みでも、py2exeからのgen_py警告を取り除くことができませんでした。setup.py ファイルと heikki.py モジュールにさまざまな調整を試みましたが、成功しませんでした。

この時点で、検討するアイデアが不足しています。

4

1 に答える 1

2

これは、64ビットWindows7マシンでPythonを使用して構築されたComサーバーの複製のように見えます。

heikki.pyの先頭に「importwin32traceutil」を追加し、2番目の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)が失敗します。

http://www.lfd.uci.edu/~gohlke/pythonlibs/#py2exeでパッチを適用したpy2exeインストーラーを試してみることをお勧めします

于 2011-01-06T21:46:11.030 に答える