|
| 1 | +--- |
| 2 | +description: "Learn more about: Use a Microsoft Visual Studio wizard to add an IDL property to an IDL interface in your project" |
| 3 | +title: "Add an IDL property" |
| 4 | +ms.date: "04/04/2022" |
| 5 | +f1_keywords: ["vc.codewiz.prop.overview", "vc.codewiz.prop.idlattributes"] |
| 6 | +helpviewer_keywords: ["interfaces, adding properties", "properties [C++], adding to interfaces", "names, add property wizard", "IDL attributes", "stock properties, about stock properties", "stock properties"] |
| 7 | +ms.assetid: 37bd4db7-efd3-4faa-87ad-64902ed16a36 |
| 8 | +ms.custom: devdivchpfy22 |
| 9 | +--- |
| 10 | +# Add an IDL property |
| 11 | + |
| 12 | +The **Add IDL Property** wizard adds a method to an interface defined in an Interface Definition Library (IDL) in a project that has IDL file. To use the **Add IDL Property** wizard, you must be in a project that doesn't support MFC. |
| 13 | + |
| 14 | +For example, if you have an ATL project, and it has an IDL file, using the following procedure you can add the method to interface. |
| 15 | + |
| 16 | +This wizard differs from the **Add Property** wizard and **ADD IDL MFC Property** wizard. The [Add Property](../../ide/adding-a-property-visual-cpp.md) wizard adds a default method to your project. The Add IDL MFC Method wizard is specific to MFC, ActiveX, or ATL projects that support MFC. |
| 17 | + |
| 18 | +**To add an IDL property to your object:** |
| 19 | + |
| 20 | +1. On the **View** menu, select **Class View**. |
| 21 | + |
| 22 | +1. In [Class View](/visualstudio/ide/viewing-the-structure-of-code), right-click the name of the interface to which you want to add the property. |
| 23 | + |
| 24 | + > [!NOTE] |
| 25 | + > You can also add properties to dispinterfaces, which, unless the project is attributed, are nested within the library node. |
| 26 | +
|
| 27 | +1. From the shortcut menu, select **Add** > **Add Property**. |
| 28 | + |
| 29 | +1. In the **Add IDL Property** wizard, provide the information to create the property. |
| 30 | + |
| 31 | +1. Specify any IDL settings for the property. |
| 32 | + |
| 33 | +1. Select **OK** to add the property. |
| 34 | + |
| 35 | +The `Get` and `Put` methods of the property are displayed as two icons in **Class View**, under the interface where it's defined. You can double-click either icon to view the property declaration in the .idl file. |
| 36 | + |
| 37 | +For ATL interfaces, the `Get` and `Put` functions are added to the .cpp file, and references to these functions are added to the .h file. |
| 38 | + |
| 39 | +## Add an IDL property wizard |
| 40 | + |
| 41 | +The following section describes the UI that you'll use to add an IDL property: |
| 42 | + |
| 43 | +:::image type="content" source="../reference/media/add-idl-property-wizard.png" alt-text="Adding IDL property to the interface"::: |
| 44 | + |
| 45 | +- **Property name** |
| 46 | + |
| 47 | + Sets the name of the property. |
| 48 | + |
| 49 | +- **Property type** |
| 50 | + |
| 51 | + Sets the type of property you're adding. |
| 52 | + |
| 53 | +- **Return type** |
| 54 | + |
| 55 | + For ATL interfaces, sets the return type for the property. For dual interfaces, `HRESULT` is always the return type, and select option is unavailable. For custom interfaces, you can select a return type from the list. `HRESULT` is still recommended, because it provides a standard way to return errors. |
| 56 | + |
| 57 | +- **Get function** |
| 58 | + |
| 59 | + For ATL interfaces, sets the property as readable. It creates the `Get` method for retrieving property from the object. Select **Get**, **Put**, or both. |
| 60 | + |
| 61 | +- **Put function** |
| 62 | + |
| 63 | + For ATL interfaces, sets the property writable. It creates the `Put` method for setting, or "putting," property of the object. Select **Get**, **Put**, or both. If you select **Put function** option, you can choose from the following two ways to implement the method: |
| 64 | + |
| 65 | + |Option|Description| |
| 66 | + |------------|-----------------| |
| 67 | + |**PropPut**|The [PropPut](../windows/attributes/propput.md) function returns a copy of the object. **PropPut** is the default and the most common way to make the property writable.| |
| 68 | + |**PropPutRef**|The [PropPutRef](../windows/attributes/propputref.md) function returns a reference to the object, rather than returning the copy of the object itself. Consider using **PropPutRef** option for objects, such as large structs or arrays, that may have initialization overhead.| |
| 69 | + |
| 70 | +- **Parameters** |
| 71 | + |
| 72 | + Displays the list of parameters added to the property. Each item in the list consists of the parameter name, parameter type, and attributes. |
| 73 | + |
| 74 | + The `in` indicates that the parameter is passed from the calling procedure to the called procedure. The `out` indicates that the pointer parameter is returned from the called procedure to the calling procedure (from the server to the client). |
| 75 | + |
| 76 | +- **+** |
| 77 | + |
| 78 | + Add a parameter. In **Parameters**, type the parameter type and name. For example, `int x`, and select **OK**. |
| 79 | + |
| 80 | +- **x** |
| 81 | + |
| 82 | + Removes the selected parameter from **Parameters**. |
| 83 | + |
| 84 | +- **Pencil icon** |
| 85 | + |
| 86 | + Edit the selected parameter. |
| 87 | + |
| 88 | +- **Attributes** |
| 89 | + |
| 90 | + - `helpcontext` |
| 91 | + |
| 92 | + Specifies a context ID that lets the user view information about this property in the Help file. For more information, see [helpcontext](/windows/win32/Midl/helpcontext) in the *MIDL Reference*. |
| 93 | + |
| 94 | + - `helpstring` |
| 95 | + |
| 96 | + Specifies a character string that's used to describe the element to which it applies. By default, it's set to **`property`** *Property name*. For more information, see [helpstring](/windows/win32/Midl/helpstring) in the *MIDL Reference*. |
| 97 | + |
| 98 | + - `id` |
| 99 | + |
| 100 | + Sets the numerical ID that identifies the property. This option isn't available for properties of custom interfaces. For more information, see [id](/windows/win32/Midl/id) in the *MIDL Reference*. |
| 101 | + |
| 102 | +- **Additional attributes** |
| 103 | + |
| 104 | +|Option|Description| |
| 105 | +|------------|-----------------| |
| 106 | +|`bindable`|Indicates that the property supports data binding. For more information, see [bindable](/windows/win32/Midl/bindable) in the *MIDL Reference*.| |
| 107 | +|`defaultbind`|Indicates that this single, bindable property best represents the object. For more information, see [defaultbind](/windows/win32/Midl/defaultbind) in the *MIDL Reference*.| |
| 108 | +|`defaultcollelem`|Indicates that the property is an accessor function for an element of the default collection. For more information, see [defaultcollelem](/windows/win32/Midl/defaultcollelem) in the *MIDL Reference*.| |
| 109 | +|`displaybind`|Indicates that this property should be displayed to the user as bindable. For more information, see [displaybind](/windows/win32/Midl/displaybind) in the *MIDL Reference*.| |
| 110 | +|`hidden`|Indicates that the property exists but shouldn't be displayed in a user-oriented browser. For more information, see [hidden](/windows/win32/Midl/hidden) in the *MIDL Reference*.| |
| 111 | +|`immediatebind`|Indicates that the database will be notified immediately of all changes to this property of a data-bound object. For more information, see [immediatebind](/windows/win32/Midl/immediatebind) in the *MIDL Reference*.| |
| 112 | +|`local`|Specifies to the MIDL compiler that the property isn't remote. For more information, see [local](/windows/win32/Midl/local) in the *MIDL Reference*.| |
| 113 | +|`nonbrowsable`|Tags an interface or dispinterface member that shouldn't be displayed in a properties browser. For more information, see [nonbrowsable](/windows/win32/Midl/nonbrowsable) in the *MIDL Reference*.| |
| 114 | +|`requestedit`|Indicates that the property supports the `OnRequestEdit` notification. For more information, see [requestedit](/windows/win32/Midl/requestedit) in the *MIDL Reference*.| |
| 115 | +|`restricted`|Specifies that the property can't be called arbitrarily. For more information, see [restricted](/windows/win32/Midl/restricted) in the *MIDL Reference*.| |
| 116 | +|`source`|Indicates that a member of the property is a source of events. For more information, see [source](/windows/win32/Midl/source) in the *MIDL Reference*.| |
0 commit comments