398 399 // Increase the buffer size for 1 additional null-terminating character. 400 bytesCopied += sizeof(TCHAR); 401 TCHAR* tabTipFilePath = new TCHAR[bytesCopied / sizeof(TCHAR)]; 402 ::memset(tabTipFilePath, 0, bytesCopied); 403 404 DWORD oldBytesCopied = bytesCopied; 405 if (::RegQueryValueEx(hTabTipCoKey, NULL, NULL, NULL, 406 (LPBYTE)tabTipFilePath, &bytesCopied) == ERROR_SUCCESS) { 407 const TCHAR searchedStr[] = _T("%CommonProgramFiles%"); 408 const size_t searchedStrLen = ::_tcslen(searchedStr); 409 int searchedStrStartIndex = -1; 410 411 TCHAR* commonFilesDirPath = NULL; 412 DWORD commonFilesDirPathLen = 0; 413 414 // Check, if '%CommonProgramFiles%' string is present in the defined 415 // path of the touch keyboard executable. 416 TCHAR* const searchedStrStart = ::_tcsstr(tabTipFilePath, searchedStr); 417 if (searchedStrStart != NULL) { 418 searchedStrStartIndex = searchedStrStart - tabTipFilePath; 419 420 // Get value of 'CommonProgramFiles' environment variable, if the 421 // file path of the touch keyboard executable was found in 32-bit 422 // registry view, otherwise get value of 'CommonProgramW6432'. 423 const TCHAR envVar32BitName[] = _T("CommonProgramFiles"); 424 const TCHAR envVar64BitName[] = _T("CommonProgramW6432"); 425 const TCHAR* envVarName = (regViewWithTabTipCoKey == WOW64_32BIT ? 426 envVar32BitName : envVar64BitName); 427 428 DWORD charsStored = ::GetEnvironmentVariable(envVarName, NULL, 0); 429 if (charsStored > 0) { 430 commonFilesDirPath = new TCHAR[charsStored]; 431 ::memset(commonFilesDirPath, 0, charsStored * sizeof(TCHAR)); 432 433 DWORD oldCharsStored = charsStored; 434 if (((charsStored = ::GetEnvironmentVariable(envVarName, 435 commonFilesDirPath, charsStored)) > 0) && 436 (charsStored <= oldCharsStored)) { 437 commonFilesDirPathLen = charsStored; 438 } else { 439 delete[] commonFilesDirPath; 440 commonFilesDirPath = NULL; 441 } 442 } 443 } 444 445 // Calculate 'm_touchKbrdExeFilePath' length in characters including 446 // the null-terminating character. 447 DWORD exeFilePathLen = oldBytesCopied / sizeof(TCHAR); 448 if (commonFilesDirPathLen > 0) { 449 exeFilePathLen = exeFilePathLen - searchedStrLen + 450 commonFilesDirPathLen; 451 } 452 453 if (m_touchKbrdExeFilePath != NULL) { 454 delete[] m_touchKbrdExeFilePath; 455 m_touchKbrdExeFilePath = NULL; 456 } 457 m_touchKbrdExeFilePath = new TCHAR[exeFilePathLen]; 458 ::memset(m_touchKbrdExeFilePath, 0, exeFilePathLen * sizeof(TCHAR)); 459 460 if (commonFilesDirPathLen > 0) { 461 ::_tcsncpy_s(m_touchKbrdExeFilePath, exeFilePathLen, tabTipFilePath, 462 searchedStrStartIndex); 463 DWORD charsCopied = searchedStrStartIndex; 464 465 ::_tcsncpy_s(m_touchKbrdExeFilePath + charsCopied, 466 exeFilePathLen - charsCopied, commonFilesDirPath, 467 commonFilesDirPathLen); 468 charsCopied += commonFilesDirPathLen; 469 | 398 399 // Increase the buffer size for 1 additional null-terminating character. 400 bytesCopied += sizeof(TCHAR); 401 TCHAR* tabTipFilePath = new TCHAR[bytesCopied / sizeof(TCHAR)]; 402 ::memset(tabTipFilePath, 0, bytesCopied); 403 404 DWORD oldBytesCopied = bytesCopied; 405 if (::RegQueryValueEx(hTabTipCoKey, NULL, NULL, NULL, 406 (LPBYTE)tabTipFilePath, &bytesCopied) == ERROR_SUCCESS) { 407 const TCHAR searchedStr[] = _T("%CommonProgramFiles%"); 408 const size_t searchedStrLen = ::_tcslen(searchedStr); 409 int searchedStrStartIndex = -1; 410 411 TCHAR* commonFilesDirPath = NULL; 412 DWORD commonFilesDirPathLen = 0; 413 414 // Check, if '%CommonProgramFiles%' string is present in the defined 415 // path of the touch keyboard executable. 416 TCHAR* const searchedStrStart = ::_tcsstr(tabTipFilePath, searchedStr); 417 if (searchedStrStart != NULL) { 418 searchedStrStartIndex = static_cast<int>(searchedStrStart - tabTipFilePath); 419 420 // Get value of 'CommonProgramFiles' environment variable, if the 421 // file path of the touch keyboard executable was found in 32-bit 422 // registry view, otherwise get value of 'CommonProgramW6432'. 423 const TCHAR envVar32BitName[] = _T("CommonProgramFiles"); 424 const TCHAR envVar64BitName[] = _T("CommonProgramW6432"); 425 const TCHAR* envVarName = (regViewWithTabTipCoKey == WOW64_32BIT ? 426 envVar32BitName : envVar64BitName); 427 428 DWORD charsStored = ::GetEnvironmentVariable(envVarName, NULL, 0); 429 if (charsStored > 0) { 430 commonFilesDirPath = new TCHAR[charsStored]; 431 ::memset(commonFilesDirPath, 0, charsStored * sizeof(TCHAR)); 432 433 DWORD oldCharsStored = charsStored; 434 if (((charsStored = ::GetEnvironmentVariable(envVarName, 435 commonFilesDirPath, charsStored)) > 0) && 436 (charsStored <= oldCharsStored)) { 437 commonFilesDirPathLen = charsStored; 438 } else { 439 delete[] commonFilesDirPath; 440 commonFilesDirPath = NULL; 441 } 442 } 443 } 444 445 // Calculate 'm_touchKbrdExeFilePath' length in characters including 446 // the null-terminating character. 447 DWORD exeFilePathLen = oldBytesCopied / sizeof(TCHAR); 448 if (commonFilesDirPathLen > 0) { 449 exeFilePathLen = exeFilePathLen - static_cast<DWORD>(searchedStrLen) + 450 commonFilesDirPathLen; 451 } 452 453 if (m_touchKbrdExeFilePath != NULL) { 454 delete[] m_touchKbrdExeFilePath; 455 m_touchKbrdExeFilePath = NULL; 456 } 457 m_touchKbrdExeFilePath = new TCHAR[exeFilePathLen]; 458 ::memset(m_touchKbrdExeFilePath, 0, exeFilePathLen * sizeof(TCHAR)); 459 460 if (commonFilesDirPathLen > 0) { 461 ::_tcsncpy_s(m_touchKbrdExeFilePath, exeFilePathLen, tabTipFilePath, 462 searchedStrStartIndex); 463 DWORD charsCopied = searchedStrStartIndex; 464 465 ::_tcsncpy_s(m_touchKbrdExeFilePath + charsCopied, 466 exeFilePathLen - charsCopied, commonFilesDirPath, 467 commonFilesDirPathLen); 468 charsCopied += commonFilesDirPathLen; 469 |