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.
library
block. That doesn't make any sense. Methods, naturally, must be part of an interface. – Igor Tandetnikauto_search
attribute with your#import
directive. Or else explicitly#import
Csharp.tlb first. – Igor Tandetnik#import
statement in your C++ code. Are you saying you don't have such a statement? With all due respect, I find it difficult to believe. – Igor Tandetnik