【问题标题】:win32client dispatch fails in python while win32::ole new runs successfully in perl for a com dllwin32client 调度在 python 中失败,而 win32::ole new 在 perl 中成功运行 com dll
【发布时间】:2018-02-27 11:53:43
【问题描述】:

我有一个用 C# 实现的 com dll,并通过 regasm 注册。 当我尝试通过

在 python 中获取此 dll 的句柄时
handle = win32com.client.Dispatch('{EC456B4B-5AC4-46E8-99E8-54C193C316BC}')

handle = win32com.client.Dispatch('MyCOMdll')

失败并出现错误:(-2147221164, 'Class not registered', None, None)

虽然这在我使用的 perl 脚本中有效

my $handle = Win32::OLE->new('MyCOMdll');

my $handle = Win32::OLE->new('{EC456B4B-5AC4-46E8-99E8-54C193C316BC}');

同时 win32com.client.Dispatch 对 COM exe 对象运行良好。

我将 win32.comclient 用于 COM dll 的方式是否正确?


[更新01]

正在运行的perl代码

use Win32::OLE;
my $handle = Win32::OLE->new('MyCOMdll');
# my $handle = Win32::OLE->new('{EC456B4B-5AC4-46E8-99E8-54C193C316BC}');
my $result = Win32::OLE->LastError();
if ($result != 0)
{
    print("OLE Error: ",$result,"/n");
    die "";
}
else
{
    print("OLE Success!!/n");
}
exit 0;

仅适用于 COM exe 而不适用于 COM dll 的 Python 代码

import win32com.client

try:
    handle = win32com.client.Dispatch('MyCOMdll')
    # handle = win32com.client.Dispatch('{EC456B4B-5AC4-46E8-99E8-54C193C316BC}')
except Exception as ex:
    handle = None
    print(ex)

【问题讨论】:

  • 闻起来像 32/64 位问题。确保您的客户端与 COM dll 具有相同的位数
  • @SimonMourier: 2.7.12 [MSC v.1500 32 bit (Intel)] 是python版本,v5.14.4 MSWin32-x86-multi-thread 是 perl 版本,COM dll 是为 Visual Studio 中的 x86 目标构建的
  • @SimonMourier:看起来像是 32 位和 64 位的问题。我删除了以前的注册并重新注册并尝试使用 32 位 python,现在错误不同(OLE 错误 0x80131534:猜测依赖项有问题)

标签: python perl com win32com win32ole


【解决方案1】:

这是一个 32 位/64 位的问题。使用32位python版本后,问题解决。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多