ProtocolImpl.h 和 ProtocolImpl.inl 我如何才能用?

中国蓝计划 esp  2010-07-21 01:13:54
ProtocolImpl.h 和 ProtocolImpl.inl 我如何才能用?

想在 vbWB.h 或则 vbWB.cpp中 使用 class ATL_NO_VTABLE IInternetProtocolImpl : 类中的一部分函数

我该如何做呢?

下边两贴,贴出源码!(代码太多一回搞不下)







[ProtocolImpl.h]

class ATL_NO_VTABLE IInternetProtocolImpl :
public IPassthroughObject,
public IInternetProtocol,
public IInternetProtocolInfo,
public IInternetPriority,
public IInternetThreadSwitch,
public IWinInetHttpInfo
{
public:
void ReleaseAll();

DECLARE_GET_TARGET_UNKNOWN(m_spInternetProtocolUnk)
public:
// IPassthroughObject
STDMETHODIMP SetTargetUnknown(IUnknown* punkTarget);

// IInternetProtocolRoot
STDMETHODIMP Start(
/* [in] */ LPCWSTR szUrl,
/* [in] */ IInternetProtocolSink *pOIProtSink,
/* [in] */ IInternetBindInfo *pOIBindInfo,
/* [in] */ DWORD grfPI,
/* [in] */ HANDLE_PTR dwReserved);

STDMETHODIMP Continue(
/* [in] */ PROTOCOLDATA *pProtocolData);

STDMETHODIMP Abort(
/* [in] */ HRESULT hrReason,
/* [in] */ DWORD dwOptions);

STDMETHODIMP Terminate(
/* [in] */ DWORD dwOptions);

STDMETHODIMP Suspend();

STDMETHODIMP Resume();

// IInternetProtocol
STDMETHODIMP Read(
/* [in, out] */ void *pv,
/* [in] */ ULONG cb,
/* [out] */ ULONG *pcbRead);

STDMETHODIMP Seek(
/* [in] */ LARGE_INTEGER dlibMove,
/* [in] */ DWORD dwOrigin,
/* [out] */ ULARGE_INTEGER *plibNewPosition);

STDMETHODIMP LockRequest(
/* [in] */ DWORD dwOptions);

STDMETHODIMP UnlockRequest();

// IInternetProtocolInfo
STDMETHODIMP ParseUrl(
/* [in] */ LPCWSTR pwzUrl,
/* [in] */ PARSEACTION ParseAction,
/* [in] */ DWORD dwParseFlags,
/* [out] */ LPWSTR pwzResult,
/* [in] */ DWORD cchResult,
/* [out] */ DWORD *pcchResult,
/* [in] */ DWORD dwReserved);

STDMETHODIMP CombineUrl(
/* [in] */ LPCWSTR pwzBaseUrl,
/* [in] */ LPCWSTR pwzRelativeUrl,
/* [in] */ DWORD dwCombineFlags,
/* [out] */ LPWSTR pwzResult,
/* [in] */ DWORD cchResult,
/* [out] */ DWORD *pcchResult,
/* [in] */ DWORD dwReserved);

STDMETHODIMP CompareUrl(
/* [in] */ LPCWSTR pwzUrl1,
/* [in] */ LPCWSTR pwzUrl2,
/* [in] */ DWORD dwCompareFlags);

STDMETHODIMP QueryInfo(
/* [in] */ LPCWSTR pwzUrl,
/* [in] */ QUERYOPTION QueryOption,
/* [in] */ DWORD dwQueryFlags,
/* [in, out] */ LPVOID pBuffer,
/* [in] */ DWORD cbBuffer,
/* [in, out] */ DWORD *pcbBuf,
/* [in] */ DWORD dwReserved);

// IInternetPriority
STDMETHODIMP SetPriority(
/* [in] */ LONG nPriority);

STDMETHODIMP GetPriority(
/* [out] */ LONG *pnPriority);

// IInternetThreadSwitch
STDMETHODIMP Prepare();

STDMETHODIMP Continue();

// IWinInetInfo
STDMETHODIMP QueryOption(
/* [in] */ DWORD dwOption,
/* [in, out] */ LPVOID pBuffer,
/* [in, out] */ DWORD *pcbBuf);

// IWinInetHttpInfo
STDMETHODIMP QueryInfo(
/* [in] */ DWORD dwOption,
/* [in, out] */ LPVOID pBuffer,
/* [in, out] */ DWORD *pcbBuf,
/* [in, out] */ DWORD *pdwFlags,
/* [in, out] */ DWORD *pdwReserved);

public:
CComPtr<IUnknown> m_spInternetProtocolUnk;
CComPtr<IInternetProtocol> m_spInternetProtocol;
CComPtr<IInternetProtocolInfo> m_spInternetProtocolInfo;
CComPtr<IInternetPriority> m_spInternetPriority;
CComPtr<IInternetThreadSwitch> m_spInternetThreadSwitch;
CComPtr<IWinInetInfo> m_spWinInetInfo;
CComPtr<IWinInetHttpInfo> m_spWinInetHttpInfo;
};
...全文
170 点赞 收藏 15
写回复
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
向立天 2010-07-22
[Quote=引用 14 楼 redsleaf 的回复:]
苦熬两天两夜,边学vc,边悟,多靠大家的帮助,纵欲与 2010年7月21日 21:45 突破(我快饿死了,吃饭去了)


