แก้ไข

แชร์ผ่าน


Attributes by Usage

This topic lists attributes according to the C++ language elements to which they apply.

If an attribute precedes an element that is not in the attribute's scope, the attribute block is treated as a comment.

Attribute Description
Module Attributes Applies to the module attribute.
Interface Attributes Applies to the __interface C++ keyword.
Class Attributes Applies to the C++ keyword.
Method Attributes Applies to the methods in a class, coclass, or interface.
Parameter Attributes Applies to parameters of a method in a class or interface.
Data Member Attributes Applies to the data members in a class, coclass, or interface.
Typedef, Enum, Union, and Struct Attributes Applies to the C++ keywords.
Array Attributes Applies to arrays or SAFEARRAYs.
Stand-Alone Attributes Operates more like a line of code but does not operate on a C++ keyword. Stand-alone attribute statements require a semicolon at the end of the line.
Custom Attributes Allows the user to extend metadata.

Module Attributes

The following attribute can only be applied to the module attribute.

Attribute Description
helpstringdll Specifies the name of the DLL to use to perform document string lookup (localization).

Interface Attributes

The following attributes apply to the interface (or __interface) C++ keyword.

Attribute Description
async_uuid Specifies the UUID that directs the MIDL compiler to define both synchronous and asynchronous versions of a COM interface.
custom Lets you define your own attributes.
dispinterface Places an interface in the .idl file as a dispatch interface.
dual Places an interface in the .idl file as a dual interface.
export Causes a data structure to be placed in the .idl file.
helpcontext Specifies a context ID that lets the user view information about this element in the Help file.
helpfile Sets the name of the Help file for a type library.
helpstring Specifies a character string that is used to describe the element to which it applies.
helpstringcontext Specifies the ID of a help topic in an .hlp or .chm file.
helpstringdll Specifies the name of the DLL to use to perform document string lookup (localization).
hidden Indicates that the item exists but should not be displayed in a user-oriented browser.
library_block Places a construct inside the .idl file's library block.
local Allows you to use the MIDL compiler as a header generator when used in the interface header. When used in an individual function, designates a local procedure for which no stubs are generated.
nonextensible Specifies that the IDispatch implementation includes only the properties and methods listed in the interface description and cannot be extended with additional members at run time. This attribute is only valid on a dual interface.
odl Identifies an interface as an Object Description Language (ODL) interface.
object Identifies a custom interface.
oleautomation Indicates that an interface is compatible with Automation.
pointer_default Specifies the default pointer attribute for all pointers except top-level pointers that appear in parameter lists.
ptr Designates a pointer as a full pointer.
restricted Designates which members of the library cannot be called arbitrarily.
uuid Provides the unique ID for the library

You must observe these rules for defining an interface:

  • Default calling convention is __stdcall.

  • A GUID is supplied for you if you do not supply one.

  • No overloaded methods are allowed.

When not specifying the uuid attribute and using the same interface name in different attribute projects, the same GUID is generated.

See also

C++ Attributes for COM and .NET
Attributes by Group
Attributes Alphabetical Reference