[英]win32client dispatch fails in python while win32::ole new runs successfully in perl for a com dll
I have a com dll implemented in C# and is registered via regasm. 我有一个用C#实现的com dll,并且通过regasm注册。 When I try to get a handle to this dll in python via 当我尝试通过python获取此dll的句柄时
handle = win32com.client.Dispatch('{EC456B4B-5AC4-46E8-99E8-54C193C316BC}')
or 要么
handle = win32com.client.Dispatch('MyCOMdll')
it fails with an error: (-2147221164, 'Class not registered', None, None) 它失败并显示错误:(-2147221164,“类未注册”,无,无)
while this works in the perl script where I use 虽然这在我使用的perl脚本中有效
my $handle = Win32::OLE->new('MyCOMdll');
or 要么
my $handle = Win32::OLE->new('{EC456B4B-5AC4-46E8-99E8-54C193C316BC}');
Meanwhile win32com.client.Dispatch is working good for the COM exe objects. 同时,win32com.client.Dispatch对于COM exe对象运行良好。
Is the way I am using the win32.comclient for COM dlls correct ? 我将win32.comclient用于COM dll的方式正确吗?
[update 01] [更新01]
perl code which is working 运行的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;
Python code which works only for COM exe and not for COM dlls 仅适用于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)
It was a 32 bit/ 64 bit problem. 这是一个32位/ 64位问题。 After using a 32 bit python version, the issue was resolved. 使用32位python版本后,此问题已解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.