C# 包装器接口错误:E_NOINTERFACE [英] C# wrapper interface error: E_NOINTERFACE

查看:20
本文介绍了C# 包装器接口错误:E_NOINTERFACE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我拥有的 COM 对象(名为 SC_COM.dll)生成 C# 包装器,但在将其与 Visual Studio 2008(运行 Vista)链接时遇到了一些问题.我需要使用 COM DLL 进行无需注册的操作——我正在使用清单文件让 Visual Studio 知道 SC_COM.dll,这似乎可以正常工作.我使用 TblImp.exe 生成了我在 Visual Studio 2008 中引用的类型库 (SC_COMtlb.dll),因此我可以与我需要的 DLL 进行早期绑定.DLL 都与清单和可执行文件位于同一目录中.

I am trying to produce a C# wrapper for a COM object that I have (named SC_COM.dll), but am having some issues linking it with Visual Studio 2008 (running Vista). I need to do this registration-free with the COM DLL--I'm using a manifest file to let Visual Studio know about SC_COM.dll, and that appears to be working. I used TblImp.exe to generate a type library (SC_COMtlb.dll) that I'm referencing in Visual Studio 2008 so I can do early binding with the DLL that I need. The DLLs are both in the same directory as the manifest and the executable.

问题是:当我实例化对象并尝试在 C# 中调用其方法之一时,它会引发以下错误:

Here's the issue: When I instantiate the object and try and call one of its methods in C#, it throws the following error:

检测到错误:无法将SC_COMtlb.SCAccessObjClass"类型的 COM 对象转换为接口类型SC_COMtlb.ISCUploader".此操作失败,因为 IID 为{C677308A-AC0F-427D-889A-47E5DC990138}"的接口的 COM 组件上的 QueryInterface 调用因以下错误而失败:不支持此类接口(来自 HRESULT 的异常:0x80004002 (E_NOINTERFACE)).

Error detected: Unable to cast COM object of type 'SC_COMtlb.SCAccessObjClass' to interface type 'SC_COMtlb.ISCUploader'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{C677308A-AC0F-427D-889A-47E5DC990138}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

我不完全确定这个错误是什么意思——我已经对错误代码进行了搜索,它似乎是一个相对普遍的 C# 错误.那么我是要在这里以错误的方式链接 COM 对象,还是我可能遗漏了其他一些重要步骤?

I'm not entirely certain what this error means--I've done a search on the error code, and it appears to be a relatively general C# error. So am I going about linking the COM object the wrong way here, or is there some other important step I may be missing?

我可能应该注意到,我不完全确定我生成的类型库 (SC_COMtlb.dll) 如何知道实际的 COM DLL 在哪里,因为它没有在系统中注册——我假设它只是看起来在同一目录中.这可能是问题所在吗?如果是,我怎样才能更好地将两者联系起来?

I should probably note that I'm not entirely sure how the type library (SC_COMtlb.dll) that I produced knows where the actual COM DLL is, since it's not registered with the system--I assume it just looks in the same directory. Could this potentially be the issue, and if so, how can I better link the two?

推荐答案

尝试将此添加到您的 App.exe.manifest:

Try adding this to your App.exe.manifest:

<comInterfaceExternalProxyStub 
  name="ISCUploader" 
  iid="{C677308A-AC0F-427D-889A-47E5DC990138}"
  proxyStubClsid32="{00020424-0000-0000-C000-000000000046}"
  baseInterface="{00000000-0000-0000-C000-000000000046}"
  tlbid = "{PUT-YOUR-TLB-GUID-HERE}" />

可以从 Visual Studio 生成的 Native.Namespace.Assembly.Name.manifest 中找到 TLBID,如下所示:

Where TLBID can be found from your Visual Studio generated Native.Namespace.Assembly.Name.manifest, looking like this:

<typelib tlbid="{A-GUID-IS-HERE--USE-IT}"
  version="1.0" helpdir="" resourceid="0" flags="HASDISKIMAGE" />

我为此纠结了很长时间,但我找到了这些有用的参考资料并将其拼凑在一起,它对我有用:

I was banging my head against this for quite some time, but I found these helpful references and pieced it together and it's working for me:

这篇关于C# 包装器接口错误:E_NOINTERFACE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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