STDMETHODIMP_(ULONG) Release();
STDMETHODIMP CreateInstance(IUnknown * pUnkOuter,REFIID riid,void ** ppvObject);
STDMETHODIMP LockServer(BOOL fLock);
private:
int m_refcnt;
};
// CCopyHook.cpp
//CCopyHook对象和CClassFactory对象的实现文件
#include <stdio.h>
#include "CCopyHook.h"
extern LONG nLocks; //对象计数,用于DllCanUnloadNow
ULONG __stdcall CCopyHook::AddRef(){
if(m_refcnt==0)
nLocks++;
m_refcnt++;
return m_refcnt;
}
ULONG __stdcall CCopyHook::Release(){
int nNewCnt=--m_refcnt;
if(nNewCnt<=0){
nLocks--;
delete this;
}
return nNewCnt;
}
HRESULT __stdcall CCopyHook::QueryInterface(REFIID iid,void** ppvObject){
if(iid==IID_IUnknown)
*ppvObject=static_cast<IUnknown*>(this);
else
if(iid==IID_IShellCopyHook)
*ppvObject=static_cast<ICopyHook*>(this);
else
return E_NOINTERFACE;
reinterpret_cast<IUnknown*>(*ppvObject)->AddRef();