|
| 1 | +--- |
| 2 | +description: "Learn more about: Add an IDL MFC method to an interface in your MFC project" |
| 3 | +title: "Add an IDL MFC method" |
| 4 | +ms.date: "03/14/2022" |
| 5 | +f1_keywords: ["vc.codewiz.method.overview", "vc.codewiz.method.idlattrib"] |
| 6 | +helpviewer_keywords: ["add IDL MFC method wizard [C++]", "IDL MFC methods [C++], adding", "methods [C++], adding using wizards", "IDL attributes, add an IDL MFC method wizard"] |
| 7 | +ms.custom: devdivchpfy22 |
| 8 | +--- |
| 9 | + |
| 10 | +# Add an IDL MFC method |
| 11 | + |
| 12 | +You can use the [Add an IDL MFC method wizard](#add-an-idl-mfc-method-wizard) to add an IDL MFC method to an interface in your MFC project. If the project contains a class associated with the interface, the wizard modifies the class, too. |
| 13 | + |
| 14 | +:::image type="content" source="../reference/media/add-idl-mfc-method-wizard.png" alt-text="Add an IDL MFC method screenshot."::: |
| 15 | + |
| 16 | +**To add a method to your object:** |
| 17 | + |
| 18 | +1. In **Class View**, expand the project node to display the interface to which you want to add the method. |
| 19 | + |
| 20 | +1. Right-click the name of the interface. |
| 21 | + |
| 22 | +1. On the shortcut menu, choose **Add**, and then choose **Add Method**. |
| 23 | + |
| 24 | +1. In the Add Method Wizard, provide the information to create the method. |
| 25 | + |
| 26 | +1. Specify any interface definition language settings for this method in the [IDL attributes](#idl-attributes-add-method-wizard) page of the wizard. |
| 27 | + |
| 28 | +1. Select **OK** to add the method. |
| 29 | + |
| 30 | +## In this section |
| 31 | + |
| 32 | +- [Add an IDL MFC method wizard](#add-an-idl-mfc-method-wizard) |
| 33 | +- [IDL attributes, add method wizard](#idl-attributes-add-method-wizard) |
| 34 | + |
| 35 | +## Add an IDL MFC method wizard |
| 36 | + |
| 37 | +Use this wizard to add an IDL MFC method to an interface. |
| 38 | + |
| 39 | +### Names |
| 40 | + |
| 41 | +- **Method name** |
| 42 | + |
| 43 | + Sets the name for the method. |
| 44 | + |
| 45 | + |Interface type|Description| |
| 46 | + |--------------------|-----------------| |
| 47 | + |ATL dual interface, custom interface, and local custom interface|Provide your own method name.| |
| 48 | + |MFC dispinterface|Provide your own method name or select a suggested method name from the list. If you select a name from the list, the appropriate value appears in the **Return type** box, and it's unchangeable.| |
| 49 | + |MFC ActiveX control dispinterface|Provide your own or select either of the stock methods [DoClick](../mfc/reference/colecontrol-class.md#doclick) and [Refresh](../mfc/reference/colecontrol-class.md#refresh). For more information, see [MFC ActiveX controls: Adding stock methods](../mfc/mfc-activex-controls-adding-stock-methods.md).| |
| 50 | + |
| 51 | +- **Internal name** |
| 52 | + |
| 53 | + Available for only custom methods added to an MFC dispinterface. Sets the name used in the dispatch map, the header (`.h`) file, and the implementation (`.cpp`) file. By default, this name is the same as **Method name**. You can change the method name if you're working with an MFC dispinterface or if you're adding a custom method to an MFC ActiveX control dispinterface. |
| 54 | + |
| 55 | + |Interface type|Description| |
| 56 | + |--------------------|-----------------| |
| 57 | + |ATL dual interface, custom interface, and local custom interface|Not available.| |
| 58 | + |MFC dispinterface|Set to the method name by default. You can edit the internal name.| |
| 59 | + |MFC ActiveX control dispinterface|You can set the internal name only for custom methods. Stock methods don't use an internal name.| |
| 60 | + |
| 61 | +- **Return type** |
| 62 | + |
| 63 | + The data type returned by the method. `HRESULT` is recommended for all interface types, it provides a standard way to return errors. |
| 64 | + |
| 65 | + |Interface type|Description| |
| 66 | + |--------------------|-----------------| |
| 67 | + |Dual interface|`HRESULT`. Unchangeable.| |
| 68 | + |Custom interface|`HRESULT`. Unchangeable.| |
| 69 | + |Local custom interface|Provide your own return type or select from the list.| |
| 70 | + |Dispinterface|Provide your own return type or select from the list.| |
| 71 | + |MFC ActiveX control dispinterface|If you implement a stock method, the return type is set to the appropriate value and is unchangeable. If you select a method from the **Method name** list and select **Custom** under **Select method type**, select a return type from the list.| |
| 72 | + |
| 73 | +- **Method type** |
| 74 | + |
| 75 | + Available only for MFC ActiveX controls. If you provide a method name in the **Method name** box, rather than selecting a method from the list, this box is unavailable. |
| 76 | + |
| 77 | + If you select one of the methods in the **Method name** list, select either the stock implementation or a custom implementation. |
| 78 | + |
| 79 | + |Method type|Description| |
| 80 | + |-----------------|-----------------| |
| 81 | + |**Stock**|The default. Inserts the stock implementation of the method you select in the **Method name** list. **Return type** is unchangeable if you select **Stock**.| |
| 82 | + |**Custom**|Inserts a stub implementation of the method selected in the **Method name** list. For custom method types, you can provide your own return type, or you can select one from the **Return type** list.| |
| 83 | + |
| 84 | +- **Parameter type** |
| 85 | + |
| 86 | + Sets the data type of the parameter. You can type it or select the type from the list. |
| 87 | + |
| 88 | +- **Parameter name** |
| 89 | + |
| 90 | + Sets the name of a parameter. Select **+** to add the parameter in **parameters**. If you don't provide a parameter name, the wizard ignores any parameter attributes (ATL only) or **Parameter type** selections. |
| 91 | + |
| 92 | + > [!NOTE] |
| 93 | + > If you supply a parameter name and then select **OK** before you select **+**, the parameter isn't added to the method. You must find the method and insert the parameter manually. |
| 94 | +
|
| 95 | +- **+** |
| 96 | + |
| 97 | + Adds the parameter to the list of **parameters**. Specify the parameter name in **Parameter name**, and its type and parameter attributes in **Parameters**. |
| 98 | + |
| 99 | +- **x** |
| 100 | + |
| 101 | + Removes the selected parameter from the **Parameters** list. |
| 102 | + |
| 103 | +- **Parameters** |
| 104 | + |
| 105 | + Displays all of the methods parameters, modifiers, and types. The wizard updates the **Parameters** list as you add parameters. |
| 106 | + |
| 107 | +## IDL attributes, add method wizard |
| 108 | + |
| 109 | +Use this page of the Add Method Wizard to specify any interface definition language (IDL) settings for the method. |
| 110 | + |
| 111 | +- `id` |
| 112 | + |
| 113 | + Sets the numerical ID that identifies the method. For more information, see [id](/windows/win32/Midl/id) in the *MIDL Reference*. |
| 114 | + |
| 115 | +- `call_as` |
| 116 | + |
| 117 | + Specifies the name of a remote method to which this local method can be mapped. For more information, see [call_as](/windows/win32/Midl/call-as) in the *MIDL Reference*. |
| 118 | + |
| 119 | +- `helpcontext` |
| 120 | + |
| 121 | + Specifies a context ID that lets the user view information about this method in the Help file. For more information, see [helpcontext](/windows/win32/Midl/helpcontext) in the *MIDL Reference*. |
| 122 | + |
| 123 | +- `helpstring` |
| 124 | + |
| 125 | + Specifies a character string that's used to describe the element to which it applies. It's set by default to "method *Method name*." For more information, see [helpstring](/windows/win32/Midl/helpstring) in the *MIDL Reference*. |
0 commit comments