现在开始散分。来着有分。
[/Quote]
恭喜了
功夫不负有心人
回复
中国蓝计划 2010-07-21
[MetaFactory]

// ===== CMetaFactory =====

template <class Factory, class Protocol, class FactoryComObject>
inline HRESULT CMetaFactory<Factory, Protocol, FactoryComObject>::
CreateInstance(Factory** ppObj)
{
ATLASSERT(ppObj != 0);
if (!ppObj)
{
return E_POINTER;
}

HRESULT hr = E_OUTOFMEMORY;
void* pv = static_cast<void*>(CreatorClass::CreateInstance);
FactoryComObject* p = 0;
ATLTRY(p = new FactoryComObject(pv))
if (p != NULL)
{
p->SetVoid(pv);
p->InternalFinalConstructAddRef();
hr = p->FinalConstruct();
p->InternalFinalConstructRelease();
if (FAILED(hr))
{
delete p;
p = 0;
}
}
*ppObj = p;
return hr;
}

template <class Factory, class Protocol, class FactoryComObject>
inline HRESULT CMetaFactory<Factory, Protocol, FactoryComObject>::
CreateInstance(IClassFactory* pTargetCF, IClassFactory** ppCF)
{
if (!ppCF)
{
return E_POINTER;
}
*ppCF = 0;

Factory* pObj = 0;
HRESULT hr = CreateInstance(&pObj);
ATLASSERT(SUCCEEDED(hr) && pObj != 0);
if (SUCCEEDED(hr))
{
pObj->AddRef();

hr = pObj->SetTargetClassFactory(pTargetCF);
ATLASSERT(SUCCEEDED(hr));

if (SUCCEEDED(hr))
{
hr = pObj->QueryInterface(IID_IClassFactory,
reinterpret_cast<void**>(ppCF));
ATLASSERT(SUCCEEDED(hr) && *ppCF != 0);
}

pObj->Release();
}
return hr;
}

template <class Factory, class Protocol, class FactoryComObject>
inline HRESULT CMetaFactory<Factory, Protocol, FactoryComObject>::
CreateInstance(REFCLSID clsidTarget, IClassFactory** ppCF)
{
if (!ppCF)
{
return E_POINTER;
}
*ppCF = 0;

Factory* pObj = 0;
HRESULT hr = CreateInstance(&pObj);
ATLASSERT(SUCCEEDED(hr) && pObj != 0);
if (SUCCEEDED(hr))
{
pObj->AddRef();

hr = pObj->SetTargetCLSID(clsidTarget);
ATLASSERT(SUCCEEDED(hr));

if (SUCCEEDED(hr))
{
hr = pObj->QueryInterface(IID_IClassFactory,
reinterpret_cast<void**>(ppCF));
ATLASSERT(SUCCEEDED(hr) && *ppCF != 0);
}

pObj->Release();
}
return hr;
}

}
回复
中国蓝计划 2010-07-21
---------------------------
错误信息
---------------------------
错误码1: 2147746132 没有注册类别
错误码2: 2147746132 没有注册类别

