Skip to content

Commit cd83167

Browse files
authored
Merge pull request #4189 from rachana-satao/RAS-cpp-US1921538-2
New article - Add IDL Method Wizard
2 parents 0bdc759 + 7d05532 commit cd83167

3 files changed

Lines changed: 119 additions & 0 deletions

File tree

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
---
2+
description: "Learn more about: Use a Microsoft Visual Studio wizard to add a method to an interface definition language (IDL) interface in your project"
3+
title: "Add an IDL method"
4+
ms.date: "04/13/2022"
5+
f1_keywords: ["vc.codewiz.method.overview", "vc.codewiz.method.idlattrib"]
6+
helpviewer_keywords: ["add IDL method wizard [C++]", "IDL methods [C++], adding", "methods [C++], adding using wizards", "IDL attributes, add an IDL method wizard"]
7+
ms.custom: devdivchpfy22
8+
---
9+
10+
# Add an IDL method
11+
12+
The **Add IDL Method** wizard adds a method to an Interface Definition Library (IDL) interface, such as in an ATL project that contains an IDL file. This wizard isn't available in projects that support MFC.
13+
14+
This wizard differs from the [**Add method**](adding-a-method-visual-cpp.md) wizard and the [**Add IDL MFC method**](../mfc/reference/add-idl-mfc-method-wizard.md) wizard in the following ways:
15+
16+
- The **Add method** wizard adds a method to an interface in your project and can update the class associated with the interface.
17+
- The **Add IDL MFC method** wizard is specific to MFC, ActiveX, or ATL projects that support MFC.
18+
19+
## Add a method to your IDL interface
20+
21+
1. On the **View** menu, select **Class View**.
22+
23+
1. In the **Class View** pane, expand the project node to display the IDL interface (`.idl`file) to which you want to add the method.
24+
25+
1. Right-click the name of the interface.
26+
27+
1. On the shortcut menu, select **Add** > **Add Method**.
28+
29+
1. In the **Add IDL Method** wizard, provide the information to create the method.
30+
31+
1. Select **OK** to add the method.
32+
33+
### User Interface element list
34+
35+
The following section describes the wizard interface that you'll use to add a method:
36+
37+
:::image type="content" source= "media/add-interface-definition-library-method-wizard.png" alt-text="Screenshot of adding a method using the wizard. Shows two parameters: [ in ] int i and [ in ] float f. Return type is HRESULT. Infer in out parameter values from type is selected.":::
38+
39+
- **Method name**
40+
41+
Provide a name for the method.
42+
43+
- **Return type**
44+
45+
The data type returned by the method. The standard way to return error codes from methods defined in an interface is with a `HRESULT`.
46+
47+
The following table describes the different kinds of interfaces that you can add a method to, and the allowed return type. For dual and custom interfaces, the return type must be `HRESULT` and the wizard won't allow you to change it.
48+
49+
|Interface kind|Return type|
50+
|--------------------|-----------------|
51+
|[Dual interface](/windows/win32/winauto/dual-interfaces--iaccessible-and-idispatch)|`HRESULT`. Unchangeable.|
52+
|[Custom interface](/windows/win32/winauto/custom-user-interface-elements)|`HRESULT`. Unchangeable.|
53+
|Local custom interface|Provide your own return type or select it from the drop-down list.|
54+
|[Dispinterface](/windows/win32/midl/dispinterface)|Provide your own return type or select it from the drop-down list.|
55+
56+
- **Parameters**
57+
58+
Displays the method's parameters, modifiers, and types.
59+
60+
- **+**
61+
62+
Add a parameter. In **Parameters**, type the parameter type, name, and any modifiers. For example, `[in] int i`, and choose **OK**.
63+
64+
- **x**
65+
66+
Removes the selected parameter from the **Parameters** list.
67+
68+
- **Infer in/out parameters values from types**
69+
70+
Inserts the `[in]` or `[out]` attribute based on the parameter's type.
71+
72+
- **Set the last parameter as the return value (retval)**
73+
74+
The last parameter will be treated as the method's return value.
75+
76+
- **Attributes**
77+
78+
The following attributes are also described in the [MIDL Reference](/windows/win32/midl/midl-language-reference.md).
79+
80+
- `id`
81+
82+
Sets the numeric ID that identifies the method. For more information, see [`id`](/windows/win32/Midl/id).
83+
84+
- `call_as`
85+
86+
Specifies the name of the remote method to map to this local method. For more information, see [`call_as`](/windows/win32/Midl/call-as).
87+
88+
- `helpcontext`
89+
90+
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).
91+
92+
- `helpstring`
93+
94+
Specifies the character string used to describe the element to which it applies. For more information, see [`helpstring`](/windows/win32/Midl/helpstring).
95+
96+
- **Additional attributes**
97+
98+
- `hidden`
99+
100+
Indicates that the item exists but shouldn't be displayed in a user-oriented browser. For more information, see [`hidden`](/windows/win32/Midl/hidden).
101+
102+
- `local`
103+
104+
Specifies that an interface or function isn't remote. For more information, see [`local`](/windows/win32/Midl/local).
105+
106+
- `restricted`
107+
108+
Specifies that a library, or member of a module, interface, or dispinterface can't be called arbitrarily. For more information, see [`restricted`](/windows/win32/Midl/restricted).
109+
110+
- `source`
111+
112+
Indicates that a member of a [`coclass`](/windows/win32/Midl/coclass), property, or method is a source of events. For a member of a `coclass`, this attribute means that the member is called rather than implemented. For more information, see [`source`](/windows/win32/Midl/source).
113+
114+
## See also
115+
116+
[Add a method wizard](adding-a-method-visual-cpp.md)\
117+
[Add an IDL MFC method wizard](../mfc/reference/add-idl-mfc-method-wizard.md)
24.9 KB
Loading

docs/ide/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ items:
7878
href: ../ide/adding-a-member-variable-visual-cpp.md
7979
- name: Add a method
8080
href: ../ide/adding-a-method-visual-cpp.md
81+
- name: Add an IDL method
82+
href: ../ide/add-interface-definition-library-method-wizard.md
8183
- name: Add a property
8284
href: ../ide/adding-a-property-visual-cpp.md
8385
- name: Add an IDL property

0 commit comments

Comments
 (0)