//////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////// PUBLIC FUNCTIONS ///////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////// int GetFolderPath(FolderType folder,wchar_t *path,unsigned int pathsize) { int iReturnCode = RETURN_OK; switch(folder) { case FOLDER_SYSTEM32: if(0==GetSystemDirectory(path,pathsize)) { LOG(L" --> ERROR - GetFolderPath - System32 folder not found (LastError=%d)\n", GetLastError()); iReturnCode = RETURN_ERR_INTERNAL; } break; case FOLDER_WOWSYS64: #ifdef WIN64 if(0==GetSystemWow64Directory(path,pathsize)) { LOG(L" --> ERROR - GetFolderPath - SystemWow64 folder not found (LastError=%d)\n", GetLastError()); iReturnCode = RETURN_ERR_INTERNAL; } #else if(IsWow64Proc()) { if(0==GetSystemWow64Directory(path,pathsize)) { LOG(L" --> ERROR - GetFolderPath - SystemWow64 folder not found (LastError=%d)\n", GetLastError()); iReturnCode = RETURN_ERR_INTERNAL; } } else { iReturnCode = RETURN_SKIP_FOLDER; } #endif break; case FOLDER_APP: if(-1==swprintf_s(path,pathsize,L"C:\\Program Files\\Belgium Identity Card")) { LOG(L" --> ERROR - GetFolderPath - Buffer too small\n"); iReturnCode = RETURN_ERR_INTERNAL; } break; default: if(0==GetTempPath(pathsize,path)) { LOG(L" --> ERROR - GetFolderPath - Temp folder not found (LastError=%d)\n", GetLastError()); iReturnCode = RETURN_ERR_INTERNAL; } break; } return iReturnCode; }
bool CBTFullLibPath::GetConditionalDllPathOf(TCHAR* szFileNameOnly, TCHAR* pOutBuf, size_t OutBufCapacity) { // Note: OutBufCapacity size is in TCHARs bool bResult = false; if ((NULL != szFileNameOnly) && (NULL != pOutBuf) && (OutBufCapacity > 0)) { EnterCriticalSection(&cs_libpath); if (m_fLoadedFullPath) { // Use SysWow64 path if detected as WOW64 TCHAR* target_folder = (IsWow64Proc() ? m_szInstDirSysWow64 : m_szInstallDir); _stprintf_s(pOutBuf, OutBufCapacity, _T("%s%s"), (LPCTSTR)target_folder, (LPCTSTR)szFileNameOnly); bResult = true; } else { _stprintf_s(pOutBuf, OutBufCapacity, _T("%s"), (LPCTSTR)szFileNameOnly); } LeaveCriticalSection(&cs_libpath); } return bResult; }
CBTFullLibPath::CBTFullLibPath() { if (1 == InterlockedIncrement(&m_nRefCount)) { InitializeCriticalSection(&cs_libpath); } EnterCriticalSection(&cs_libpath); if (!m_fLoadedFullPath) { // Retrieve BTW Install Directory from Registry and generate full BtRez.dll path DWORD dwResult = ERROR_SUCCESS; DWORD dwFlag; HKEY hKey; dwFlag = KEY_READ; m_bIsWow64 = IsWow64Proc(); if (m_bIsWow64) { dwFlag |= KEY_WOW64_64KEY; } if (ERROR_SUCCESS == (dwResult = RegOpenKeyEx(BT_INSTALL_PATH_REG_HIVE, BT_INSTALL_PATH_REG_KEY, 0, dwFlag, &hKey))) { // Retrieve BTW Install Directory Path DWORD dwBytes = sizeof(m_szInstallDir); dwResult = RegQueryValueEx (hKey, BT_INSTALL_PATH_REG_VALUE, NULL, NULL, (LPBYTE)m_szInstallDir, &dwBytes); RegCloseKey(hKey); // Include trailing '\' if not already included size_t path_len = _tcslen(m_szInstallDir); if ((path_len > 0) && (path_len < MAX_PATH)) { TCHAR last_char = m_szInstallDir[path_len-1]; if ((last_char != '\\') && (last_char != '/')) { _tcscat_s(m_szInstallDir, MAX_PATH, _T("\\")); } } if (ERROR_SUCCESS == dwResult) { // Also set SysWow64 path from install directory if (-1 == _stprintf_s(m_szInstDirSysWow64, MAX_PATH, _T("%s%s"), (LPCTSTR)m_szInstallDir, (LPCTSTR)BT_INSTALL_PATH_SYSWOW64)) { dwResult = ERROR_BAD_PATHNAME; } } if (ERROR_SUCCESS == dwResult) { // Generate full BtRez.dll path and take WOW64 into account TCHAR* target_folder = (IsWow64Proc() ? m_szInstDirSysWow64 : m_szInstallDir); if (-1 == _stprintf_s(m_szBtRezPath, MAX_PATH, _T("%s%s"), (LPCTSTR)target_folder, (LPCTSTR)BTREZ_DLL_FILENAME)) { dwResult = ERROR_BAD_PATHNAME; } } } bool bPathsLoaded = (ERROR_SUCCESS == dwResult); if (!bPathsLoaded) { // One or more steps failed; Fall back to BtRez name only _stprintf_s(m_szBtRezPath, MAX_PATH, _T("%s"), BTREZ_DLL_FILENAME); } m_fLoadedFullPath = bPathsLoaded; } LeaveCriticalSection(&cs_libpath); } // CBTFullLibPath::CBTFullLibPath