---------------------------
确定
---------------------------

注册和调用的时候都提示这个错误!



HRESULT hr=::CoInternetGetSession(0,&spSession,0); 执行成功了
可是
当使用hr=::CoGetClassObject(CLSID_HTMLFilter,CLSCTX_SERVER,NULL,IID_IClassFactory,(void**)&e_Hxxp);返回错误
当使用hr=MetaFactory::CreateInstance(CLSID_HTMLFilter, &e_Hxxp); 注册,同样返回错误
可以排除是函数的问题(MetaFactory 类在楼下)
这个错误如何解决(接近成功了啊:>)



[vvvv.idl]

[
object,
uuid(4C562AF2-F327-410E-B1EE-9B9305E1D946),
dual,
helpstring("IHTMLFilter Interface"),
pointer_default(unique)
]
interface IHTMLFilter : IDispatch
{
};



library VBMHWBLib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");

………………………………………………………

[
uuid(D804EF17-9395-4B09-9AEE-09A3BA229407),
helpstring("HTMLFilter Class")
]
coclass HTMLFilter
{
[default] interface IHTMLFilter;
};

};


代码如下:
	CComPtr<IInternetSession> spSession;
HRESULT hr=::CoInternetGetSession(0,&spSession,0);
if(regORunreg == VARIANT_TRUE && SUCCEEDED(hr))
{

//hr=::CoGetClassObject(CLSID_HTMLFilter,CLSCTX_SERVER,NULL,IID_IClassFactory,(void**)&e_Hxxp);
hr=MetaFactory::CreateInstance(CLSID_HTMLFilter, &e_Hxxp);
if(SUCCEEDED(hr)){
spSession->RegisterNameSpace(e_Hxxp, CLSID_NULL, AgreemName, 0, 0, 0);
USES_CONVERSION;
*pVal = Hxxp_Efun.SetHashTable(W2A(AgreemName),eFun);
}else{
TCHAR printbuf[80];
wsprintf(printbuf,_T("错误码1: %u\n错误码2: %u\n"),hr,hr);
::MessageBox(NULL, printbuf , _T("错误信息") ,MB_OK | MB_ICONSTOP);
}

}
回复
redsleaf001 2010-07-21
上边问题解决了,又出现了新的错误!【三次回复,马甲上场】
回复
中国蓝计划 2010-07-21
还有当我将 HTMLFilter.h 头文件加入 vbMHWB.h中,错误又多了一个,去掉就无这个错误!
怎么解决


BSCMAKE: error BK1506 : cannot open file '.\ReleaseUMinDependency\vbMHWB.sbr': No such file or directory
回复
中国蓝计划 2010-07-21
'CLSID_HTMLFilter' 'IHTMLFilter' 在哪里定义的啊!我怎么在无错的代码中搜索不到它的定义呢?
回复
中国蓝计划 2010-07-21
下段代码提示错误!如何解决!


D:\我的系统\桌面\VBHTML\源码\vbMHWB\HTMLFilter.h(15) : error C2065: 'CLSID_HTMLFilter' : undeclared identifier
D:\我的系统\桌面\VBHTML\源码\vbMHWB\HTMLFilter.h(16) : error C2065: 'IHTMLFilter' : undeclared identifier
D:\我的系统\桌面\VBHTML\源码\vbMHWB\HTMLFilter.h(16) : error C2065: 'IID_IHTMLFilter' : undeclared identifier
D:\我的系统\桌面\VBHTML\源码\vbMHWB\HTMLFilter.h(16) : error C2065: 'LIBID_VBMHWBLib' : undeclared identifier




#ifndef __HTMLFILTER_H_
#define __HTMLFILTER_H_

#include "resource.h" // main symbols

typedef unsigned long HANDLE_PTR;

