|
1 |
| ---- |
2 |
| -title: "import | Microsoft Docs" |
3 |
| -ms.custom: "" |
4 |
| -ms.date: "11/04/2016" |
5 |
| -ms.technology: ["cpp-windows"] |
6 |
| -ms.topic: "reference" |
7 |
| -f1_keywords: ["vc-attr.import"] |
8 |
| -dev_langs: ["C++"] |
9 |
| -helpviewer_keywords: ["import attribute"] |
10 |
| -ms.assetid: ebf07cae-39fb-4047-8b57-54af0a9a83de |
11 |
| -author: "mikeblome" |
12 |
| -ms.author: "mblome" |
13 |
| -ms.workload: ["cplusplus", "uwp"] |
14 |
| ---- |
15 |
| -# import |
16 |
| -Specifies another .idl, .odl, or header file containing definitions you want to reference from your main IDL. |
17 |
| - |
18 |
| -## Syntax |
19 |
| - |
20 |
| -``` |
21 |
| - |
22 |
| - [ import( |
23 |
| - idl_file |
24 |
| -) ]; |
25 |
| -``` |
26 |
| - |
27 |
| -#### Parameters |
28 |
| - `idl_file` |
29 |
| - The name of an .idl file that you want imported into the type library of the current project. |
30 |
| - |
31 |
| -## Remarks |
32 |
| - The **import** C++ attribute causes an `#import` statement to be placed below the `import "docobj.idl"` statement in the generated .idl file. The **import** attribute has the same functionality as the [import](http://msdn.microsoft.com/library/windows/desktop/aa367047) MIDL attribute. |
33 |
| - |
34 |
| - The **import** attribute only places the specified file into the .idl file that will be generated by your project; the **import** attribute does not let you call constructs in the specified file from source code in your project. To call constructs in the specified file from source code in your project, either use [#import](../preprocessor/hash-import-directive-cpp.md) and the `embedded_idl` attribute or you can include the .h file for the `idl_file`, if a .h file exists. |
35 |
| - |
36 |
| -## Example |
37 |
| - The following code: |
38 |
| - |
39 |
| -``` |
40 |
| -// cpp_attr_ref_import.cpp |
41 |
| -// compile with: /LD |
42 |
| -[module(name="MyLib")]; |
43 |
| -[import(import.idl)]; |
44 |
| -``` |
45 |
| - |
46 |
| - produces the following code in the generated .idl file: |
47 |
| - |
48 |
| -``` |
49 |
| -import "docobj.idl"; |
50 |
| -import "import.idl"; |
51 |
| - |
52 |
| -[ uuid(EED3644C-8488-3ECD-BA97-147DB3CDB499), version(1.0) ] |
53 |
| -library MyLib { |
54 |
| - importlib("stdole2.tlb"); |
55 |
| - importlib("olepro32.dll"); |
56 |
| -... |
57 |
| -``` |
58 |
| - |
59 |
| -## Requirements |
60 |
| - |
61 |
| -### Attribute Context |
62 |
| - |
63 |
| -||| |
64 |
| -|-|-| |
65 |
| -|**Applies to**|Anywhere| |
66 |
| -|**Repeatable**|No| |
67 |
| -|**Required attributes**|None| |
68 |
| -|**Invalid attributes**|None| |
69 |
| - |
70 |
| - For more information, see [Attribute Contexts](../windows/attribute-contexts.md). |
71 |
| - |
72 |
| -## See Also |
73 |
| - [IDL Attributes](../windows/idl-attributes.md) |
74 |
| - [Stand-Alone Attributes](../windows/stand-alone-attributes.md) |
75 |
| - [importidl](../windows/importidl.md) |
76 |
| - [importlib](../windows/importlib.md) |
77 |
| - [include](../windows/include-cpp.md) |
78 |
| - [includelib](../windows/includelib-cpp.md) |
| 1 | +--- |
| 2 | +title: "import | Microsoft Docs" |
| 3 | +ms.custom: "" |
| 4 | +ms.date: "11/04/2016" |
| 5 | +ms.technology: ["cpp-windows"] |
| 6 | +ms.topic: "reference" |
| 7 | +f1_keywords: ["vc-attr.import"] |
| 8 | +dev_langs: ["C++"] |
| 9 | +helpviewer_keywords: ["import attribute"] |
| 10 | +ms.assetid: ebf07cae-39fb-4047-8b57-54af0a9a83de |
| 11 | +author: "mikeblome" |
| 12 | +ms.author: "mblome" |
| 13 | +ms.workload: ["cplusplus", "uwp"] |
| 14 | +--- |
| 15 | +# import |
| 16 | +Specifies another .idl, .odl, or header file containing definitions you want to reference from your main IDL. |
| 17 | + |
| 18 | +## Syntax |
| 19 | + |
| 20 | +``` |
| 21 | +[ import( |
| 22 | + idl_file |
| 23 | +) ]; |
| 24 | +``` |
| 25 | + |
| 26 | +### Parameters |
| 27 | + *idl_file* |
| 28 | + The name of an .idl file that you want imported into the type library of the current project. |
| 29 | + |
| 30 | +## Remarks |
| 31 | + The **import** C++ attribute causes an `#import` statement to be placed below the `import "docobj.idl"` statement in the generated .idl file. The **import** attribute has the same functionality as the [import](http://msdn.microsoft.com/library/windows/desktop/aa367047) MIDL attribute. |
| 32 | + |
| 33 | + The **import** attribute only places the specified file into the .idl file that will be generated by your project; the **import** attribute does not let you call constructs in the specified file from source code in your project. To call constructs in the specified file from source code in your project, either use [#import](../preprocessor/hash-import-directive-cpp.md) and the `embedded_idl` attribute or you can include the .h file for the *idl_file*, if a .h file exists. |
| 34 | + |
| 35 | +## Example |
| 36 | + The following code: |
| 37 | + |
| 38 | +```cpp |
| 39 | +// cpp_attr_ref_import.cpp |
| 40 | +// compile with: /LD |
| 41 | +[module(name="MyLib")]; |
| 42 | +[import(import.idl)]; |
| 43 | +``` |
| 44 | + |
| 45 | + produces the following code in the generated .idl file: |
| 46 | + |
| 47 | +``` |
| 48 | +import "docobj.idl"; |
| 49 | +import "import.idl"; |
| 50 | + |
| 51 | +[ uuid(EED3644C-8488-3ECD-BA97-147DB3CDB499), version(1.0) ] |
| 52 | +library MyLib { |
| 53 | + importlib("stdole2.tlb"); |
| 54 | + importlib("olepro32.dll"); |
| 55 | +... |
| 56 | +``` |
| 57 | + |
| 58 | +## Requirements |
| 59 | + |
| 60 | +### Attribute Context |
| 61 | + |
| 62 | +||| |
| 63 | +|-|-| |
| 64 | +|**Applies to**|Anywhere| |
| 65 | +|**Repeatable**|No| |
| 66 | +|**Required attributes**|None| |
| 67 | +|**Invalid attributes**|None| |
| 68 | + |
| 69 | + For more information, see [Attribute Contexts](../windows/attribute-contexts.md). |
| 70 | + |
| 71 | +## See Also |
| 72 | + [IDL Attributes](../windows/idl-attributes.md) |
| 73 | + [Stand-Alone Attributes](../windows/stand-alone-attributes.md) |
| 74 | + [importidl](../windows/importidl.md) |
| 75 | + [importlib](../windows/importlib.md) |
| 76 | + [include](../windows/include-cpp.md) |
| 77 | + [includelib](../windows/includelib-cpp.md) |
0 commit comments