简体   繁体   中英

Problems connecting x64 application through COM objects

We had a C++ program 'A' that was built in the Win32 platform which was connected from a C# application 'B' that was built in Any CPU platform. The B application accessed A though some COM objects and 'A' program creates .tlb files which I referenced from B. With the Win32 and Any CPU platforms I had no problem in making the two programs connect and work.

Recently 'A' program was updated to work in 64x and the Win32 version is no longer built for it. Now whenever I try to reference the new .tlb files from project 'B', I get errors saying

"A reference to ...tlb could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component"

I have tried building the 'B' project with x86 and x64, but nothing is working.

I'm new to COM objects, so my knowledge is very limited in this subject. I'm working in VS 2017. Any help would be appreciated.

Thanks.

Your description makes me think, that A acts as a InProc COM server , which means that the architecture (x86 or x64) does matter. So if you run into trouble after changing the architecture of A , I suggest you try to get more control about the creation of the Runtime Callable Wrapper , which is created out of A 's .tlb file.

Please refer to https://docs.microsoft.com/en-us/dotnet/framework/tools/tlbimp-exe-type-library-importer for the TLB-Importer tool. Use it create the Runtime Callable Wrapper (aka interop.*.dll ) and make sure to add the switch /machine:x64 . Eg run a command like the following in a terminal window with elevated user rights to get a .NET assembly, which can be loaded by an x64 .NET program: tlbimp A.tlb /machine:x64

Provided that A.tlb is registered properly and you are running on a x64 platform (so Any CPU really means x64 ) B should b able to load the RCW and refer to type information from the registry. In case this still makes some trouble, you should consider to have a closer look at the registered type using https://docs.microsoft.com/en-us/windows/win32/com/ole-com-object-viewer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM