// ConsoleApplication7.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#pragma comment (lib, "urlmon.lib")
class CMarshaller2 : public IBindStatusCallback
{
LONG _ref_count;
public:
CMarshaller2() : _ref_count(1)
{
}
~CMarshaller2() {}
STDMETHOD(OnStartBinding)(
DWORD dwReserved,
IBinding __RPC_FAR *pib)
{
return S_OK;;
}
STDMETHOD(GetPriority)(
LONG __RPC_FAR *pnPriority)
{
return S_OK;;
}
STDMETHOD(OnLowResource)(
DWORD reserved)
{
return S_OK;;
}
STDMETHOD(OnProgress)(
ULONG ulProgress,
ULONG ulProgressMax,
ULONG ulStatusCode,
LPCWSTR wszStatusText)
{
return S_OK;;
}
STDMETHOD(OnStopBinding)(
HRESULT hresult,
LPCWSTR szError)
{
return S_OK;;
}
STDMETHOD(GetBindInfo)(
DWORD __RPC_FAR *pgrfBINDF,
BINDINFO __RPC_FAR *pbindInfo)
{
//*pgrfBINDF = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_GETNEWESTVERSION; // bind asynchronously
//pbindInfo->cbSize = sizeof(BINDINFO);
//pbindInfo->szExtraInfo = NULL;
//memset(&pbindInfo->stgmedData, 0, sizeof(STGMEDIUM));
//pbindInfo->grfBindInfoF = 0;
//pbindInfo->dwBindVerb = BINDVERB_GET;
//pbindInfo->szCustomVerb = NULL;
return S_OK;
}
STDMETHOD(OnDataAvailable)(
DWORD grfBSCF,
DWORD dwSize,
FORMATETC __RPC_FAR *pformatetc,
STGMEDIUM __RPC_FAR *pstgmed)
{
return S_OK;;
}
STDMETHOD(OnObjectAvailable)(
REFIID riid,
IUnknown __RPC_FAR *punk)
{
return S_OK;;
}
STDMETHOD_(ULONG, AddRef)()
{
return InterlockedIncrement(&_ref_count);
}
STDMETHOD_(ULONG, Release)()
{
printf("Release: %d\n", _ref_count);
ULONG ret = InterlockedDecrement(&_ref_count);
if (ret == 0)
{
printf("Release object %p\n", this);
delete this;
}
return ret;
}
STDMETHOD(QueryInterface)(
REFIID riid,
void __RPC_FAR *__RPC_FAR *ppv)
{
*ppv = NULL;
if (riid == IID_IUnknown || riid == IID_IBindStatusCallback)
{
*ppv = this;
AddRef();
return S_OK;
}
return E_NOINTERFACE;
}
};
int wmain(int argc, wchar_t** argv)
{
IMoniker* pMoniker;
CMarshaller2* pBSC = new CMarshaller2();
CLSID iid = IID_IStream;
IStream* pStream = nullptr;
HRESULT hResult;
IBindCtx* pNewBindCtx=nullptr;
hResult = CreateURLMoniker(NULL, L"http://localhost:50001/Index.html", &pMoniker);
if (FAILED(hResult))
{
return(hResult);
}
hResult = CreateBindCtx(0, &pNewBindCtx);
if (FAILED(hResult))
{
return(hResult);
}
//向绑定环境注册一个回调接口IBindStatusCallback,CCuteMoniker派生自接口IBindStatusCallback。
hResult = RegisterBindStatusCallback(pNewBindCtx, static_cast<IBindStatusCallback*>(pBSC), 0, 0L);
if (FAILED(hResult))
{
return(hResult);
}
hResult = pMoniker->BindToStorage(pNewBindCtx, 0, IID_IStream, (void**)&pStream);
if (FAILED(hResult))
{
return(hResult);
}
return hResult;
}
URLMoniker用法
最新推荐文章于 2019-06-26 09:51:04 发布