顯示具有 windows com 標籤的文章。 顯示所有文章
顯示具有 windows com 標籤的文章。 顯示所有文章

2009年9月21日 星期一

how to use a com object

obtain object's interface

Call QueryInterface to Request a New Interface:

Interface Definition Language (IDL)

Interface definition language (IDL) files are a structured way to define interfaces and objects.

ex:
[
object,
uuid(),
helpstring("IWDFObject Interface"),
local,
restricted,
pointer_default(unique)
]
interface IWDFObject : IUnknown
{

HRESULT
DeleteWdfObject(
void
);

HRESULT
AssignContext(
[in, unique, annotation("__in_opt")] IObjectCleanup * pCleanupCallback,
[in, unique, annotation("__in_opt")] void * pContext
);

HRESULT
RetrieveContext(
[out, annotation("__out")] void ** ppvContext
);

void
AcquireLock(
void
);

void
ReleaseLock(
void
);
};

Active Template Library (ATL)

a set of template-based C++ classes that are often used to simplify the creation of COM objects

HRESULT & com

a 32-bit type
three field:
(1) severity bit:
indicate success or error
(2) facility
(3) return code

success codes are assigned names that begin with S, such as S_OK
failure codes are assigned names that begin with E

use FAILED(hr) or SUCCEEDED(hr) to check success or failure

GUID & com

Globally unique identifiers (GUIDs)
1.Interface ID (IID)
a GUID that uniquely identifies a particular COM interface

2.Class ID (CLSID)
a GUID that uniquely identifies a particular COM object

com & interface

An interface is the COM mechanism for exposing public methods on an object

If an object exposes a standard interface, the object must implement every method in that interface.

A typical COM object exposes at least two and sometimes many interfaces.

IUnknown
IUnknown is the key COM interface. Every COM object must expose this interface