【发布时间】:2010-11-18 13:43:17
【问题描述】:
我有一个 .exe 文件,里面有 COM 类——这些来自 C++,而不是 .net ComVisible 类型
我想在我的 .net 项目中使用这些类,但我无法添加对 exe 的引用;当我尝试时,我得到了
DIALOG BOX:
---------------------------
Microsoft Visual Studio
---------------------------
A reference to 'C:\Program Files\blah\blah.exe'
could not be added. Please make sure that the
file is accessible, and that it is a valid
assembly or COM component.
---------------------------
OK
---------------------------
tlbimp 也失败了;
TLBIMP OUTPUT:
> tlbimp blah.exe
Microsoft (R) .NET Framework Type Library
to Assembly Converter 3.5.30729.1
Copyright (C) Microsoft Corporation. All rights reserved.
TlbIml : error TI0000 : The input file
'c:\program files\blah\blah.exe' is not
a valid type library
但看起来确实有可用的 COM 类;在我的HKEY_CLASSES_ROOT hive 中,我可以看到不同 COM 类的条目;
REGISTRY ENTRY:
\HKEY_CLASSES_ROOT
\CLSID
\{456B14EA-4CCC-11D4-BB91-0020AFC894E9}
@="COM.Classname"
\InprocHandler32
@="ole32.dll"
\LocalServer32
"LocalServer32"=hex(7) ...
@="C:\\PROGRA~2\\blah\blah.exe"
\ProgID
@="COM.Classname"
有人知道我如何,甚至是否可以在 .net 项目中使用这些 COM 类吗?
【问题讨论】:
-
后期绑定可能值得一试。不过,另一方面,
tlbimp正在告诉您问题所在。它是可执行文件,而不是类型库 (dll)。
标签: c# .net com com-interop tlbimp