I have a com dll implemented in C# and is registered via regasm. When I try to get a handle to this dll in python via
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)
while this works in the perl script where I use
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.
Is the way I am using the win32.comclient for COM dlls correct ?
[update 01]
perl code which is working
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
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. After using a 32 bit python version, the issue was resolved.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.