MaLe
MaLe

Reputation: 33

Compiler Error C3646 'unknown override specifier' in auto generated .tlh when using importlib in idl

I use Visual Studio 2015 and I have a C# Application-Project that defines a COM-Interface and generates a .tlb file on compilation. Now I want to import that Csharp.tlb into an idl.

MyLibrary.idl:

import "oaidl.idl";
import "ocidl.idl";
import "Cplusplus.idl";

library MyLibrary
{
  importlib("stdole32.tlb");
  importlib("stdole2.tlb");
  importlib("Csharp.tlb");

  interface IMyCOM : IDispatch
  {
    [propget, id(1)]
    HRESULT CpluplusObject
    (
      [out,retval] ICplusplusObject** cplusplusObject
    );

    [propget, id(2)]
    HRESULT CsharpObject
    (
      [out, retval] ICsharpObject** csharpObject
    );
  }

  coclass MyCOM
  {
    [default] interface IMyCOM;
  };
}

During compilation I get an error

C3646 'csharpObject': unknown override specifier in MyLibrary.tlh

MyLibrary.tlh was auto generated by the compilation and looks as the following

MyLibrary.tlh:

#pragma once
#pragma pack(push, 8)

#include <comdef.h>

namespace MyLibrary {

  struct __declspec(uuid("8e664998-bc93-48e7-adcc-84fc8598cd5d"))
  /* dual interface */ ICplusplusObject;

  _COM_SMARTPTR_TYPEDEF(ICplusplusObject, __uuidof(ICplusplusObject));

  struct __declspec(uuid("388ebf11-05c8-4b86-b2bd-60f0ef38695e"))
  IMyLibrary : IDispatch
  {
    __declspec(property(get=GetCplusplusObject))
    ICplusplusObjectPtr cplusplusObject;
    __declspec(property(get=GetCsharpObject))
    ICsharpObjectPtr csharpObject;

    ICplusplusObjectPtr GetCplusplusObject ( );
    ICsharpObjectPtr GetCsharpObject ( );

    virtual HRESULT __stdcall get_CplusplusObject (
      /*[out,retval]*/ struct ICplusplusObject * * cplusplusObject ) = 0;
    virtual HRESULT __stdcall get_CsharpObject (
      /*[out,retval]*/ struct ICsharpObject * * csharpObject ) = 0;
  }

  __declspec(implementation_key(1)) ICplusplusObjectPtr IMyLibrary::GetcplusplusObject ( );
  __declspec(implementation_key(2)) ICsharpObjectPtr IMyLibrary::GetcsharpObject ( );
}

The error means that ICsharpObjectPtr or ICsharpObject respectively is not known which I understand so far. ICplusplusObjectPtr is known because import "ICplusplus.idl" added the definitions into the .tlh and importlib("ICsharp.tlb"); did not obviously.

For Test reasons I generated the ICsharp.idl out of the .tlb by using OLE/COM Object Viewer and made an import of that idl. The error was gone after that.

But why does the importlib of the .tlb not work directly? I do not want to generate an idl file every time out of the .tlb.

I think that there is an #include "ICsharp.tlh" missing or something to make the type known for the .tlh. But how to tell the idl or the compiler to properly reference the ICsharpObject?

Thank you so much in advance for your help.

Upvotes: 1

Views: 2459

Answers (1)

MaLe
MaLe

Reputation: 33

This is an error due to wrong order of tlb-imports. The #import directive tries to generate the primary (.tlh) and secondary (.tli) header files on compilation. If a tlb uses a type of another typelib which was not imported first this error will occur. In this case the following solved the error

Importer.cpp

#import "CplusplusLibrary.tlb"
#import "CsharpLibrary.tlb"
#import "MyLibrary.tlb"

Thank you so much Igor.

Upvotes: 1

Related Questions