VC中的#import

 ms-help://MS.MSDNQTR.v80.chs/MS.MSDN.v80/MS.VisualStudio.v80.chs/dv_vclang/html/e0fc4564-b6cf-4a36-bf51-6ccd7abd0a94.htm
ms-help://MS.MSDNQTR.v80.chs/MS.MSDN.v80/MS.VisualStudio.v80.chs/dv_vclang/html/787d1112-e543-40d7-ab15-a63d43f4030a.htm
C++ Specific
Used to incorporate information from a type library. The content of the type library is converted into C++ classes, mostly describing the COM interfaces.
 
#import "filename" [attributes]
#import <filename> [attributes]


Parameters
filename
Allows you to specify which type library you want to import. filename can be one of the following:
A type library (.tlb or .odl). file:, which indicates type library, can precede each filename.

// The progid of a control in the type library. Note that progid: can precede each progid. For example:
#import "progid:my.prog.id.1.5"
 
// The library ID of the type library. Note that libid: can precede each library ID. For example:
#import "libid:12341234-1234-1234-1234-123412341234" version("4.0") lcid("9")

attributes
One or more #import attributes. Separate attributes with either a space or comma. For example:

// 添加属性
#import "../drawctl/drawctl.tlb" no_namespace, raw_interfaces_only
// 或者
#import "../drawctl/drawctl.tlb" no_namespace raw_interfaces_only


// Specifying the Localization ID and Version Number
// When you specify a progid, you can also specify the localization ID and version number of the progid.
#import "progid:my.prog.id" lcid("0") version("4.0)

#import Attributes
#import can optionally include one or more attributes. These attributes tell the compiler to modify the contents of the type-library headers. A backslash (/)

symbol can be used to include additional lines in a single #import statement. For example:

// rename
#import "test.lib" no_namespace /
   rename("OldName", "NewName")

// attributes
Provides links to attributes used with the #import directive.

Microsoft Specific

The following attributes are available to the #import directive.

auto_rename
Renames C++ reserved words by appending two underscores (__) to the variable name to resolve potential name conflicts.
 
auto_search
Specifies that, when a type library is referenced with #import and itself references another type library, the compiler can do an implicit #import for the

other type library.
 
embedded_idl
Specifies that the type library is written to the .tlh file with the attribute-generated code preserved.
 
exclude (#import)
Excludes items from the type library header files being generated.
 
high_method_prefix
Specifies a prefix to be used in naming high-level properties and methods.
 
high_property_prefixes
Specifies alternate prefixes for three property methods.
 
implementation_only
Suppresses the generation of the .tlh header file (the primary header file).
 
include()
Disables automatic exclusion.
 
inject_statement
Inserts its argument as source text into the type-library header.
 
named_guids
Tells the compiler to define and initialize GUID variables in old style, of the form LIBID_MyLib, CLSID_MyCoClass, IID_MyInterface, and DIID_MyDispInterface.
 
no_auto_exclude
Disables automatic exclusion.
 
no_dual_interfaces
Changes the way the compiler generates wrapper functions for dual interface methods.
 
no_implementation
Suppresses the generation of the .tli header, which contains the implementations of the wrapper member functions.
 
no_namespace
Specifies that the namespace name is not generated by the compiler.
 
no_registry
Tells the compiler not to search the registry for type libraries.
 
no_search_namespace
Has the same functionality as the no_namespace attribute but is used on type libraries that you use the #import directive with the auto_search attribute.
 
no_smart_pointers
Suppresses the creation of smart pointers for all interfaces in the type library.
 
raw_dispinterfaces
Tells the compiler to generate low-level wrapper functions for dispinterface methods and properties that call IDispatch::Invoke and return the HRESULT error

code.
 
raw_interfaces_only
Suppresses the generation of error-handling wrapper functions and property (C++) declarations that use those wrapper functions.
 
raw_method_prefix
Specifies a different prefix to avoid name collisions.
 
raw_native_types
Disables the use of COM support classes in the high-level wrapper functions and forces the use of low-level data types instead.
 
raw_property_prefixes
Specifies alternate prefixes for three property methods.
 
rename (#import)
Works around name collision problems.
 
rename_namespace
Renames the namespace that contains the contents of the type library.
 
rename_search_namespace
Has the same functionality as the rename_namespace attribute but is used on type libraries that you use the #import directive with the auto_search attribute.
 
tlbid
Allows for loading libraries other than the primary type library.

你可能感兴趣的:(VC中的#import)