Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C ATL COM VC9.0
Hi I am trying to run UrlDownloadToFile()
CBSCallbackImplPX callback;
::URLDownloadToFileA(NULL, "http://www.codeproject.com/KB/system/keyboard.aspx" ,"c:\\test\\a.html",NULL,&callback);
 
Where
class CBSCallbackImplPX : public IBindStatusCallback 
 
It is working fine even in proxy.as it uses IE's credential.
 
But today when I am trying the same code under password protected proxy it is returning
E_ACCESSDENIED
.
 
I studied this link
http://www.ureader.com/msg/1510234.aspx[^]
 
and came to know about
IAuthenticate
Interface.
 
but not able to implement.
 
below is my call back code
 
class CBSCallbackImplPX : public IBindStatusCallback //,IServiceProvider,TIAuthenticate
{
public:
  CBSCallbackImplPX();
  ~CBSCallbackImplPX();
//TIAuthenticate  class taken from http://www.ureader.com/msg/1510234.aspx
//TIAuthenticate myAuthenticate;

 CString m_csData; 
 DWORD m_dwSize;
 int nTitmeOut;
  // IUnknown methods
  STDMETHOD(QueryInterface)(REFIID riid, void **ppvObject);
  STDMETHOD_(ULONG, AddRef)();
  STDMETHOD_(ULONG, Release)();
 
  // IBindStatusCallback methods
  STDMETHOD(OnStartBinding)(DWORD, IBinding *);
  STDMETHOD(GetPriority)(LONG *);
  STDMETHOD(OnLowResource)(DWORD);
  STDMETHOD(OnProgress)(ULONG ulProgress,
    ULONG ulProgressMax,
    ULONG ulStatusCode,
    LPCWSTR szStatusText);
  STDMETHOD(OnStopBinding)(HRESULT, LPCWSTR);
  STDMETHOD(GetBindInfo)(DWORD *, BINDINFO *);
  STDMETHOD(OnDataAvailable)(DWORD, DWORD, FORMATETC *, STGMEDIUM *);
  STDMETHOD(OnObjectAvailable)(REFIID, IUnknown *);
 
//   HRESULT STDMETHODCALLTYPE QueryService( REFGUID guidService, REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject) ;
protected:
  ULONG m_ulObjRefCount;
  clock_t m_startDownload,m_endDownload;
 
};
 

 

 
// BSCallbackImpl.cpp: implementation of the CBSCallbackImplPX class.
//
//////////////////////////////////////////////////////////////////////
 
#include "stdafx.h"
#include "BSCallbackImplPX.h"
 

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
 
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//--------------------------------------------------------------------
CBSCallbackImplPX::CBSCallbackImplPX()
{
	nTitmeOut=10;
	m_ulObjRefCount = 1;
	m_csData="";
	m_dwSize=0;
	m_startDownload,m_endDownload=0;
}
 

//--------------------------------------------------------------------
CBSCallbackImplPX::~CBSCallbackImplPX()
{
}
 

//--------------------------------------------------------------------
// IUnknown
STDMETHODIMP CBSCallbackImplPX::QueryInterface(REFIID riid, void **ppvObject)
{
	
	*ppvObject = NULL;
 
	// IUnknown
	if (::IsEqualIID(riid, __uuidof(IUnknown)))
	{
		//TRACE(_T("IUnknown::QueryInterface(IUnknown)\n"));
 
		*ppvObject = this;
	}
	// IBindStatusCallback
	else if (::IsEqualIID(riid, __uuidof(IAuthenticate)))
	{
		//TRACE(_T("IUnknown::QueryInterface(IBindStatusCallback)\n"));
 
		AfxMessageBox("found something");//can I implement the callback here??
		//*ppvObject = /*static_cast(*/this/*)*/;
	}
 
		if (::IsEqualIID(riid, __uuidof(IUnknown)))
		{}
	if (*ppvObject)
	{
		this->AddRef();
		/*(*reinterpret_cast(ppvObject))->AddRef();*/  //Ram:As unicode casting.
 
		return S_OK;
	}
 
	return E_NOINTERFACE;
}
 

 

 
//--------------------------------------------------------------------
STDMETHODIMP_(ULONG) CBSCallbackImplPX::AddRef()
{
	//TRACE(_T("IUnknown::AddRef\n"));
 
	return ++m_ulObjRefCount;
}
 

//--------------------------------------------------------------------
STDMETHODIMP_(ULONG) CBSCallbackImplPX::Release()
{
	//TRACE(_T("IUnknown::Release\n"));
 
	return --m_ulObjRefCount;
}
 

//--------------------------------------------------------------------
// IBindStatusCallback
STDMETHODIMP CBSCallbackImplPX::OnStartBinding(DWORD d, IBinding *ib)
{
	//ib=&myAuthenticate;
	//TRACE(_T("IBindStatusCallback::OnStartBinding\n"));
	m_startDownload=clock();
	return S_OK;
}
 

