home *** CD-ROM | disk | FTP | other *** search
- /*==================================================================
- File: Win32ZStringTools.cpp
-
- Contains: Defines the class behaviors for the application
-
- Written by: Nalini Prakash
-
- Copyright: 2000-2001 Connectix Corporation
-
- This source has been placed into the public domain by
- Connectix Corporation. You have the right to modify,
- distribute or use this code without any legal limitations
- or finanicial/licensing requirements. Connectix is not
- liable for any problems that result from the use of this
- code.
-
- If you have comments, feedback, questions, or would like
- to submit bug fixes or updates to this code, please email
- opensource@connectix.com.
- ==================================================================*/
-
- #include "StdAfx.h"
- #include "Win32ZStringTools.h"
- #include "Win32ZStringToolsDlg.h"
-
- #include "ZStringTypes.h"
- #include "resource.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CWin32ZStringToolsApp
-
- BEGIN_MESSAGE_MAP(CWin32ZStringToolsApp, CWinApp)
- //{{AFX_MSG_MAP(CWin32ZStringToolsApp)
- //}}AFX_MSG_MAP
- ON_COMMAND(ID_HELP, CWinApp::OnHelp)
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CWin32ZStringToolsApp construction
-
- CWin32ZStringToolsApp::CWin32ZStringToolsApp()
- {
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // The one and only CWin32ZStringToolsApp object
-
- CWin32ZStringToolsApp theApp;
-
- /////////////////////////////////////////////////////////////////////////////
- // CWin32ZStringToolsApp initialization
-
- BOOL CWin32ZStringToolsApp::InitInstance()
- {
- AfxEnableControlContainer();
-
- // Standard initialization
- // If you are not using these features and wish to reduce the size
- // of your final executable, you should remove from the following
- // the specific initialization routines you do not need.
-
- #ifdef _AFXDLL
- Enable3dControls(); // Call this when using MFC in a shared DLL
- #else
- Enable3dControlsStatic(); // Call this when linking to MFC statically
- #endif
-
- ::OleInitialize(NULL); // Enable Drag & drop
-
- CWin32ZStringToolsDlg dlg;
- m_pMainWnd = &dlg;
- int nResponse = dlg.DoModal();
-
- // Since the dialog has been closed, return FALSE so that we exit the
- // application, rather than start the application's message pump.
- return FALSE;
- }
-
-
- /*------------------------------------------------------------------
- OpenMemMappedFile
-
- Open file and create memory mapped view.
- ------------------------------------------------------------------*/
-
- BOOL
- OpenMemMappedFile(
- const char * inPathName,
- HANDLE & outFileHandle,
- HANDLE & outMemfileHandle,
- char *& outData,
- Z_UInt32 & outSize)
- {
- outSize = 0;
- outData = NULL;
- outFileHandle = INVALID_HANDLE_VALUE;
-
- // Open the file.
- outFileHandle = ::CreateFile(
- inPathName, // file name
- GENERIC_READ, // access mode
- FILE_SHARE_READ, // share mode
- NULL, // SD
- OPEN_EXISTING, // how to create, fails if file doesn't exist
- FILE_ATTRIBUTE_NORMAL, // file attributes
- NULL); // handle to template file
-
- if (outFileHandle == INVALID_HANDLE_VALUE)
- return false;
-
- DWORD sizeLow = 0;
- DWORD sizeHigh = 0;
- sizeLow = ::GetFileSize (outFileHandle, &sizeHigh);
- outSize = sizeLow;
-
- // Create file mapping.
- outMemfileHandle = ::CreateFileMapping(
- outFileHandle, // handle to file
- NULL, // security
- PAGE_READONLY, // protection
- sizeHigh, // high-order DWORD of size
- outSize, // low-order DWORD of size
- NULL); // object name
-
- if (outMemfileHandle)
- {
- // Map file into memory.
- outData = (char *)::MapViewOfFile(
- outMemfileHandle, // handle to file-mapping object
- FILE_MAP_READ, // access mode
- 0, // high-order DWORD of offset
- 0, // low-order DWORD of offset
- 0); // number of bytes to map - map entire file.
- }
- else
- {
- // Display Error Message.
- DWORD err = ::GetLastError();
- CloseHandle(outFileHandle);
- outFileHandle = INVALID_HANDLE_VALUE;
- }
-
- return (outData != NULL);
- }
-
-
- /*------------------------------------------------------------------
- CloseFiles
- ------------------------------------------------------------------*/
-
- void
- CloseFiles(
- void * inData,
- HANDLE & inMemFileHandle,
- HANDLE & inFileHandle)
- {
- ::UnmapViewOfFile(inData);
- inData = 0;
-
- ::CloseHandle(inMemFileHandle);
- inMemFileHandle = INVALID_HANDLE_VALUE;
-
- ::CloseHandle(inFileHandle);
- inFileHandle = INVALID_HANDLE_VALUE;
- }
-
-