Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
340 views
in Technique[技术] by (71.8m points)

winapi - 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)inNETFX 4.8 Toolslbexp.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_Dllinx86DebugMy_Dll.tlb 1>My_Dll.tlb 
1>..My_Dllinx86DebugMy_Dll.tlb(1): warning C4335: Mac file format detected: please convert the source file to either DOS or UNIX format 
1>..My_Dllinx86DebugMy_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_Dllinx86DebugMy_Dll.tlb(1): error MIDL2026: cannot recover from earlier syntax errors; aborting compilation 1>Done building project "My_Dll_Test_MFC.vcxproj" -- FAILED.

What mistake have I made here?

question from:https://stackoverflow.com/questions/65924974/c-sharp-class-library-export-as-com-errors-during-midl-compilation

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should not use duplicated element id. HTML attribute id is unique value.

$('input[name=work_status]:checked').val() will helps you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...