Skip to content

Commit 37d86ab

Browse files
authored
Merge pull request #4175 from rachana-satao/RAS-cpp-US1921552-1
new article- Add an IDL MFC method
2 parents f8c4583 + 2241c0b commit 37d86ab

File tree

4 files changed

+147
-1
lines changed

4 files changed

+147
-1
lines changed
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
---
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"
3+
title: "Add an IDL MFC method"
4+
ms.date: "04/01/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+
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.
13+
14+
To use 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:
17+
18+
- 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:
20+
21+
```cpp
22+
BEGIN_DISPATCH_MAP(CMFCApplication2Doc, CDocument)
23+
DISP_FUNCTION_ID(CMFCApplication2Doc, "methodName", dispidmethodName, internalName, VT_EMPTY, VTS_NONE)
24+
END_DISPATCH_MAP()
25+
```
26+
27+
- It generates the following associated method implementation:
28+
29+
```cpp
30+
void CMFCApplication2Doc::internalName()
31+
{
32+
AFX_MANAGE_STATE(AfxGetAppModuleState());
33+
// TODO: Add your dispatch handler code here
34+
}
35+
```
36+
37+
## Add a method to an interface
38+
39+
1. On the **View** menu, select **Class View**.
40+
41+
1. In **Class View**, expand the project node to display the interface to which you want to add the method.
42+
43+
1. Right-click the name of the interface.
44+
45+
1. On the shortcut menu, select **Add** and then select **Add Method**.
46+
47+
1. In the **Add IDL MFC Method** wizard, provide information about the method.
48+
49+
1. Select **OK** to add the method.
50+
51+
### UI element list
52+
53+
The following section describes the Add IDL MFC Method wizard UI:
54+
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.":::
56+
57+
- **Method name**
58+
59+
Set the name for the method. The following table describes the method name options depending on the kind of interface:
60+
61+
|Interface kind|Method name|
62+
|--------------------|-----------------|
63+
|ATL dual interface, custom interface, and local custom interface|Provide your own method name.|
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).|
66+
67+
- **Internal name**
68+
69+
Only available when **Method type** is **custom**. **Internal name** 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's added to the MFC dispinterface.
70+
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:
72+
73+
|Interface type|Internal name|
74+
|--------------------|-----------------|
75+
|ATL dual interface, custom interface, and local custom interface|Not available.|
76+
|MFC dispinterface|Set to the method name by default. You can edit the internal name.|
77+
|MFC ActiveX control dispinterface|You can set the internal name only for custom methods. Stock methods don't use an internal name.|
78+
79+
- **Return type**
80+
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.
84+
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:
86+
87+
|Interface kind|Return type|
88+
|--------------------|-----------------|
89+
|Dual interface|`HRESULT`. Unchangeable.|
90+
|Custom interface|`HRESULT`. Unchangeable.|
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.|
94+
95+
- **Method type**
96+
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.
98+
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. The selection of the method affects the return type and method implementation that the wizard provides, as described in the following table:
100+
101+
|Method type|Description|
102+
|-----------------|-----------------|
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.|
105+
106+
- **Parameters**
107+
108+
Displays the method's parameters, modifiers, and types. The wizard updates the **Parameters** list as you add parameters.
109+
110+
- **+**
111+
112+
Add a parameter. In **Parameters**, type the parameter type, name, and any modifiers. For example, `int x`, and choose **OK**.
113+
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.
115+
116+
- **x**
117+
118+
Removes the selected parameter from the **Parameters** list.
119+
120+
- **Pencil icon**
121+
122+
Edit the selected parameter.
123+
124+
- **`id`**
125+
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).
127+
128+
- **`call_as`**
129+
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).
131+
132+
- **`helpcontext`**
133+
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).
135+
136+
- **`helpstring`**
137+
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).
139+
140+
## See also
141+
142+
[Add method wizard](../../ide/adding-a-method-visual-cpp.md)\
143+
[MFC wizards and dialog boxes](mfc-wizards-and-dialog-boxes.md)
Loading

docs/mfc/reference/mfc-wizards-and-dialog-boxes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ The Microsoft Foundation Class (MFC) wizards generate boilerplate code for vario
2323
|[ATL Support in an MFC Project](../../mfc/reference/adding-atl-support-to-your-mfc-project.md)|Creates headers and macros that are required by the Active Template Library (ATL).|
2424
|[MFC Class Wizard](../../mfc/reference/mfc-class-wizard.md)|Creates an .h file and a .cpp file.|
2525
|[MFC Desktop Applications](../../mfc/mfc-desktop-applications.md)|Links to the MFC documentation.|
26+
|[IDL MFC Method Wizard](../../mfc/reference/add-idl-mfc-method-wizard.md)| Add a method to an IDL interface in an MFC project.|

docs/mfc/toc.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2916,5 +2916,7 @@ items:
29162916
href: reference/adding-atl-support-to-your-mfc-project.md
29172917
- name: Details of ATL support added by the ATL wizard
29182918
href: reference/details-of-atl-support-added-by-the-atl-wizard.md
2919+
- name: Add a method to an IDL interface in a MFC project
2920+
href: reference/add-idl-mfc-method-wizard.md
29192921
- name: MFC class wizard
2920-
href: reference/mfc-class-wizard.md
2922+
href: reference/mfc-class-wizard.md

0 commit comments

Comments
 (0)