在 VC++ 程序中使用 #import from MSOUTL.OLB 创建 .tlh 和 .tli 文件时出错

Posted

技术标签:

【中文标题】在 VC++ 程序中使用 #import from MSOUTL.OLB 创建 .tlh 和 .tli 文件时出错【英文标题】:Error while creating .tlh and .tli file using #import from MSOUTL.OLB in VC++ program 【发布时间】:2021-08-25 17:46:17 【问题描述】:

我想创建 MSOUTL.OLB 文件的 .thl.tli 文件,因为我想使用生成的 .thl 和 . tli 文件在我的 C++ 项目中使用#include 语句。为此,我正在使用下面的代码行,它会引发如下所述的错误。知道为什么会这样吗?

#import "C:\\Program Files\\Microsoft Office\\root\\Office16\\MSOUTL.OLB" rename("CopyFile", "OlkCopyFile") named_guids

当我编译它时。它抛出以下错误

1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6767): error C3646: 'Assistant': unknown override specifier
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6767): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6777): error C3646: 'Assistance': unknown override specifier
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6777): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6781): error C3646: 'COMAddIns': unknown override specifier
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6781): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6783): error C3646: 'PickerDialog': unknown override specifier
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6783): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6789): error C3646: 'LanguageSettings': unknown override specifier
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6789): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6797): error C3646: 'AnswerWizard': unknown override specifier
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6797): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6801): error C3646: 'MsoDebugOptions': unknown override specifier
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6801): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6805): error C3646: 'DataPrivacyOptions': unknown override specifier
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6805): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6815): error C3646: 'GetAssistant': unknown override specifier
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6815): error C2059: syntax error: '('
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6815): error C2238: unexpected token(s) preceding ';'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6830): error C3646: 'GetCOMAddIns': unknown override specifier
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6830): error C2059: syntax error: '('
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6830): error C2238: unexpected token(s) preceding ';'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6833): error C3646: 'GetLanguageSettings': unknown override specifier
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6833): error C2059: syntax error: '('
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6833): error C2238: unexpected token(s) preceding ';'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6835): error C3646: 'GetAnswerWizard': unknown override specifier
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6835): error C2059: syntax error: '('
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6835): error C2238: unexpected token(s) preceding ';'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6858): error C3646: 'GetAssistance': unknown override specifier
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6858): error C2059: syntax error: '('
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6858): error C2238: unexpected token(s) preceding ';'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6860): error C3646: 'GetPickerDialog': unknown override specifier
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6860): error C2059: syntax error: '('
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6860): error C2238: unexpected token(s) preceding ';'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6863): error C3646: 'GetMsoDebugOptions': unknown override specifier
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6863): error C2059: syntax error: '('
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6863): error C2238: unexpected token(s) preceding ';'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6864): error C3646: 'GetDataPrivacyOptions': unknown override specifier
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6864): error C2059: syntax error: '('
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6864): error C2238: unexpected token(s) preceding ';'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(7087): error C3646: 'CreateContactCard': unknown override specifier
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(7087): error C2059: syntax error: '('
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(7088): error C2238: unexpected token(s) preceding ';'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(7971): error C3646: 'CommandBars': unknown override specifier
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(7971): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(8009): error C3646: 'GetCommandBars': unknown override specifier
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(8009): error C2059: syntax error: '('
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(8009): error C2238: unexpected token(s) preceding ';'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(18001): error C3646: 'CommandBars': unknown override specifier
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(18001): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(18057): error C3646: 'GetCommandBars': unknown override specifier
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(18057): error C2059: syntax error: '('
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(18057): error C2238: unexpected token(s) preceding ';'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(21638): error C2556: 'Outlook::AddressEntryPtr Outlook::_AppointmentItem::GetOrganizer(void)': overloaded function differs only by return type from '_bstr_t Outlook::_AppointmentItem::GetOrganizer(void)'
1>  c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(21536): note: see declaration of 'Outlook::_AppointmentItem::GetOrganizer'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(21638): error C2371: 'Outlook::_AppointmentItem::GetOrganizer': redefinition; different basic types
1>  c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(21536): note: see declaration of 'Outlook::_AppointmentItem::GetOrganizer'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28929): error C2039: 'GetAssistant': is not a member of 'Outlook::_Application'
1>  c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6756): note: see declaration of 'Outlook::_Application'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28929): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28929): error C2497: 'AssistantPtr': 'implementation_key' can only be applied to function declarations
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28929): error C2146: syntax error: missing ';' before identifier 'GetAssistant'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28939): error C2039: 'GetCOMAddIns': is not a member of 'Outlook::_Application'
1>  c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6756): note: see declaration of 'Outlook::_Application'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28939): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28939): error C2497: 'COMAddInsPtr': 'implementation_key' can only be applied to function declarations
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28939): error C2146: syntax error: missing ';' before identifier 'GetCOMAddIns'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28942): error C2039: 'GetLanguageSettings': is not a member of 'Outlook::_Application'
1>  c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6756): note: see declaration of 'Outlook::_Application'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28942): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28942): error C2497: 'LanguageSettingsPtr': 'implementation_key' can only be applied to function declarations
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28942): error C2146: syntax error: missing ';' before identifier 'GetLanguageSettings'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28944): error C2039: 'GetAnswerWizard': is not a member of 'Outlook::_Application'
1>  c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6756): note: see declaration of 'Outlook::_Application'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28944): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28944): error C2497: 'AnswerWizardPtr': 'implementation_key' can only be applied to function declarations
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28944): error C2146: syntax error: missing ';' before identifier 'GetAnswerWizard'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28956): error C2039: 'GetAssistance': is not a member of 'Outlook::_Application'
1>  c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6756): note: see declaration of 'Outlook::_Application'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28956): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28956): error C2497: 'IAssistancePtr': 'implementation_key' can only be applied to function declarations
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28956): error C2146: syntax error: missing ';' before identifier 'GetAssistance'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28958): error C2039: 'GetPickerDialog': is not a member of 'Outlook::_Application'
1>  c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6756): note: see declaration of 'Outlook::_Application'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28958): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28958): error C2497: 'PickerDialogPtr': 'implementation_key' can only be applied to function declarations
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28958): error C2146: syntax error: missing ';' before identifier 'GetPickerDialog'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28960): error C2039: 'GetMsoDebugOptions': is not a member of 'Outlook::_Application'
1>  c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6756): note: see declaration of 'Outlook::_Application'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28960): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28960): error C2497: 'MsoDebugOptionsPtr': 'implementation_key' can only be applied to function declarations
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28960): error C2146: syntax error: missing ';' before identifier 'GetMsoDebugOptions'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28961): error C2039: 'GetDataPrivacyOptions': is not a member of 'Outlook::_Application'
1>  c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6756): note: see declaration of 'Outlook::_Application'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28961): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28961): error C2497: 'DataPrivacyOptionsPtr': 'implementation_key' can only be applied to function declarations
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(28961): error C2146: syntax error: missing ';' before identifier 'GetDataPrivacyOptions'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(29006): error C2039: 'CreateContactCard': is not a member of 'Outlook::_NameSpace'
1>  c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(6960): note: see declaration of 'Outlook::_NameSpace'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(29006): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(29006): error C2497: 'ContactCardPtr': 'implementation_key' can only be applied to function declarations
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(29006): error C2146: syntax error: missing ';' before identifier 'CreateContactCard'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(29137): error C2039: 'GetCommandBars': is not a member of 'Outlook::_Inspector'
1>  c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(21536): note: see declaration of 'Outlook::_AppointmentItem::GetOrganizer'
1>c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(31671): error C2371: 'Outlook::_AppointmentItem::GetOrganizer': redefinition; different basic types
1>  c:\temp\testunicode\testunicode\x64\release\msoutl.tlh(21536): note: see declaration of 'Outlook::_AppointmentItem::GetOrganizer'

