Skip to content

Commit 9102931

Browse files
TylerMSFTTylerMSFT
authored andcommitted
edit pass
1 parent e967edf commit 9102931

File tree

1 file changed

+53
-47
lines changed

1 file changed

+53
-47
lines changed
Lines changed: 53 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,107 @@
11
---
2-
description: "Learn more about: Use a Microsoft Visual Studio wizard to add a method to an IDL interface in your MFC or ATL project"
2+
description: "Learn more about: Use the Microsoft Visual Studio Add IDL MFC wizard to add a method to an IDL interface in your MFC or ATL project"
33
title: "Add an IDL MFC method"
4-
ms.date: "03/30/2022"
4+
ms.date: "03/31/2022"
55
f1_keywords: ["vc.codewiz.method.overview", "vc.codewiz.method.idlattrib"]
66
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"]
77
ms.custom: devdivchpfy22
88
---
99

1010
# Add an IDL MFC method
1111

12-
The **Add IDL MFC Method** wizard adds a method to an interface defined in an Interface Definition Library (IDL) in a Microsoft Framework Class (MFC) project. To use the **Add IDL MFC Method** wizard you must be in an MFC Project, ActiveX project or an ATL project that supports MFC. For example, if you have a Microsoft ActiveX control project, and you open the IDL library, using following procedure you can add the method to interface. If the project contains a class associated with the interface, the wizard will add the method to the class, too.
12+
The **Add IDL MFC Method** wizard adds a method to an Interface Definition Library (IDL) interface defined in your Microsoft Framework Class (MFC) project. If the project contains a class associated with the interface, the wizard also adds the method to the class.
1313

14-
This wizard differs from the [Add Method](../../ide/adding-a-method-visual-cpp.md) wizard (which adds a method to an IDL interface) in the following ways:
14+
To use the this wizard, you must be in an MFC Project, ActiveX project, or an ATL project that supports MFC. For example, if you have a Microsoft ActiveX control project, you can use the following procedure to add a method to an IDL interface in the solution.
15+
16+
This wizard differs from the [Add Method](../../ide/adding-a-method-visual-cpp.md) wizard (which adds a method to an IDL interface) in the following ways:
1517

1618
- It's specific to MFC, ActiveX, or ATL projects that support MFC. For ATL projects that don't support MFC, only the **Add Method** wizard is available.
19+
- It adds the following entries if a Dispatch map is found in the project:
1720

18-
- It adds the following entries if a Dispatch map is found in the project.
1921
```cpp
20-
BEGIN_DISPATCH_MAP(CMFCApplication2Doc, CDocument)
21-
DISP_FUNCTION_ID(CMFCApplication2Doc, "methodName", dispidmethodName, internalName, VT_EMPTY, VTS_NONE)
22-
END_DISPATCH_MAP()
22+
BEGIN_DISPATCH_MAP(CMFCApplication2Doc, CDocument)
23+
DISP_FUNCTION_ID(CMFCApplication2Doc, "methodName", dispidmethodName, internalName, VT_EMPTY, VTS_NONE)
24+
END_DISPATCH_MAP()
2325
```
24-
- It generates the following associated method implementations:
26+
27+
- It generates the following associated method implementation:
28+
2529
```cpp
26-
void CMFCApplication2Doc::internalName()
27-
{
28-
AFX_MANAGE_STATE(AfxGetAppModuleState());
29-
// TODO: Add your dispatch handler code here
30-
}
30+
void CMFCApplication2Doc::internalName()
31+
{
32+
AFX_MANAGE_STATE(AfxGetAppModuleState());
33+
// TODO: Add your dispatch handler code here
34+
}
3135
```
32-
For ATL projects that don't support MFC, this wizard isn't available.
3336

34-
## Add a method to your interface
37+
## Add a method to an interface
3538

3639
1. On the **View** menu, choose **Class View**.
3740

3841
1. In **Class View**, expand the project node to display the interface to which you want to add the method.
3942

4043
1. Right-click the name of the interface.
4144

42-
1. On the shortcut menu, choose **Add**, and then choose **Add Method**.
45+
1. On the shortcut menu, choose **Add** and then choose **Add Method**.
4346

44-
1. In the **Add IDL MFC Method** wizard, provide the information to create the method.
47+
1. In the **Add IDL MFC Method** wizard, provide information about the method.
4548

4649
1. Select **OK** to add the method.
4750

4851
### UI element list
4952

50-
The following section describes the UI that you'll use to add a method:
53+
The following section describes the Add IDL MFC Method wizard UI:
5154

52-
:::image type="content" source="../reference/media/add-idl-mfc-method-wizard.png" alt-text="Add IDL MFC method screenshot.":::
55+
:::image type="content" source="../reference/media/add-idl-mfc-method-wizard.png" alt-text="Wizard UI. Method name:DoClick, Internal name:DoClick, Return type:void, Method type:custom, Parameters:long l, char C, Attributes id:1.":::
5356

5457
- **Method name**
5558

56-
Set the name for the method.
59+
Set the name for the method. The following table describes the method name options depending on the kind of interface:
5760

58-
|Interface type|Description|
61+
|Interface kind|Method name|
5962
|--------------------|-----------------|
6063
|ATL dual interface, custom interface, and local custom interface|Provide your own method name.|
61-
|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**, and it can't be changed.|
62-
|MFC ActiveX control dispinterface|Provide your own or select either of the stock methods [DoClick](../reference/colecontrol-class.md#doclick) and [Refresh](../reference/colecontrol-class.md#refresh). For more information, see [MFC ActiveX controls: Adding stock methods](../mfc-activex-controls-adding-stock-methods.md).|
64+
|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 return type appears in **Return type**, and can't be changed.|
65+
|MFC ActiveX control dispinterface|Provide your own method name or select one of the stock methods: [DoClick](../reference/colecontrol-class.md#doclick) or [Refresh](../reference/colecontrol-class.md#refresh). For more information about stock methods, see [MFC ActiveX controls: Adding stock methods](../mfc-activex-controls-adding-stock-methods.md).|
6366

6467
- **Internal name**
6568

66-
Only available for custom methods (if **Method type** is selected as custom) added to an MFC dispinterface. The name that will be used in the dispatch map, the header (.h) file, and the implementation (.cpp) file. By default, this name is the same as **Method name**.
69+
Only available when **Method type** is **custom**. This is the name that will be used in the dispatch map, the header (.h) file, and the implementation (.cpp) file. By default, this name is the same as **Method name**. It is added to the MFC dispinterface.
6770

68-
You can change the method name according to the following table if you are adding the method to an MFC dispinterface or MFC ActiveX control dispinterface.
71+
If you're adding the method to an MFC or MFC ActiveX control dispinterface, you can change the method name as described by the following table:
6972

70-
|Interface type|Description|
73+
|Interface type|Internal name|
7174
|--------------------|-----------------|
7275
|ATL dual interface, custom interface, and local custom interface|Not available.|
7376
|MFC dispinterface|Set to the method name by default. You can edit the internal name.|
7477
|MFC ActiveX control dispinterface|You can set the internal name only for custom methods. Stock methods don't use an internal name.|
7578

7679
- **Return type**
7780

78-
The data type returned by the method. The standard way to return error codes from methods defined in an interface is with a `HRESULT`.
81+
The data type returned by the method. The standard return type for interface methods is `HRESULT`.
82+
83+
If the interface is a dual interface or a custom interface, only the `HRESULT` return type is allowed.
7984

80-
If the interface type is dual interface or custom interface, only `HRESULT` return type is allowed. You can set the data type according to the interface type, as defined in the following table:
85+
You can set the data type according to the kind of interface the method is being added to, as described in the following table:
8186

82-
|Interface type|Description|
87+
|Interface kind|Return type|
8388
|--------------------|-----------------|
8489
|Dual interface|`HRESULT`. Unchangeable.|
8590
|Custom interface|`HRESULT`. Unchangeable.|
86-
|Local custom interface|Provide your own return type or select from the list.|
87-
|Dispinterface|Provide your own return type or select from the list.|
88-
|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.|
91+
|Local custom interface|Provide your own return type or select one from the list.|
92+
|Dispinterface|Provide your own return type or select one from the list.|
93+
|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.|
8994

9095
- **Method type**
9196

92-
Available only for MFC ActiveX controls. Unavailable if you provide a method name in **Method name** rather than selecting a method from the list.
97+
Available only for MFC ActiveX controls. Unavailable if you provided a method name in **Method name** rather than selecting a method from the list.
9398

94-
If you select one of the methods in the **Method name** list, select either the stock implementation or a custom implementation.
99+
If you select one of the methods in the **Method name** list, in the **Method type** drop-down select either the **Stock** or **Custom** implementation. This affects the return type and method implementation that the wizard provides, as described in the following table:
95100

96101
|Method type|Description|
97102
|-----------------|-----------------|
98-
|**Stock**|The default. Inserts the default implementation of the method you select in the **Method name** list. **Return type** is unchangeable if you select **Stock**.|
99-
|**Custom**|You provide a custom implementation for the method selected in **Method name**. You can provide your own return type, or select one from the **Return type** list|
103+
|**Stock**|The default. Inserts the default implementation of the method selected in the **Method name** list. **Return type** is unchangeable if you select **Stock**.|
104+
|**Custom**|You provide a custom implementation for the method selected in **Method name**. You can provide your own return type or select one from the **Return type** list.|
100105

101106
- **Parameters**
102107

@@ -106,7 +111,7 @@ The following section describes the UI that you'll use to add a method:
106111

107112
Add a parameter. In **Parameters**, type the parameter type, name, and any modifiers. For example, `int x`, and choose **OK**.
108113

109-
If you don't provide a parameter name, the wizard ignores any parameter attributes (ATL only) or **Parameter type** selections.
114+
If you don't provide a parameter name, the wizard ignores any **Parameter type** selections; and for ATL projects, the parameter attributes are also ignored.
110115

111116
- **x**
112117

@@ -116,22 +121,23 @@ The following section describes the UI that you'll use to add a method:
116121

117122
Edit the selected parameter.
118123

119-
- `id`
124+
- **`id`**
120125

121-
Sets the numeric ID that identifies the method. For more information, see [id](/windows/win32/Midl/id) in the *MIDL Reference*.
126+
Sets the numeric ID that identifies the method. For more information, see [id](/windows/win32/midl/id) in the [MIDL reference](/windows/win32/midl/midl-language-reference.md).
122127

123-
- `call_as`
128+
- **`call_as`**
124129

125-
Specifies the name of the remote method to map to this local method. For more information, see [call_as](/windows/win32/Midl/call-as) in the *MIDL Reference*.
130+
Specifies the name of the remote method to map to this local method. For more information, see [call_as](/windows/win32/midl/call-as) in the [MIDL reference](/windows/win32/midl/midl-language-reference.md).
126131

127-
- `helpcontext`
132+
- **`helpcontext`**
128133

129-
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*.
134+
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](/windows/win32/midl/midl-language-reference.md).
130135

131-
- `helpstring`
136+
- **`helpstring`**
132137

133-
Specifies a text that describes the associated element. By default its *Method name*. For more information, see [helpstring](/windows/win32/Midl/helpstring) in the *MIDL Reference*.
138+
Specifies a text that describes the associated element. By default its *Method name*. For more information, see [helpstring](/windows/win32/Midl/helpstring) in the [MIDL reference](/windows/win32/midl/midl-language-reference.md).
134139

135140
## See also
136141

137-
[Add Method ](../../ide/adding-a-method-visual-cpp.md)
142+
[Add method wizard](../../ide/adding-a-method-visual-cpp.md)\
143+
[MFC wizards and dialog boxes](mfc-wizards-and-dialog-boxes)

0 commit comments

Comments
 (0)