简体   繁体   English

如何注册 64 位 python COM 服务器

[英]how to register a 64bit python COM server

ahk code: ComObjCreate("{C2474B5A-5E9D-484D-BDFD-20A100183426}") ahk 代码: ComObjCreate("{C2474B5A-5E9D-484D-BDFD-20A100183426}")

this works in AutoHotkeyU32.exe, but not in AutoHotkeyU64.exe这适用于 AutoHotkeyU32.exe,但不适用于 AutoHotkeyU64.exe
error message is: the specified module could not be found.错误信息是: the specified module could not be found.

full code is here: How to program hotstrings in python like in autohotkey完整代码在这里: How to program hotstrings in python like in autohotkey


I call my SymPy functions using ahk hotkeys. 我使用 ahk 热键调用我的 SymPy 函数。 I register the python script as a COM server using pywin32 and load it using ahk. 我使用 pywin32 将 python 脚本注册为 COM 服务器并使用 ahk 加载它。

you'll need pywin32, but don't download using pip install pywin32您需要 pywin32,但不要使用pip install pywin32
download from https://github.com/mhammond/pywin32/releaseshttps 下载://github.com/mhammond/pywin32/releases
OR ELSE IT WON'T WORK for AutoHotkeyU64.exe, it will only work for AutoHotkeyU32.exe.否则它对 AutoHotkeyU64.exe 不起作用,它只对 AutoHotkeyU32.exe 起作用。
make sure to download amd64, (I downloaded pywin32-300.win-amd64-py3.8.exe)确保下载amd64,(我下载了pywin32-300.win-amd64-py3.8.exe)

EDIT: now I understand why it didn't work编辑:现在我明白为什么它不起作用
I think it CAN work when using pip install pywin32 if you register it correctly.如果您正确注册,我认为它可以在使用pip install pywin32时工作。
you have 2 choices:你有2个选择:

  1. register it correctly as shown here How to program hotstrings in python like in autohotkey :正确注册它,如下所示如何在 python 中编程热字串,如在 autohotkey 中
    do NOT use UseCommandLine() , use RegisterServer(clsctx=pythoncom.CLSCTX_LOCAL_SERVER, ...)不要使用UseCommandLine() ,使用RegisterServer(clsctx=pythoncom.CLSCTX_LOCAL_SERVER, ...)
  2. after server has been registed using UseCommandLine() , delete the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{C70F3BF7-2947-4F87-B31E-9F5B8B13D24F}\PythonCOMPath\InprocServer32使用UseCommandLine()注册服务器后,删除注册表项HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{C70F3BF7-2947-4F87-B31E-9F5B8B13D24F}\PythonCOMPath\InprocServer32

    replace {C70F3BF7-2947-4F87-B31E-9F5B8B13D24F} with your own CLSID用您自己的CLSID替换{C70F3BF7-2947-4F87-B31E-9F5B8B13D24F}

(I think) there is no need for (我认为)没有必要
key: InprocServer32 :键: InprocServer32
Name : (Default) Name :( (Default)
Type : REG_EXPAND_SZ TypeREG_EXPAND_SZ
Data : pythoncom39.dll , Datapythoncom39.dll
also, requiring it makes it fail另外,要求它会失败

(I think) There's no need because it actually uses LocalServer32 (which is also a key) (我认为)没有必要,因为它实际上使用 LocalServer32 (这也是一个关键)
mine is:我的是:
Name : (Default) Name :( (Default)
Type : REG_SZ TypeREG_SZ
Data : C:\PROGRA~3\Miniconda3\pythonw.exe "C:\ProgramData\Miniconda3\lib\site-packages\win32com\server\localserver.py" {C70F3BF7-2947-4F87-B31E-9F5B8B13D24F} DataC:\PROGRA~3\Miniconda3\pythonw.exe "C:\ProgramData\Miniconda3\lib\site-packages\win32com\server\localserver.py" {C70F3BF7-2947-4F87-B31E-9F5B8B13D24F}

localserver.py is the one doing the COM stuff, to prove it, replace pythonw with python . localserver.py是做 COM 东西的人,为了证明这一点,将pythonw替换为python you will the window when it's ran.当它运行时,你会得到 window。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM