简体   繁体   English

在.NET应用程序中使用免费注册com

[英]Using registration free com in a .NET app

I'm trying to use a 3rd party COM DLL (I don't believe its a .NET component) from a .NET service without registering the COM DLL but I'm having no luck so far. 我试图从.NET服务使用第三方COM DLL(我不相信它的.NET组件)而没有注册COM DLL,但到目前为止我没有运气。

I've copied the manifest files from here (http://stackoverflow.com/questions/465882/generate-manifest-files-for-registration-free-com) to use as a starting point (I generated the COM DLL manifest using the referenced mt.exe/regsvr42.exe). 我已经从这里复制了清单文件(http://stackoverflow.com/questions/465882/generate-manifest-files-for-registration-free-com)以作为起点使用(我使用生成的COM DLL清单)引用的mt.exe / regsvr42.exe)。 However all I get is the following error: 但是我得到的是以下错误:

Exception: System.InvalidCastException Message: Unable to cast COM object of type 'LOGICLib.LogicClass' to interface type 'LOGICLib.ILogic'. 异常:System.InvalidCastException消息:无法将类型为“LOGICLib.LogicClass”的COM对象强制转换为接口类型“LOGICLib.ILogic”。 This operation failed because the QueryInterface call on the COM component for the interface with IID '{AAAAAAAA-AAAA-AAAA-AAAA-AAAAAA3E8FB4}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)). 此操作失败,因为由于以下错误,对IID为“{AAAAAAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA-AAAA 。 Source: Interop.LOGICLib at LOGICLib.LogicSecuredClass.Connect(String IP, UInt16 Value, Int32& Result) at My.Server.MyAssembly.Loader.Connect() in D:\\MyProject\\Source\\Server\\MyAssembly\\Loader.cs:line 461 来源:Interop.LOGICLib at LOGICLib.LogicSecuredClass.Connect(String IP,UInt16 Value,Int32&Result)位于D:\\ MyProject \\ Source \\ Server \\ MyAssembly \\ Loader.cs中的My.Server.MyAssembly.Loader.Connect():行461

The application manifest is named after the exe that starts the service - I've also tried naming it after the assembly that calls the COM DLL. 应用程序清单以启动服务的exe命名 - 我也尝试在调用COM DLL的程序集之后命名它。 I've tried starting on the command line and via Visual Studio's debugger. 我试过在命令行和Visual Studio的调试器上启动。 I've also tried using the Interop file supplied by the third party and generating my own. 我也尝试使用第三方提供的Interop文件并生成自己的文件。

(Note - I've only tested under Windows XP so far.) (注意 - 到目前为止我只在Windows XP下测试过。)

I've spent two days on this now and have not progressed at all. 我现在花了两天时间在这上面并没有取得任何进展。 Any ideas what I may have missed? 我可能错过了什么想法?

The application manifest is named after the exe that starts the service 应用程序清单以启动服务的exe命名

Yes, this does not work. 是的,这不起作用。 Windows always looks for a manifest in the EXE itself, embedded as an unmanaged resource. Windows始终在EXE本身中查找清单,作为非托管资源嵌入。 Only when it cannot find one in there will it look for a .manifest file on disk. 只有当它找不到那个时才会在磁盘上查找.manifest文件。 Problem is, a managed program built with VS2008 and up already has a manifest. 问题是,使用VS2008构建的托管程序已经有了清单。 The default one says "I'm Vista aware" only. 默认的只有“我知道Vista”。

You can verify this for yourself by using File + Open + File and selecting your EXE. 您可以使用File + Open + File并选择您的EXE来自行验证。 Open the RT_MANIFEST node and double-click resource 1. If you don't see your reg-free COM manifest entries there then it isn't going to work. 打开RT_MANIFEST节点,然后双击资源1.如果没有看到您的免注册COM清单条目,那么它将不起作用。

To fix, use Project + Add New Item and select the Application Manifest File item template. 要修复,请使用Project + Add New Item并选择Application Manifest File项目模板。 You'll get the boilerplate manifest, copy and paste your regfree COM entries in there. 您将获得样板清单,在那里复制并粘贴您的regfree COM条目。

Well, from the exception, you're getting a cast error when trying to cast an object of type LogicClass to an interface type of ILogic. 好吧,从异常中,当您尝试将LogicClass类型的对象强制转换为ILogic的接口类型时,您会收到强制转换错误。 Looks like LogicClass doesn't implement ILogic. 看起来LogicClass没有实现ILogic。

You didn't supply what the DLL is or where you got it, so you're best bet is to look at the documentation for the library you're trying to use. 你没有提供DLL或你得到它的地方,所以你最好的办法是查看你想要使用的库的文档。 Just a wild guess, but it looks like you're implementing it incorrectly. 只是一个疯狂的猜测,但看起来你正在错误地实现它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以使用COM可见的.NET类与免注册COM? - Is it possible to use COM visible .NET classes with registration free COM? 使用托管应用程序中的本机注册免费C ++ COM服务器 - Using native registration free C++ COM server from managed app 使用免注册com激活(基于COM Interop的)ActiveX控制 - Activate a (COM Interop based) ActiveX contol using registration free com 如何在点网中使用免注册COM dll - How to use Registration free COM dll in dot net EXE免费注册COM错误 - Registration Free COM errors with EXE 从.Net COM dll回拨到Delphi客户端,无需注册(并排)COM - Callback from .Net COM dll to Delphi client in registration-free (side-by-side) COM .NET Framework (v 4.0) COM 注册免费从 Win32 C++ 应用程序调用 - .NET Framework (v 4.0) COM Registration free called from Win32 C++ application 64位COM dll和C#/。Net应用程序之间的免注册互操作 - Registration-free Interop between a 64-bit COM dll and a C#/.Net application 免注册 COM 在本地机器上工作,但在 Azure 应用服务中抛出异常 - Registration-free COM works on a local machine, but throws exception in Azure App Service 免费注册COM Interop初始化-无参数构造函数 - Registration Free COM Interop Initialization - parameterless constructor
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM