Recently when using this function doesn't know what's the meaning of the function of the parameters, more do not know is how to use this function, would like to ask which can help the younger brother I solve, and appreciate,
CodePudding user response:
STDMETHOD: defines a returned HRESULT types of virtual method,# define STDMETHOD (method) virtual HRESULT STDMETHODCALLTYPE method
Among them, the STDMETHODCALLTYPE defines the method of parameter type, as follows:
# ifdef _WIN32//Win32 doesn 't support __export
# define STDMETHODCALLTYPE __stdcall
# the else
# define STDMETHODCALLTYPE __export __stdcall
# endif [1]
So when writing a function STDMETHOD (op1 (int I))
Unfolds as: virtual HRESULT __stdcall op1 (int I);
So this just a virtual function op1, of course the virtual function can only be in the interface definition, so STDMETHOD macro is used to define the interface to use, in a header file,
STDMETHOD_ : defines a return to specify the type of virtual method,
# define STDMETHOD_ (type, method) virtual type STDMETHODCALLTYPE method
For example: STDMETHOD_ (ULONG, release) after () is a virtual ULONG STDMETHODCALLTYPE release () STDMETHODCALLTYPE macro expansion is __stdcall,
STDMETHODIMP: defines a returned HRESULT interface function,
# define STDMETHODIMP HRESULT STDMETHODCALLTYPE
STDMETHODIMP_ : defines a function returns the specified type interface,
# define STDMETHODIMP_ (type) type STDMETHODCALLTYPE
2
Example
Edit
# undef INTERFACE
# define INTERFACE ISomeInterface
DECLARE_INTERFACE_ (ISomeInterface IUnknown)
{
STDMETHOD (QueryInterface) (THIS_REFIID riid,
Void * * ppvObj) PURE;
STDMETHOD_ ULONG32, AddRef () the (THIS) PURE;
PURE STDMETHOD_ (ULONG32, Release) (THIS);
STDMETHOD (GetSomething) (THIS_
REF (IOtherInterface *) pOther) PURE;
};
STDMETHOD () contains the virtual keyword, the return type and invoke the specification, STDMETHOD_ (), too, unless you don't specify
With a return type, the PURE expanded the c + + "=0", make this function a PURE virtual function,
STDMETHOD STDMETHOD_ and () () there is a corresponding macro method is used to realize - STDMETHODIMP and STDMETHODIMP_ (),