C#wrapper接口错误:E_NOINTERFACE [英] C# wrapper interface error: E_NOINTERFACE
问题描述
我试图为我有一个COM对象(名为SC_COM.dll)生成一个C#包装,但我有一些问题链接到Visual Studio 2008(运行Vista)。我需要做这个免注册COM DLL - 我使用清单文件让Visual Studio知道SC_COM.dll,这似乎是工作。我使用TblImp.exe生成一个类型库(SC_COMtlb.dll),我在Visual Studio 2008中引用,所以我可以做早期绑定与我需要的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 '。此操作失败,因为COM组件上的QueryInterface调用与IID'{C677308A-AC0F-427D-889A-47E5DC990138}'的接口失败,原因是以下错误:不支持此类接口(来自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?
我应该注意到,我不是完全确定如何生成的类型库(S \C_COMtlb.dll)知道实际的COM DLL的位置,因为它没有注册到系统 - 我认为它只是看起来在同一个目录。
I should probably note that I'm not entirely sure how the type library (S\C_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?
推荐答案
尝试将此添加到您的应用程序中.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}" />
其中TLBID可以从Visual Studio生成的Native.Namespace.Assembly.Name.manifest找到,像这样:
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:
- Why do I get E_NOINTERFACE when creating an object that supports that interface?
- Registration-Free Skype4Com and multithreaded apartment
- Registration-Free Activation of COM Components: A Walkthrough
这篇关于C#wrapper接口错误:E_NOINTERFACE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!