Going to answer my own question here. The mistake is you don't do that with the tlb, only the idl. The way to import it is with the #import directive, which seems to build just fine.
C# class library export as COM, errors during MIDL compilation.
I'm trying to create a COM library from a C# library I have. In order to do this I've defined my C# class as follows:
[Guid("830D0BFA-8045-455B-AAB7-2A7D4A16455C")]
[ComVisible(true)]
public interface IMyInterface
{
uint Start();
}
[Guid("22B91F20-1CC3-4276-BB51-0AE75D7DA5BB")]
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
public class MyInterface_Impl : IMyInterface, IDisposable
{
public uint Start()
{
return 0;
}
}
Additionally, I've enabled "Register for COM interop" in the project's build properties. The next step to allow a Win32 app (actually an MFC app) to use it is I think to generate a .tlb for the assembly. I'm doing this with the following post-build command:
"$(FrameworkSdkDir)\bin\NETFX 4.8 Tools\tlbexp.exe" "$(TargetFileName)" "$(TargetName).tlb" /win32
I see the .tlb in the build folder and then proceed to add it to the MFC project, right clicking it and setting it to Item Type: MIDL tool. When I then build this project, I get the following warnings and errors:
1>------ Build started: Project: My_Dll_Test_MFC, Configuration: Debug Win32 ------
1>Processing ..\My_Dll\bin\x86\Debug\My_Dll.tlb
1>My_Dll.tlb
1>..\My_Dll\bin\x86\Debug\My_Dll.tlb(1): warning C4335: Mac file format detected: please convert the source file to either DOS or UNIX format
1>..\My_Dll\bin\x86\Debug\My_Dll.tlb(1): error MIDL2025: syntax error : expecting an interface name or DispatchInterfaceName or CoclassName or ModuleName or LibraryName or ContractName or a type specification near "MSFT"
1>..\My_Dll\bin\x86\Debug\My_Dll.tlb(1): error MIDL2026: cannot recover from earlier syntax errors; aborting compilation
1>Done building project "My_Dll_Test_MFC.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
What mistake have I made here?