object
[
object, uuid(string-uuid)[ , interface-attribute-list]
]
interface interface-name : base-interface
string-uuid
Specifies a
UUID string generated by the uuidgen utility. You can enclose the UUID
string in quotes, except when you use the MIDL compiler switch /osf.
interface-attribute-list
Specifies
other attributes that apply to the interface as a whole.
interface-name
Specifies the
name of the interface.
base-interface
Specifies the
name of an OLE interface from which this derived interface inherits member
functions, status codes, and interface attributes. All OLE interfaces are
derived from the IUnknown interface or another OLE interface.
Remarks
The object
interface attribute identifies a custom OLE interface. An interface attribute
list that does not include the object attribute indicates a DCE RPC
interface. An interface attribute list for an OLE interface must include the uuid
attribute, but it cannot include the version attribute.
By default,
compiling an OLE 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
OLE interface by both client applications and object servers. However, if the
interface attribute list for an OLE interface specifies the local
attribute, the MIDL compiler generates only the interface header file.
The MIDL
compiler automatically generates an interface data type for an OLE 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;
}
In an OLE
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.
See Also