C# wrapper interface error: E_NOINTERFACE

前端 未结 3 1785
忘了有多久
忘了有多久 2020-12-06 08:55

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

相关标签:
3条回答
  • 2020-12-06 09:10

    Which version of Windows? Since Windows Vista, an internal manifest overrides an external manifest. By default, C# executables have internal manifests, which means that your whatever.exe.manifest file will be ignored.

    If you go to the properties page for your C# EXE, you'll see there's an "Icon and manifest" section on the "Application tab". Set "Manifest" to the name of your manifest file, and it'll be embedded instead of the default one.

    If that doesn't work, you might have to do some post-build steps with MT.EXE in order to merge your external manifest with the default internal one and to put the merged manifest back into the .EXE file.

    0 讨论(0)
  • 2020-12-06 09:10

    the error code means that Visual Studio thinks that a certain object is supposed to implement a certain interface, but when I tries to "connect" to that interface the object responds that it doesn't know about it.

    I would guess that the problem is in SC_COM.dll. TLBIMP.EXE extracts class and interface information from metadata stored within the DLL and builds wrappers for the class.

    For example, if SC_COM is written in C++, this could happen if the creator of the DLL indicated in the IDL file that a class implements that interface, but the actual code doesn't support that interface.

    Here's another common source of problems this DLL might have: sometimes you have a class implementing an ISomething2 interface which derives from an ISomething interface, but the class implementation to only recognize ISomething2. If you implement a derived interface, you must recognize its base interface as well. This is a common mistake.

    Do you have (and control) the source code for the DLL?

    0 讨论(0)
  • 2020-12-06 09:12

    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}" />
    

    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
    0 讨论(0)
提交回复
热议问题