LPVOID CFileMap::Open(HANDLE hFile, DWORD Mode) { // Create a file mapping object. if (Mode == FILE_READ) m_hFileMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL); else if (Mode == FILE_WRITE) m_hFileMap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, 0, NULL); if (m_hFileMap == INVALID_HANDLE_VALUE) { CError error; error.Message(GetForegroundWindow(), _T("File mapping error.")); return NULL; } // Get start address of the map view. if (Mode == FILE_READ) m_lpFileMapBase = MapViewOfFile(m_hFileMap, FILE_MAP_READ, 0, 0, 0); else if (Mode == FILE_WRITE) m_lpFileMapBase = MapViewOfFile(m_hFileMap, FILE_MAP_WRITE, 0, 0, 0); if (m_lpFileMapBase == NULL) { CError error; error.Message(GetForegroundWindow(), _T("File mapping error.")); return NULL; } m_lpFileMap = m_lpFileMapBase; return m_lpFileMapBase; }
BOOL CFolderDialog::DoModal(HWND hWnd, LPCTSTR lpszTitle, LPTSTR pDir) { BROWSEINFO bi = {}; bi.hwndOwner = hWnd; bi.lpfn = reinterpret_cast<BFFCALLBACK>(BrowseCallBackProc); bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI; bi.lParam = reinterpret_cast<LPARAM>(pDir); bi.lpszTitle = lpszTitle; LPITEMIDLIST pItemID = SHBrowseForFolder(&bi); if (pItemID == nullptr) return FALSE; LPMALLOC pMalloc = nullptr; if (SHGetMalloc(&pMalloc) == E_FAIL) { CError error; error.Message(hWnd, _T("SHGetMalloc Error")); return FALSE; } SHGetPathFromIDList(pItemID, pDir); pMalloc->Free(pItemID); pMalloc->Release(); return TRUE; }