//========================================================================
//TITLE:
// COM宏小結
//AUTHOR:
// norains
//DATE:
// Wednesday 24-October-2007
//Environment:
// EVC4.0 + Windows CE 5.0 Standard SDK
//========================================================================
COM接口用到的宏主要有六個:STDMETHOD,STDMETHODIMP,STDMETHOD_,STDMETHODIMP_,SUCCEEDED,FAILED.
我們首先來看看這六個宏的定義:
STDMETHOD:
#define STDMETHOD(method) virtual HRESULT STDMETHODCALLTYPE method
#ifdef _WIN32 // Win32 doesn't support __export
#define STDMETHODCALLTYPE __stdcall
#else
#define STDMETHODCALLTYPE __export __stdcall
#endif
STDMETHODIMP:
#define STDMETHODIMP HRESULT STDMETHODCALLTYPE
#ifdef _WIN32 // Win32 doesn't support __export
#define STDMETHODCALLTYPE __stdcall
#else
#define STDMETHODCALLTYPE __export __stdcall
#endif
STDMETHOD_:
#define STDMETHOD_(type,method) virtual type STDMETHODCALLTYPE method
#ifdef _WIN32 // Win32 doesn't support __export
#define STDMETHODCALLTYPE __stdcall
#else
#define STDMETHODCALLTYPE __export __stdcall
#endif
STDMETHODIMP_:
#define STDMETHODIMP_(type) type STDMETHODCALLTYPE
#ifdef _WIN32 // Win32 doesn't support __export
#define STDMETHODCALLTYPE __stdcall
#else
#define STDMETHODCALLTYPE __export __stdcall
#endif
SUCCEEDED:
#define SUCCEEDED(Status) ((HRESULT)(Status) >= 0)
FAILED:
#define FAILED(Status) ((HRESULT)(Status)<0)
由定義我們可以看出兩點:
1)STDMETHOD和STDMETHODIMP,STDMETHOD_和STDMETHODIMP_分別為一對,SUCCEEDED和FAILED為相反.
2)STDMETHOD只是STDMETHOD_的簡化版.
比如這兩個語句互為等價關系:
STDMETHOD (QueryInterface) (REFIID riid, LPVOID * ppv);
STDMETHOD_ (HRESULT,