任何帮助,如何解决这个问题?我需要添加任何引用或任何编译器选项吗?

【问题讨论】:

您是否对 .tlh 文件使用单独的#include?​​span> 几十年前的一篇帖子说AssistantMSO9.DLL 中定义。这可能表明MSOUTL.OLB 不是独立的。 更新 - 更新见第一个答案 - social.msdn.microsoft.com/Forums/vstudio/en-US/… @RichardCritten 是的,我也遇到了这些链接......经过一些试验和错误,以及一些谷歌搜索:#import "C:\Program Files\Microsoft Office\Root\VFS\ProgramFilesCommonX86\Microsoft Shared\OFFICE16\MSO.dll" rename_namespace("Outlook") #import "C:\\Program Files\\Microsoft Office\\root\\Office16\\MSOUTL.OLB" rename_namespace("Outlook") rename ("GetOrganizer", "GetOrganizer1") 至少编译没有错误。 对 MSO.dll 的依赖出现在生成的 msoutl.tlh 的顶部: // Cross-referenced type libraries: // // #import "C:\Program Files\Microsoft Office\Root\VFS\ProgramFilesCommonX86\Microsoft Shared\OFFICE16\MSO.DLL" // 【参考方案1】:

提示@Simon Mourier,您需要先导入一个依赖项:

#import "C:\Program Files\Microsoft Office\Root\VFS\ProgramFilesCommonX86\Microsoft Shared\OFFICE16\MSO.dll" \
    rename("RGB","RGB_mso") rename("DocumentProperties","DocumentProperties_mso") \
    no_function_mapping

using namespace Office;

#import "C:\\Program Files\\Microsoft Office\\root\\Office16\\MSOUTL.OLB" \
    rename("GetOrganizer", "GetOrganizer_msoutl") rename("CopyFile","CopyFile_msoutl") rename ("PlaySound","PlaySound_msoutl") \
    no_function_mapping

我已经重命名了在我的编译器(VS Community 2019)和我的类型库版本上发出重复警告的所有函数。我还添加了(未记录的)no_function_mapping 限定符,因为诸如此类的大型类型库的函数映射(根据 MS 的旧编译器的一些遗留功能)可能会导致罕见的问题:See SO answer here。

【讨论】:

以上是关于在 VC++ 程序中使用 #import from MSOUTL.OLB 创建 .tlh 和 .tli 文件时出错的主要内容,如果未能解决你的问题,请参考以下文章

Python的from import和import的区别

python中import和from...import区别

import和from-import的区别

vc中怎么连接SqlServer

用一个简单小程序谈import和from...import的区别

python import 与 from .... import ...区别