Bewerken

Delen via


object attribute

The [object] interface attribute identifies a COM interface. (An interface attribute list that does not include the [object] attribute indicates a DCE RPC interface.)

[ 
    object, 
    uuid(string-uuid)
    [ , interface-attribute-list] 
] 
interface interface-name : base-interface
{
...    
}

Parameters

string-uuid

A UUID string generated by the Uuidgen utility. You can enclose the UUID string in quotes.

interface-attribute-list

Other attributes that apply to the interface as a whole.

interface-name

The name of the interface.

base-interface

The COM interface from which this interface derives. The base interface must be IUnknown, IDispatch, or another COM interface that derives, either directly or indirectly, from IUnknown or IDispatch.

Remarks

An interface attribute list for a COM interface must include the [uuid] attribute, but it cannot include the [version] attribute.

By default, compiling a COM interface with the MIDL compiler generates the files needed to build a proxy DLL. This DLL contains the code to support the use of the custom COM interface by both client applications and object servers. However, if the interface attribute list for a COM interface specifies the [local] attribute, the MIDL compiler generates only the interface header file.

The MIDL compiler automatically generates an interface data type for a COM interface. As an alternative, you can use typedef with the interface keyword to explicitly define an interface data type. The interface specification can then use the interface data type in function parameters and return values, struct and union members, and other type declarations. The following example illustrates the use of an automatically generated IStream data type:

[
    object, 
    uuid (ABCDEFOO-1234-1234-5678-ABCDEF123456)
] 
interface IStream : IUnknown
{ 
    typedef IStream * LPSTREAM; 
    // Other interface definition statements.
}

In a COM interface, all the interface member functions are assumed to be virtual functions. A virtual function has an implicit this pointer as the first parameter. The virtual function table contains an entry for each interface member function.

Non-[local] object interface member functions must have a return value of HRESULT or SCODE. (Note that earlier versions of MIDL allowed member functions to return void. However, beginning with MIDL version 3.0, returning void generates a compiler error.) Having a return value of HRESULT or SCODE means that if an exception is generated during a remote call, the generated proxies catch the exception and return the exception code in the return value. If your application can afford to ignore errors that occur during a remote procedure call, you can specify HRESULT as the return type without checking the return value after the call.

If you are recompiling an old application, changing the return types can introduce backward compatibility problems when the server sends the newly introduced result to the client. As an alternative to changing the return type, you can label the function that returns void with the [call_as] attribute, thus making it a local function. Then define a related remote function with the same parameters but with the return type of HRESULT. The local function can raise an exception based on that HRESULT value, if necessary.

The [object] attribute is not available when you compile using the MIDL compiler /osf switch.

Examples

[
    uuid(12345678-1234-1234-1234-123456789ABC), 
    object
] 
interface IMyInterface : IUnknown
{
    // Interface definition statements.
}

[
    uuid(87654321-1234-1234-1234-123456789ABC), 
    object, 
    local
] 
interface ILocalInterface : ISomeOldCOMInterface
{
    // Interface definition statements.
}

See also

call_as

Interface Definition (IDL) File

iid_is

interface

local

/osf

typedef

uuid

version