导入.TLB文件会给出“无法打开源文件x.tlh”。 [英] Import .TLB file gives "cannot open source file x.tlh"
问题描述
我正在将VS2010 C ++项目更新为VS2019。
I'm updating a VS2010 C++ project to VS2019.
该项目正在导入多个tlb文件,对于每个文件,VS2019都给出了错误提示.tlh文件为无法打开源文件。
The project is importing several tlb files, and for each of these, VS2019 is giving an error that it "cannot open source file" for the .tlh file.
其中之一来自我也已升级的DLL(用C#编写,在其中建立并注册为OK) VS2019),另外2个是第三方tlb文件。
One of these is from a DLL that I've also upgraded (written in C#, built and registered OK in VS2019), and 2 others are 3rd party tlb files.
以下是导入语句的示例(在我的头文件中)...
Here's an example of the import statement (in my header file)...
#import "../ExcelInterop/bin/Debug/ExcelInterop.tlb" raw_interfaces_only, raw_native_types, no_namespace, named_guids
头文件位置中的相对路径正确。
The relative path is correct from the header file location.
如何解决此问题错误,并让VS2019正确处理我的.tlb文件?
How do I fix this error, and get VS2019 to correctly process my .tlb files?
推荐答案
我找到了一种解决方法。如果您#import XXX.dll而编译器抱怨它无法打开源文件XXX.tlh,则只需在#import行上方添加以下行:
I have found a workaround. If you #import XXX.dll and the compiler complains about that it "cannot open source file XXX.tlh", just add this line above the #import line:
#include" [XXX.tlh的完整路径]
#include "[full path of XXX.tlh]"
并注释掉#import行。现在它应该通过编译,因为文件XXX.tlh确实存在。成功后,将您的代码恢复为原始代码。
and comment out the #import line. It should now pass the compilation because the file XXX.tlh does exist. Once successful, revert your code back to the original.
这篇关于导入.TLB文件会给出“无法打开源文件x.tlh”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!