Com入门

1. 定义CLSID_IExample和IID_IExample,分别作为实现类(coclass)和接口类的id
2. 声明接口IExample,从IUnknown继承
STDMETHOD  (QueryInterface)        (THIS_ REFIID, void **) PURE;
STDMETHOD_ (ULONG, AddRef)        (THIS) PURE;
STDMETHOD_ (ULONG, Release)        (THIS) PURE;
STDMETHOD  (SetString)            (THIS_ char *) PURE;
STDMETHOD  (GetString)            (THIS_ char *, DWORD) PURE;

3. 实现接口IExample类MyRealIExample
4. 实现接口IClassFactory
HRESULT STDMETHODCALLTYPE QueryInterface( REFIID factoryGuid, void **ppv)
ULONG STDMETHODCALLTYPE AddRef()
ULONG STDMETHODCALLTYPE Release()
HRESULT STDMETHODCALLTYPE CreateInstance(IUnknown *punkOuter, REFIID vTableGuid, void **objHandle)
HRESULT STDMETHODCALLTYPE LockServer(BOOL flock)
5. 实现函数
HRESULT PASCAL DllGetClassObject(REFCLSID objGuid, REFIID factoryGuid, void **factoryHandle)
HRESULT PASCAL DllCanUnloadNow(void)
STDAPI DllRegisterServer() (可选)
6. 导出函数
DllCanUnloadNow        PRIVATE
DllGetClassObject    PRIVATE
DllRegisterServer    PRIVATE

参考教程
http://www.codeproject.com/Articles/13601/COM-in-plain-C#CLASS
http://antonio.cz/static/com/5.html

Q&A

coclass??
coclass (short for component object class) is contained in a DLL or EXE, and contains the code behind one or more interfaces. The coclass is said to implement those interfaces.

GUID??
globally unique identifier  GUIDs are COM's language-independent way of identifying things. Each interface and coclass has a GUID.

UUID??
(which stands for universally unique identifier) at times. UUIDs and GUIDs are, for all practical purposes, the same.

class ID, or CLSID, is a GUID that names a coclass. An interface ID, or IID, is a GUID that names an interface.

def file: PRIVATE?

COM ThreadingModel?

__declspec(novtable)??

DECLSPEC_SELECTANY??

Powered by Jekyll and Theme by solid

本站总访问量