home *** CD-ROM | disk | FTP | other *** search
Wrap
// XceedZipEvents.cpp : implementation file // // MFC sample using The Xceed Zip Compression Library 4 // Copyright (c) 1999 Xceed Software Inc. // // This sample illustrate how to use the XceedZip control in MFC // without having to drop the control on a form. // #include "stdafx.h" #include "Typelib.h" #include "XceedZipEvents.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CXceedZipEvents IMPLEMENT_DYNCREATE(CXceedZipEvents, CCmdTarget) CXceedZipEvents::CXceedZipEvents( void ) { EnableAutomation(); m_pBar = NULL; m_pResults = NULL; m_pConnectionPoint = NULL; } CXceedZipEvents::~CXceedZipEvents( void ) { if( m_pConnectionPoint ) { m_pConnectionPoint->Unadvise( m_adviseCookie ); } } void CXceedZipEvents::OnFinalRelease() { // When the last reference for an automation object is released // OnFinalRelease is called. The base class will automatically // deletes the object. Add additional cleanup required for your // object before calling the base class. CCmdTarget::OnFinalRelease(); } BEGIN_MESSAGE_MAP(CXceedZipEvents, CCmdTarget) //{{AFX_MSG_MAP(CXceedZipEvents) // NOTE - the ClassWizard will add and remove mapping macros here. //}}AFX_MSG_MAP END_MESSAGE_MAP() // XCEED: For each event we want to handle, we add an entry here. // Since we cheated and asked the ClassWizard to create a wrapper // around _IXceedZipEvents, we can copy and paste from the // xceedzip.h and xceedzip.cpp files the required stuff! // This is much useful for the parameter list and the event ID! q;-) BEGIN_DISPATCH_MAP(CXceedZipEvents, CCmdTarget) //{{AFX_DISPATCH_MAP(CXceedZipEvents) DISP_FUNCTION_ID(CXceedZipEvents, "GlobalStatus", 0x17d5, GlobalStatus, VT_EMPTY, VTS_I4 VTS_I4 VTS_I4 VTS_I2 VTS_I4 VTS_I4 VTS_I4 VTS_I2 VTS_I4 VTS_I2) DISP_FUNCTION_ID(CXceedZipEvents, "SkippingFile", 0x17d6, SkippingFile, VT_EMPTY, VTS_BSTR VTS_BSTR VTS_BSTR VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_DATE VTS_DATE VTS_DATE VTS_I4 VTS_BOOL VTS_I4) DISP_FUNCTION_ID(CXceedZipEvents, "Warning", 0x17d7, Warning, VT_EMPTY, VTS_BSTR VTS_I4) DISP_FUNCTION_ID(CXceedZipEvents, "InsertDisk", 0x1838, InsertDisk, VT_EMPTY, VTS_I4 VTS_PBOOL) //}}AFX_DISPATCH_MAP END_DISPATCH_MAP() // Note: we add support for IID_IXceedZipEvents to support typesafe binding // from VBA. This IID must match the GUID that is attached to the // dispinterface in the .ODL file. // XCEED: We changed the pregenerated GUID for this class, since we want to // implement an existing interface. We tool the OLE view tool, found // the _IXceedZipEvents interface, right-clicked on it and selected // "Copy GUID to clipboard", which yeilds this: // {DB797691-40E0-11D2-9BD5-0060082AE372} // So we changed the structure below accordingly. static const IID IID_IXceedZipEvents = { 0xDB797691, 0x40E0, 0x11D2, { 0x9B, 0xD5, 0x00, 0x60, 0x08, 0x2A, 0xE3, 0x72 } }; BEGIN_INTERFACE_MAP(CXceedZipEvents, CCmdTarget) INTERFACE_PART(CXceedZipEvents, IID_IXceedZipEvents, Dispatch) END_INTERFACE_MAP() ///////////////////////////////////////////////////////////////////////////// // CXceedZipEvents utility methods // XCEED: This code was inspired from article Q183599 is MSDN bool CXceedZipEvents::Connect( IDispatch* pDispatch ) { if( !pDispatch ) { return false; } // Reset stuff in case Connect called more than once if( m_pConnectionPoint ) { m_pConnectionPoint->Unadvise( m_adviseCookie ); m_pConnectionPoint = NULL; } // Get server's IConnectionPointContainer interface. IConnectionPointContainer* pConnPtContainer; HRESULT hr = pDispatch->QueryInterface( IID_IConnectionPointContainer, (void **)&pConnPtContainer ); if( FAILED( hr ) ) { return false; } // Find connection point for events we're interested in. hr = pConnPtContainer->FindConnectionPoint( IID_IXceedZipEvents, &m_pConnectionPoint ); if( FAILED( hr ) ) { pConnPtContainer->Release(); return false; } // Get the IUnknown interface of our event implementation. LPUNKNOWN pUnk = GetInterface( &IID_IUnknown ); if( !pUnk ) { pConnPtContainer->Release(); return false; } // Setup advisory connection! hr = m_pConnectionPoint->Advise( pUnk, &m_adviseCookie ); pConnPtContainer->Release(); if( FAILED( hr ) ) { return false; } return true; } ///////////////////////////////////////////////////////////////////////////// // CXceedZipEvents message handlers void CXceedZipEvents::GlobalStatus(long lFilesTotal, long lFilesProcessed, long lFilesSkipped, short nFilesPercent, long lBytesTotal, long lBytesProcessed, long lBytesSkipped, short nBytesPercent, long lBytesOutput, short nCompressionRatio) { if( m_pBar ) { m_pBar->SetPos( nBytesPercent ); } } void CXceedZipEvents::SkippingFile(LPCTSTR sFilename, LPCTSTR sComment, LPCTSTR sFilenameOnDisk, long lSize, long lCompressedSize, long xAttributes, long lCRC, DATE dtLastModified, DATE dtLastAccessed, DATE dtCreated, long xMethod, BOOL bEncrypted, long xReason) { if( m_pResults ) { CString sMsg; sMsg.Format( "Skipping file %s for reason %d", sFilename, xReason ); m_pResults->AddString( sMsg ); } } void CXceedZipEvents::Warning(LPCTSTR sFilename, long xWarning) { if( m_pResults ) { CString sMsg; sMsg.Format( "Warning %d on file %s", xWarning, sFilename ); m_pResults->AddString( sMsg ); } } void CXceedZipEvents::InsertDisk(long lDiskNumber, BOOL* bDiskInserted) { int nAnswer; if( lDiskNumber == 0 ) { nAnswer = MessageBox( NULL, "Cannot find the ending portion of the zip file. If this is a " "spanned zip file, please insert the last disk and press OK.", "Insert disk", MB_OKCANCEL ); } else { CString sMsg; sMsg.Format( "Please insert disk #%d in drive.", lDiskNumber ); nAnswer = MessageBox( NULL, sMsg, "Insert disk", MB_OKCANCEL ); } *bDiskInserted = ( nAnswer == IDOK ); }