/////////////////////////////////////////////////////////////////////////////
// CHTMLFilter
//template <class ThreadModel = CComSingleThreadModel>
class ATL_NO_VTABLE CHTMLFilter :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CHTMLFilter, &CLSID_HTMLFilter>,
public IDispatchImpl<IHTMLFilter, &IID_IHTMLFilter, &LIBID_VBMHWBLib>,
public IInternetProtocol,
public IInternetProtocolSink
{
public:
CHTMLFilter()
{
}

DECLARE_REGISTRY_RESOURCEID(IDR_HTMLFILTER)
DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CHTMLFilter)
COM_INTERFACE_ENTRY(IHTMLFilter)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY_IID(IID_IInternetProtocol,IInternetProtocol)
COM_INTERFACE_ENTRY_IID(IID_IInternetProtocolSink,IInternetProtocolSink)
END_COM_MAP()
回复
中国蓝计划 2010-07-21
苦熬两天两夜,边学vc,边悟,多靠大家的帮助,纵欲与 2010年7月21日 21:45 突破(我快饿死了,吃饭去了)


现在开始散分。来着有分。
回复
Eleven 2010-07-21
inl 文件是内联函数的源文件。内联函数通常在c++头文件中实现,但有的时候内联函数较多或者出于一些别的考虑(使头文件看起来更简洁等),往往会将这部分具体定义的代码添加到INL文件中,然后在该头文件的末尾将其用#include引入。由此也可以看到inl文件的例外一个用法的影子——模板函数、模板类的定义代码的存放。对于比较大的工程来说,出于管理方面的考虑,模板函数、模板类的声明部分一般存放在一个或少数几个文件中,而将其定义部分存放在inl文件中,然后在相应的头文件中包含进来。
回复
向立天 2010-07-21
可惜我不懂
回复
中国蓝计划 2010-07-21
CLSID_HTMLFilter uuid(D804EF17-9395-4B09-9AEE-09A3BA229407)

HTMLFilter uuid(4C562AF2-F327-410E-B1EE-9B9305E1D946)
回复
中国蓝计划 2010-07-21
CComModule _Module;
BEGIN_OBJECT_MAP(ObjectMap)
OBJECT_ENTRY(CLSID_vbWB, CvbWB)
OBJECT_ENTRY(CLSID_HTMLFilter,CHTMLFilter)
END_OBJECT_MAP()




调用
_Module.Init(ObjectMap, hInstance, &LIBID_VBMHWBLib);

有什么错吗?
回复
向立天 2010-07-21
马上又要三次了
回复
中国蓝计划 2010-07-21
由于代码过长,贴出部分使用的,希望达人赐教。
回复
中国蓝计划 2010-07-21
[ProtocolImpl.inl]


………………


// ===== IInternetProtocolImpl =====

inline STDMETHODIMP IInternetProtocolImpl::SetTargetUnknown(
IUnknown* punkTarget)
{
ATLASSERT(punkTarget != 0);
if (!punkTarget)
{
return E_POINTER;
}

// This method should only be called once, and be the only source
// of target interface pointers.
ATLASSERT(m_spInternetProtocolUnk == 0);
ATLASSERT(m_spInternetProtocol == 0);
if (m_spInternetProtocolUnk || m_spInternetProtocol)
{
return E_UNEXPECTED;
}

// We expect the target unknown to implement at least IInternetProtocol
// Otherwise we reject it
HRESULT hr = punkTarget->QueryInterface(&m_spInternetProtocol);
ATLASSERT(FAILED(hr) || m_spInternetProtocol != 0);
if (FAILED(hr))
{
return hr;
}

ATLASSERT(m_spInternetProtocolInfo == 0);
ATLASSERT(m_spInternetPriority == 0);
ATLASSERT(m_spInternetThreadSwitch == 0);
ATLASSERT(m_spWinInetInfo == 0);
ATLASSERT(m_spWinInetHttpInfo == 0);

m_spInternetProtocolUnk = punkTarget;
return S_OK;
}

inline void IInternetProtocolImpl::ReleaseAll()
{
m_spInternetProtocolUnk.Release();
m_spInternetProtocol.Release();
m_spInternetProtocolInfo.Release();
m_spInternetPriority.Release();
m_spInternetThreadSwitch.Release();
m_spWinInetInfo.Release();
m_spWinInetHttpInfo.Release();
}


