我需要在我的python项目中使用COM dll(由CSharp制造)。我尝试遵循此示例,在脚本语言中使用COM对象-第2部分(Python),但没有成功。
我的python代码是:
import sys
# for TkInter GUI support
from Tkinter import *
import tkMessageBox
import tkColorChooser
# for COM support
import comtypes.client as cc
import comtypes
# Load the typelibrary registered with the Windows registry
tlb_id = comtypes.GUID("{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}")
cc.GetModule((tlb_id, 1, 0))
当我运行python类时,会发生此错误:
> Traceback (most recent call last): File "C:\Program Files
> (x86)\JetBrains\PyCharm 129.696\helpers\pydev\pydevd.py", line 1481,
> in <module>
> debugger.run(setup['file'], None, None) File "C:\Program Files (x86)\JetBrains\PyCharm 129.696\helpers\pydev\pydevd.py", line 1124,
> in run
> pydev_imports.execfile(file, globals, locals) #execute the script File "C:/aa_python/gtk_project/main.py", line 7, in <module>
> from com_class_file import ComClass File "C:/aa_python/gtk_project\com_class_file.py", line 15, in <module>
> cc.GetModule((tlb_id, 1, 0)) File "C:\Python27\lib\site-packages\comtypes-1.1.0-py2.7.egg\comtypes\client\_generate.py",
> line 101, in GetModule
> tlib = comtypes.typeinfo.LoadRegTypeLib(comtypes.GUID(tlib[0]), *tlib[1:]) File "C:\Python27\lib\site-packages\comtypes-1.1.0-py2.7.egg\comtypes\typeinfo.py",
> line 473, in LoadRegTypeLib
> _oleaut32.LoadRegTypeLib(byref(GUID(guid)), wMajorVerNum, wMinorVerNum, lcid, byref(tlib)) File "_ctypes/callproc.c", line
> 945, in GetResult WindowsError: [Error -2147319779] Library not registered
错误行:
cc.GetModule((tlb_id, 1, 0))
在我的CSharp项目中,我的COM dll中包含以下代码:
界面
[InterfaceType(ComInterfaceType.InterfaceIsDual), Guid("YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY")]
public interface ITestCOM
{
string say_hello();
}
班级
[ClassInterface(ClassInterfaceType.None), Guid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")]
public class TestCOM : ITestCOM
{
public string say_hello()
{
return "hello world!";
}
}
上面的COM项目已在其他应用程序中使用,并且工作正常。我的问题仅在python中。
及时:我的COM dll已在Windows注册表中注册
有帮助吗?
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句