//--------------------------------------------------------------------
STDMETHODIMP CBSCallbackImplPX::GetPriority(LONG *)
{
	//TRACE(_T("IBindStatusCallback::GetPriority\n"));
 
	return E_NOTIMPL;
}
 

//--------------------------------------------------------------------
STDMETHODIMP CBSCallbackImplPX::OnLowResource(DWORD)
{
	//TRACE(_T("IBindStatusCallback::OnLowResource\n"));
 
	return S_OK;
}
 

//--------------------------------------------------------------------
STDMETHODIMP CBSCallbackImplPX::OnProgress(ULONG ulProgress,
										   ULONG ulProgressMax,
										   ULONG ulStatusCode,
										   LPCWSTR szStatusText)
{
	m_endDownload=clock();
	int nTimeTakenForThisDownload=0;
	nTimeTakenForThisDownload=((int)( m_endDownload - m_startDownload)/CLOCKS_PER_SEC) ;
	if(nTimeTakenForThisDownload>=nTitmeOut)
	{
		////CMTLog::WriteLogMT("Download cancelled by client");
		return E_ABORT;  // Download canceled by the client
	}
	return S_OK;
}
 

//--------------------------------------------------------------------
STDMETHODIMP CBSCallbackImplPX::OnStopBinding(HRESULT, LPCWSTR)
{
	//TRACE(_T("IBindStatusCallback::OnStopBinding\n"));
 
	return S_OK;
}
 

//--------------------------------------------------------------------
STDMETHODIMP CBSCallbackImplPX::GetBindInfo(DWORD *d, BINDINFO * b)
{
	//b->pUnk = &myAuthenticate;
	//TRACE(_T("IBindStatusCallback::GetBindInfo\n"));
	return S_OK;
}
 

//--------------------------------------------------------------------
STDMETHODIMP CBSCallbackImplPX::OnDataAvailable(DWORD dww, DWORD dwSize,
												FORMATETC *fww, STGMEDIUM *stgmed )
{
	//TRACE(_T("IBindStatusCallback::OnDataAvailable %ld\n"), dwSize );
//	//CMTLog::WriteLogMT2("IBindStatusCallback::OnDataAvailable %ld ",dwSize);
	if ( stgmed ) {
		if ( stgmed->pstm ) {
 
			ULONG bytesRead = 0;
 
			dwSize=dwSize-m_dwSize;
 
			BYTE *data = new BYTE[ dwSize + 1 ];
			//*data=(char)NULL;
			HRESULT hRes = stgmed->pstm->Read( data, dwSize, &bytesRead );
			data[dwSize] = '\0';

			m_dwSize+=bytesRead;
			m_csData +=(char *)data;
 
			/*
			BYTE *data = (BYTE*)m_csData.GetBuffer( m_csData.GetLength() + dwSize + 1 );
			HRESULT hRes = stgmed->pstm->Read( data, dwSize, &bytesRead );
			m_dwSize+=bytesRead;
			m_csData.ReleaseBuffer();
			*/
 
			delete data;
			data=NULL;
 
			return hRes;
		}
	}
 
	return S_OK;
}
 

//--------------------------------------------------------------------
STDMETHODIMP CBSCallbackImplPX::OnObjectAvailable(REFIID, IUnknown *)
{
	//TRACE(_T("IBindStatusCallback::OnObjectAvailable\n"));
 
	return S_OK;
}
 

//--------------------------------------------------------------------
 
please help :(
Posted 12-Dec-11 22:37pm
Comments
shankha2010 at 13-Dec-11 5:44am
   
after studying this link
http://msdn.microsoft.com/en-us/library/ms775123(v=vs.85).aspx
 
I think ::URLDownloadToFileA(/*this is the place*/, "a.com","c:\a.html",NULL,&callback);
 
where I can implement
TIAuthenticate class of http://www.ureader.com/msg/1510234.aspx
and now I am getting the control but
 
HRESULT __stdcall TIAuthenticate::QueryInterface(const IID& iid,void ** ppv)
{
//
 
if(iid == IID_IUnknown)
{
*ppv = static_cast(this);
}
else if(iid == IID_IAuthenticate)
{
*ppv = static_cast(this);
AfxMessageBox("Authenticate interface requested.");
}
else
{
*ppv = NULL;
return E_NOINTERFACE;//it is coming here :(
}
reinterpret_cast(*ppv)->AddRef();
return S_OK;
 
}

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

ultimately got one way out
 
URLDownloadToFile(NULL,"http://prodex:prodex123@www.codeproject.com/KB/system/keyboard.aspx","c:\\test\\a.html",NULL,NULL);
its working Smile | :)
 
still not able to do through callback.
 
please send some code snippet for that.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 553
1 CPallini 470
2 Sergey Alexandrovich Kryukov 418
3 George Jonsson 231
4 Afzaal Ahmad Zeeshan 194
0 OriginalGriff 5,370
1 CPallini 4,360
2 Sergey Alexandrovich Kryukov 3,822
3 George Jonsson 3,037
4 Gihan Liyanage 2,435


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 13 Dec 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100