downloadEngineNew.h
downloadEngineNew.cppCode:/* * downloadEngineNew.h * * Created on: 2009-4-22 * Author: Administrator */ #ifndef DOWNLOADENGINENEW_H_ #define DOWNLOADENGINENEW_H_ #include <downloadmgrclient.h> class CDownloadMgrUiDownloadsList; class CDownloadMgrUiLibRegistry; class CDownloadMgrUiUserInteractions; const TUid KMyAppUid = {0xE08C8196}; class CDownLoadMgr : public MHttpDownloadMgrObserver { public: static CDownLoadMgr* NewL(); static CDownLoadMgr* NewLC(); ~CDownLoadMgr(); // void StartDownloading(const TDesC8& aUrl,const TDesC8& aDestFilename); void StartDownloading(const TDesC8& url,const TDesC8 & des); void DoSomethingWhenCompleted(); // To observe download events from MHttpDownloadMgrObserver void HandleDMgrEventL (RHttpDownload &aDownload, THttpDownloadEvent aEvent); private: void ConstructL(); CDownLoadMgr(); private: //Data // Return value of download creation TInt retVal ; //Download manager to download the sisx RHttpDownloadMgr iDMgr; //Registry to register ui component CDownloadMgrUiLibRegistry * iUiReg; // UI interaction component CDownloadMgrUiUserInteractions* idMgrUserInteractions; //Download list component CDownloadMgrUiDownloadsList * iMgrDownloadsList; }; #endif /* DOWNLOADENGINENEW_H_ */
my problem:Code:/* * downloadEngineNew.cpp * * Created on: 2009-4-22 * Author: Administrator */ #include <cdownloadmgruidownloadslist.h> #include <cdownloadmgruilibregistry.h> #include <cdownloadmgruiuserinteractions.h> #include <COMMDB.H> #include <aknnotewrappers.h> #include "downloadEngineNew.h" // Change these descriptor values(Give the correct URL path and sisx name) _LIT8( KCodUrl, "http://192.168.1.112/gan/1.swf"); _LIT( KTempPath , "c:\\Data\\Videos\\new.swf" ); CDownLoadMgr* CDownLoadMgr::NewL() { CDownLoadMgr* self = CDownLoadMgr::NewLC(); CleanupStack::Pop(self); return self; } CDownLoadMgr* CDownLoadMgr::NewLC() { CDownLoadMgr* self = new (ELeave) CDownLoadMgr; CleanupStack::PushL(self); self->ConstructL(); return self; } CDownLoadMgr::CDownLoadMgr() { } void CDownLoadMgr::ConstructL() { // Connect to download manager iDMgr.ConnectL( KMyAppUid,*this, ETrue ); iUiReg = CDownloadMgrUiLibRegistry::NewL( iDMgr ); idMgrUserInteractions = &iUiReg->RegisterUserInteractionsL(); iMgrDownloadsList = &iUiReg->RegisterDownloadsListL(); iDMgr.DeleteAll(); } CDownLoadMgr::~CDownLoadMgr() { delete iUiReg; iDMgr.Close(); } // Fn to download sisx from URL void CDownLoadMgr::StartDownloading(const TDesC8& url,const TDesC8 & des) { // AccessPt retrievel from CommsDB TUint32 iapId(0); CCommsDatabase* cdb = CCommsDatabase::NewL(EDatabaseTypeIAP); CleanupStack::PushL(cdb); CCommsDbConnectionPrefTableView* commDBView = cdb->OpenConnectionPrefTableInRankOrderLC(ECommDbConnectionDirectionOutgoing); if(commDBView->GotoFirstRecord() == KErrNone) { CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref; commDBView->ReadConnectionPreferenceL(pref); iapId = pref.iBearer.iIapId; } CleanupStack::PopAndDestroy(commDBView); CleanupStack::PopAndDestroy(cdb); //Setting Attribute for download manger ( Access Point) User::LeaveIfError( iDMgr.SetIntAttribute( EDlMgrIap, (TInt32)iapId ) ); TBufC8<254> URL(url); //Creation of download obj RHttpDownload& download = iDMgr.CreateDownloadL(URL,retVal); // Setting attributes for download object TBufC8<254> buf(des); TFileName filename(KTempPath); // Setting destination path for the downloaded file to be stored download.SetStringAttribute( EDlAttrDestFilename, filename ); TBool silattr(ETrue); //download progress will be silent download.SetBoolAttribute(EDlAttrSilent,silattr); // start downloading if(retVal) { TInt state = download.Start(); } else { _LIT(Ktext,"Download creation failed"); CAknInformationNote* informationNote; informationNote = new ( ELeave ) CAknInformationNote; informationNote->ExecuteLD(Ktext); } } void CDownLoadMgr::DoSomethingWhenCompleted() { // iMgrDownloadsList->DisplayDownloadsListL(); User::InfoPrint( _L( "Completed" ) ); } // To observe download events from MHttpDownloadMgrObserver void CDownLoadMgr::HandleDMgrEventL (RHttpDownload &aDownload, THttpDownloadEvent aEvent) { switch ( aEvent.iDownloadState ) { case EHttpDlCreated: { break; } case EHttpDlInprogress: { // _LIT(Ktext,"downing"); // CAknInformationNote* informationNote; // informationNote = new ( ELeave ) CAknInformationNote; // informationNote->ExecuteLD(Ktext); break; } case EHttpDlCompleted: { // On completion of download , call silent installation function // TFileName filename(KTempPath ); // aDownload.SetStringAttribute( EDlAttrDestFilename, filename ); // aDownload.Move(); DoSomethingWhenCompleted(); break; } case EHttpDlFailed: { _LIT(Kerr,"Downloading failed"); TInt32 iVal = 0L; TBuf<40> derror; aDownload.GetIntAttribute(EDlAttrGlobalErrorId, iVal); derror.Append(Kerr); derror.AppendNum(iVal); CAknInformationNote* informationNote; informationNote = new ( ELeave ) CAknInformationNote; informationNote->ExecuteLD(derror); aDownload.Delete(); break; } case EHttpDlPaused: { break; } default : { break; } } }
1、if i delete
TBool silattr(ETrue);
download.SetBoolAttribute(EDlAttrSilent,silattr);
or change it to EFalse,when i exit my app,it notes that "the application is closed,alloc xxxxx",i don't know why?MY SDK is MR.
hooklogger display that the problem happens in DownloadMgrUiLib.dll
can anyone help me?

Reply With Quote