inline STDMETHODIMP IInternetProtocolImpl::Start(
/* [in] */ LPCWSTR szUrl,
/* [in] */ IInternetProtocolSink *pOIProtSink,
/* [in] */ IInternetBindInfo *pOIBindInfo,
/* [in] */ DWORD grfPI,
/* [in] */ HANDLE_PTR dwReserved)
{

ATLASSERT(m_spInternetProtocol != 0);
return m_spInternetProtocol ?
m_spInternetProtocol->Start(szUrl, pOIProtSink, pOIBindInfo, grfPI,
dwReserved) :
E_UNEXPECTED;
}

inline STDMETHODIMP IInternetProtocolImpl::Continue(
/* [in] */ PROTOCOLDATA *pProtocolData)
{
ATLASSERT(m_spInternetProtocol != 0);
return m_spInternetProtocol ?
m_spInternetProtocol->Continue(pProtocolData) :
E_UNEXPECTED;
}


inline STDMETHODIMP IInternetProtocolImpl::Abort(
/* [in] */ HRESULT hrReason,
/* [in] */ DWORD dwOptions)
{
ATLASSERT(m_spInternetProtocol != 0);
return m_spInternetProtocol ?
m_spInternetProtocol->Abort(hrReason, dwOptions) :
E_UNEXPECTED;
}


inline STDMETHODIMP IInternetProtocolImpl::Terminate(
/* [in] */ DWORD dwOptions)
{
ATLASSERT(m_spInternetProtocol != 0);
return m_spInternetProtocol ?
m_spInternetProtocol->Terminate(dwOptions) :
E_UNEXPECTED;
}

inline STDMETHODIMP IInternetProtocolImpl::Suspend()
{
ATLASSERT(m_spInternetProtocol != 0);
return m_spInternetProtocol ?
m_spInternetProtocol->Suspend() :
E_UNEXPECTED;
}

inline STDMETHODIMP IInternetProtocolImpl::Resume()
{
ATLASSERT(m_spInternetProtocol != 0);
return m_spInternetProtocol ?
m_spInternetProtocol->Resume() :
E_UNEXPECTED;
}


inline STDMETHODIMP IInternetProtocolImpl::Read(
/* [in, out] */ void *pv,
/* [in] */ ULONG cb,
/* [out] */ ULONG *pcbRead)
{
ATLASSERT(m_spInternetProtocol != 0);
return m_spInternetProtocol ?
m_spInternetProtocol->Read(pv, cb, pcbRead) :
E_UNEXPECTED;
}

inline STDMETHODIMP IInternetProtocolImpl::Seek(
/* [in] */ LARGE_INTEGER dlibMove,
/* [in] */ DWORD dwOrigin,
/* [out] */ ULARGE_INTEGER *plibNewPosition)
{
ATLASSERT(m_spInternetProtocol != 0);
return m_spInternetProtocol ?
m_spInternetProtocol->Seek(dlibMove, dwOrigin, plibNewPosition) :
E_UNEXPECTED;
}


inline STDMETHODIMP IInternetProtocolImpl::LockRequest(
/* [in] */ DWORD dwOptions)
{
ATLASSERT(m_spInternetProtocol != 0);
return m_spInternetProtocol ?
m_spInternetProtocol->LockRequest(dwOptions) :
E_UNEXPECTED;
}



inline STDMETHODIMP IInternetProtocolImpl::UnlockRequest()
{
ATLASSERT(m_spInternetProtocol != 0);
return m_spInternetProtocol ?
m_spInternetProtocol->UnlockRequest() :
E_UNEXPECTED;
}

// IInternetProtocolInfo
inline STDMETHODIMP IInternetProtocolImpl::ParseUrl(
/* [in] */ LPCWSTR pwzUrl,
/* [in] */ PARSEACTION ParseAction,
/* [in] */ DWORD dwParseFlags,
/* [out] */ LPWSTR pwzResult,
/* [in] */ DWORD cchResult,
/* [out] */ DWORD *pcchResult,
/* [in] */ DWORD dwReserved)
{
ATLASSERT(m_spInternetProtocolInfo != 0);
return m_spInternetProtocolInfo ?
m_spInternetProtocolInfo->ParseUrl(pwzUrl, ParseAction, dwParseFlags,
pwzResult, cchResult, pcchResult, dwReserved) :
E_UNEXPECTED;
}

………………
回复
发动态
发帖子
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
社区公告
暂无公告