#import指令常用属性解释
比如我们常用代码里面会涉及renamesapce no_namespace rename等,但你知道有啥用吗?比如如下代码片段
#import "c:\Program Files\Common Files\System\ado\msado15.dll"\
rename_namespace("AdoDB")\
rename("EOF","adoEOF")
通过测试工程认识和熟悉其用法
no_namespace
#import "import_include/ado/x86/msado15.dll"
#import "import_include/ado/x86/msado15.dll" \ no_namespace
msdn有提到:Specifies that the namespace name is not generated by the compiler. 对比生成的msado15.tlh,发现使用no_namespace,无ADODB命名空间定义。
// C++ source equivalent of Win32 type library .\import_include/ado/x86/msado15.dll // compiler-generated file created 12/04/16 at 19:07:38 - DO NOT EDIT! #pragma once #pragma pack(push, 8) #include <comdef.h> namespace ADODB { ...... #include "C:\Users\AppData\Local\Temp\msado15.tli" } // namespace ADODB #pragma pack(pop)
renamespace
#import "import_include/ado/x86/msado15.dll" \ rename_namespace("ADODB_NEW")
对比tlh文件,可以看到命名空间变化如下
namespace ADODB_NEW {
rename
msdn “Works around name collision problems.” 解决冲突时使用。
测试代码:#import "import_include/ado/x86/msado15.dll" \ rename("EOF","EOF_NEW")
生成的tlh文件差异
__declspec(property(get=GetEOF)) VARIANT_BOOL EOF;
__declspec(property(get=GetEOF_NEW)) VARIANT_BOOL EOF_NEW;