The problem is, I have a DLL and TLB that I created in C#.NET, made it COM visible and wanted to expose the functions to my MFC C++ project – I made a test class first and it worked correctly, and didn’t get any errors from C++’s generated tlh. Now the actual DLL I want to use is giving me the following compilation errors:
error C2059: syntax error : '<'
error C2238: unexpected token(s) preceding ';'
error C2059: syntax error : '<'
error C2238: unexpected token(s) preceding ';'
error C2059: syntax error : '<'
error C2238: unexpected token(s) preceding ';'
From the following C++ generated tlh file:
//
// Type library items
//
struct __declspec(uuid("d6b19eb0-56bf-3c30-9f3a-ebafca303996"))
Class1;
// [ default ] interface _Class1
// interface _Object
struct __declspec(uuid("a7e7ae20-5fb3-3c3f-a9fb-1fac0128dea1"))
IProtracReader : IDispatch
{}
struct TagReadEvent
{
__int64 <Index>k__BackingField; <<< These three lines are where the errors are.
__int64 <TagID>k__BackingField;
DATE <EventMoment>k__BackingField;
};
Does anyone know why the compiler is generating this file thats giving me errors? Any help is GREATLY appreciated!
These are fields that are generated by the C# compiler when you use automatic properties. Like:
You ought to go back and fix the C# code. Also use interfaces and keep classes/structs as [ClassInterface(ClassInterfaceType.None)] so that none of the implementation is exposed. The COM way. If you can’t then you can use the exclude attribute in the #import directive to skip the troublemakers. Like:
The rename attribute can fix it too.