使用从.net一个COM EXE内部类 [英] using classes inside a COM exe from .Net

查看:189
本文介绍了使用从.net一个COM EXE内部类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个exe文件我已经给它有COM类里面 - 这是从C ++,没有.NET 标记有ComVisible特性类型

I have a .exe file I've been given which has COM classes inside it -- these are from C++, not .net ComVisible types

我想使用这些类我的.NET项目里面,但我不能添加引用exe文件;当我尝试,我得到

I'd like to use those classes inside my .net project, but I can't add a reference to the exe; when I try I get

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 also fails;

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 蜂巢我可以看到不同的COM clasess条目;

But it really looks as if there are COM classes available; in my HKEY_CLASSES_ROOT hive I can see entries for the different COM clasess;

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"

任何人有一个如何,甚至是否我可以使用这些COM类从.NET项目中的线索?

Anyone got a clue about how, and even if, I can use these COM classes from within a .net project?

推荐答案

有分发类型库的三种方法:要么分别在.tlb文件,或者作为一个.dll或.exe文件中嵌入的资源。然而,它不是强制性的与COM组件分发类型库文件

There are three methods of distributing a type library: either separately in a .tlb file, or as an embedded resource inside a .dll or .exe file. However, it is not mandatory to distribute a type library file with a COM component.

一般在那里将是HKCR \ CLSID {CLSID}下方的类型库注册表项,这将具有包含类型库ID的默认值。 (OLEView.exe这类对跟踪这些注册表项非常有用)。如果你的注册表不包含类型库密钥,然后就是可能你的组件没有被带有一个类型库。

Usually the there would be a TypeLib registry key underneath the HKCR\CLSID{CLSID}, which would have a default value containing the typelib id. (oleview.exe is very useful for tracking down these registry entries). If your registry does not contain a TypeLib key, then is is likely that your component has not been distributed with a type library.

tlbimp.exe是可以导入任何嵌入的类型库资源,里面的.dll或.exe文件,因此它上面报告的错误指示,我认为有一个在您给出的可执行文件没有嵌入式类型库。您可以通过使用资源视图中查看该exe证实了这一点。我已经忘记了Windows SDK的资源浏览器的名字,但你可以在这里找到一个免费的:的 MITEC埃克浏览器

tlbimp.exe can import any embedded type library resources inside .dll or .exe files, so the error it is reporting above indicates to me that there is no embeded type library in your given executable. You can confirm this by viewing the exe using a resource view. I have forgotten the name of the Windows SDK resource viewer, but you can find a free one here: MiTec Exe Explorer

如果exe文件不具有类型库的资源,那么你就不能创建一个.NET互操作程序库。你唯一的选择就是再联系组件的制造商,并要求一个类型库。如果无法做到这一点,您可以使用后期绑定来调用组件。

If the exe does not have a resource of TYPELIB, then you cannot create a .net interop library. Your only option is then to contact the maker of the component and ask for a type lib. If this is not possible, you can use late binding to call the component.

这篇关于使用从.net一个COM EXE内部类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