简体   繁体   中英

#import generates incorrect TLH file

I am trying to create an stdafx.cpp file that includes all the #imports in a project to improve build time. I want to include all the imports for word/excel/ppt of office 2010, 2013 and 2016.

When I place all the imports in the CPP, there is no problem but when I place all the #imports in the stdafx.cpp. cx_excel2013.tlh is generated incorrectly.

The problem is that cx_excel2013.tlh is trying to use "Office2010" namespace for objects in "Office2013", which causes the build to fail. for example, enum Office2010::MsoTriState LinkToFile is being generated which fails the build.

Can anyone explain what is going on or what is happening and how to overcome this (without returning the #imports back to the CPP)??? Also, I thought of just generating the TLH/TLI and remove the imports all together because they will not change, but it feels wrong and I don't solve the real problem.

Thanks!

STDAFX.CPP:

// Office 2010
#import "..\lib\tlb\office\MSO2010.tlb"     rename_namespace("Office2010") rename("RGB","msoRGB") rename("SearchPath", "msoSearchPath") rename("DocumentProperties", "msoDocumentProperties")
#import "..\lib\tlb\office\VBE6EXT2010.tlb" rename_namespace("VBE6EXT2010") rename("Property", "vbeProperty")
#pragma warning(disable: 4192)
#import "..\lib\tlb\office\excel2010.tlb"   rename_namespace("Excel2010") rename("VBE6", "VBE6EXT2010") rename("RGB","excelRGB") rename("DialogBox","excelDialogBox") rename("CopyFile","excelCopyFile") rename("ReplaceText","excelReplaceText") rename("Property", "excelProperty") no_function_mapping
#import "..\lib\tlb\office\msppt2010.tlb"   rename_namespace("PowerPoint2010") rename("VBE6", "VBE6EXT2010") rename("RGB","pptRGB") rename("Property", "pptProperty") no_function_mapping
#import "..\lib\tlb\office\MSWORD2010.tlb"  rename_namespace("Word2010")    rename("VBE6", "VBE6EXT2010") rename("ExitWindows","wordExitWindows") rename("FindText","FindText1") rename("RGB", "wordRGB") no_function_mapping
#pragma warning(default: 4192)

// Office 2013
#import "..\lib\tlb\office\MSO2013.tlb"     rename_namespace("Office2013") rename("RGB","msoRGB") rename("SearchPath", "msoSearchPath") rename("DocumentProperties", "msoDocumentProperties")
#import "..\lib\tlb\office\VBE6EXT2013.tlb" rename_namespace("VBE6EXT2013") rename("Property", "vbeProperty")
#pragma warning(disable: 4192)
#import "..\lib\tlb\office\excel2013.tlb"   rename_namespace("Excel2013") rename("VBE6", "VBE6EXT2013") rename("RGB","excelRGB") rename("DialogBox","excelDialogBox") rename("CopyFile","excelCopyFile") rename("ReplaceText","excelReplaceText") rename("Property", "excelProperty") no_function_mapping
#import "..\lib\tlb\office\msppt2013.tlb"   rename_namespace("PowerPoint2013") rename("VBE6", "VBE6EXT2013") rename("RGB","pptRGB") rename("Property", "pptProperty") no_function_mapping
#import "..\lib\tlb\office\MSWORD2013.tlb"  rename_namespace("Word2013")    rename("VBE6", "VBE6EXT2013") rename("ExitWindows","wordExitWindows") rename("FindText","FindText1") rename("RGB", "wordRGB") no_function_mapping
#pragma warning(default: 4192)

// Office 2016
#import "..\lib\tlb\office\MSO2016.tlb"     rename_namespace("Office2016") rename("RGB","msoRGB") rename("SearchPath", "msoSearchPath") rename("DocumentProperties", "msoDocumentProperties")
#import "..\lib\tlb\office\VBE6EXT2016.tlb" rename_namespace("VBE6EXT2016") rename("Property", "vbeProperty")
#pragma warning(disable: 4192)
#import "..\lib\tlb\office\excel2016.tlb"   rename_namespace("Excel2016") rename("VBE6", "VBE6EXT2016") rename("RGB","excelRGB") rename("DialogBox","excelDialogBox") rename("CopyFile","excelCopyFile") rename("ReplaceText","excelReplaceText") rename("Property", "excelProperty") no_function_mapping
#import "..\lib\tlb\office\msppt2016.tlb"   rename_namespace("PowerPoint2016") rename("VBE6", "VBE6EXT2016") rename("RGB","pptRGB") rename("Property", "pptProperty") no_function_mapping
#import "..\lib\tlb\office\MSWORD2016.tlb"  rename_namespace("Word2016")    rename("VBE6", "VBE6EXT2016") rename("ExitWindows","wordExitWindows") rename("FindText","FindText1") rename("RGB", "wordRGB") no_function_mapping
#pragma warning(default: 4192)

EDIT: I should add that the build fails and the other TLH/TLIs are not being generated.

The problem was that all office versions are using the same GUID, the only difference is the version, which the #import directive ignores.

That is why while constructing Excel2013.tlh/tli is using Office2010 (the first office TLB), because the GUID is it looking for is already defined so it can ignore Office2013. From VS point of view, it is the same one.

The interfaces are backward compatible, so the solution was just importing the 2016. The downside is that Office2010/2013 code can try to use code that it doesn't really support (fails in runtime).

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