Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C# COM
Hey...
 
I ran into this and was wondering if somebody has an answer for it.
 
I created a C# COM object and was trying to QI for the custom interface.
 
Here is the C# COM code:
 
 
public interface IiAddin 
{
  long Initialize(Object app);
  long Uninitialize();
}
namespace TEST_CSharpAddin
{
  [Guid("F8C17785-DB6D-4982-9D68-CA8FF6DC785A")]
  public interface CSharpAddin_Interface : IiAddin {
  }
  
  [Guid("4ADEE107-3FE3-4037-9463-FE7E94D9D544"),
      InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
  public interface CSharpAddin_Events {
  }
    [Guid("70FD2E39-D014-4064-9A7C-8C4DA743257F"),
        ClassInterface(ClassInterfaceType.None),
        ComSourceInterfaces(typeof(CSharpAddin_Events))]
  public class CSharpAddin : CSharpAddin_Interface
  {
      public long Initialize(Object app){
        return 0;
      }
      public long Uninitialize(){
        return 0;
      }
  }
}
 
( yes the project has "Make assembly COM-Visible" and "Register for COM interop" set in the project settings )
 
( and I have added "COMVisible(true)" to all of the interfaces as well, with no success either)
 

Here is the C++ code that does the QI for the interface:
 
  HRESULT hResult;
  CLSID ClassID;
  hResult = CLSIDFromProgID(_T("TEST_CSharpAddin.CSharpAddin"), &ClassID);
  IDispatch *pDispatch;
  hResult = ::CoCreateInstance(ClassID, NULL, CLSCTX_INPROC_SERVER, IID_IDispatch, (void **)&pDispatch);
  CComQIPtr<IiAddin> spAddIn(pDispatch);  // << FAILS >>
  
  // So I tried this instead:
  IiAddin* pQIAddIn;
  hResult = pDispatch->QueryInterface( IID_IiAddin, (void**)&pQIAddIn);  // << FAILS >>
 

 
I did the strong name, put it in the GAC and registered the typelib on the C# object, like this article suggests:
 

Calling Managed .NET C# COM Objects from Unmanaged C++ Code[^]
 

However, when I run the C++ code , the CLSIDFromProgID and CoCreateInstance succeed, but the QI for IiAddin fails with 0x80040154 ( class not registered )
 

Any ideas?
Posted 8-Oct-13 4:24am
Edited 8-Oct-13 4:38am
v3
Comments
cariolihome at 8-Oct-13 17:33pm
   
Please, specify value of IID_IiAddin constant, and attach tlb library

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 735
1 OriginalGriff 385
2 CPallini 240
3 PIEBALDconsult 150
4 Magic Wonder 131
0 OriginalGriff 5,835
1 Sergey Alexandrovich Kryukov 5,198
2 CPallini 4,740
3 George Jonsson 3,167
4 Gihan Liyanage 2,470


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 8 Oct 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100