|
33 | 33 | #include <windows.h> |
34 | 34 | #include <atlbase.h> |
35 | 35 | #include <msiquery.h> |
36 | | -// clang-format on |
37 | | - |
38 | | -#if defined(MOZC_ENABLE_WIN_UNIVERSAL_INSTALLER) |
39 | 36 | #include <wow64apiset.h> |
40 | | -#endif // defined(MOZC_ENABLE_WIN_UNIVERSAL_INSTALLER) |
| 37 | +// clang-format on |
41 | 38 |
|
42 | 39 | #undef StrCat // NOLINT: TODO: triggers clang-tidy, defined by windows.h. |
43 | 40 |
|
@@ -457,44 +454,43 @@ UINT __stdcall RegisterTIP(MSIHANDLE msi_handle) { |
457 | 454 | mozc::ScopedCOMInitializer com_initializer; |
458 | 455 | HRESULT result = S_OK; |
459 | 456 |
|
460 | | -#if defined(MOZC_ENABLE_WIN_UNIVERSAL_INSTALLER) |
| 457 | + // Register 64-bit TIP COM server. |
461 | 458 | // Unlike 32-bit TIP DLL, which is always x86, the expected 64-bit TIP DLL |
462 | | - // can be x64 or ARM64X depending on the target environment. This is why |
463 | | - // only 64-bit TIP DLL is dynamically registered here. |
464 | | - |
465 | | - // |IsWow64Process2| is added in Windows 10 1709 / Windows Server 1709. Let's |
466 | | - // check if the API is available before calling it. |
467 | | - // TODO: Directly call |IsWow64Process2| after we stop supporting Windows 10. |
| 459 | + // can be x64 or ARM64X depending on the target environment. |
468 | 460 | USHORT process_machine = IMAGE_FILE_MACHINE_UNKNOWN; |
469 | 461 | USHORT native_machine = IMAGE_FILE_MACHINE_UNKNOWN; |
470 | | - auto IsWow64Process2Func = reinterpret_cast<decltype(&::IsWow64Process2)>( |
471 | | - ::GetProcAddress(::GetModuleHandleA("kernel32.dll"), "IsWow64Process2")); |
472 | | - if (IsWow64Process2Func != nullptr) [[likely]] { |
473 | | - result = IsWow64Process2Func(::GetCurrentProcess(), &process_machine, |
474 | | - &native_machine); |
475 | | - } else { |
476 | | - // Fallback to x64. |
477 | | - result = E_NOTIMPL; |
478 | | - } |
| 462 | + result = IsWow64Process2(::GetCurrentProcess(), &process_machine, |
| 463 | + &native_machine); |
479 | 464 | const bool is_arm64_machine = |
480 | 465 | SUCCEEDED(result) && native_machine == IMAGE_FILE_MACHINE_ARM64; |
481 | | - const std::wstring& tip64_path = GetMozcComponentPath( |
| 466 | + const std::wstring tip64_path = GetMozcComponentPath( |
482 | 467 | is_arm64_machine ? mozc::kMozcTIP64X : mozc::kMozcTIP64); |
483 | 468 |
|
484 | | - result = mozc::win32::TsfRegistrar::RegisterCOMServer(tip64_path.c_str(), |
485 | | - tip64_path.length()); |
| 469 | + result = mozc::win32::TsfRegistrar::RegisterCOMServer( |
| 470 | + tip64_path.c_str(), tip64_path.length(), |
| 471 | + mozc::win32::COMServerBitness::k64bit); |
486 | 472 | if (FAILED(result)) { |
487 | 473 | LOG_ERROR_FOR_OMAHA(); |
488 | 474 | UnregisterTIP(msi_handle); |
489 | 475 | return ERROR_INSTALL_FAILURE; |
490 | 476 | } |
491 | | -#endif // defined(MOZC_ENABLE_WIN_UNIVERSAL_INSTALLER) |
492 | 477 |
|
| 478 | + // Register 32-bit TIP COM server. |
| 479 | + const std::wstring tip32_path = GetMozcComponentPath(mozc::kMozcTIP32); |
| 480 | + result = mozc::win32::TsfRegistrar::RegisterCOMServer( |
| 481 | + tip32_path.c_str(), tip32_path.length(), |
| 482 | + mozc::win32::COMServerBitness::k32bit); |
| 483 | + if (FAILED(result)) { |
| 484 | + LOG_ERROR_FOR_OMAHA(); |
| 485 | + UnregisterTIP(msi_handle); |
| 486 | + return ERROR_INSTALL_FAILURE; |
| 487 | + } |
| 488 | + |
| 489 | + // Register profiles and categories. |
493 | 490 | // The path here is to retrieve Win32 resources such as icon and product name, |
494 | 491 | // which does not need to match the native CPU architecture. Here we use |
495 | 492 | // 32-bit TIP DLL as it is always installed even on an ARM64 target. |
496 | | - const std::wstring resource_dll_path = GetMozcComponentPath(mozc::kMozcTIP32); |
497 | | - result = mozc::win32::TsfRegistrar::RegisterProfiles(resource_dll_path); |
| 493 | + result = mozc::win32::TsfRegistrar::RegisterProfiles(tip32_path); |
498 | 494 | if (FAILED(result)) { |
499 | 495 | LOG_ERROR_FOR_OMAHA(); |
500 | 496 | UnregisterTIP(msi_handle); |
@@ -523,13 +519,10 @@ UINT __stdcall UnregisterTIP(MSIHANDLE msi_handle) { |
523 | 519 |
|
524 | 520 | mozc::win32::TsfRegistrar::UnregisterCategories(); |
525 | 521 | mozc::win32::TsfRegistrar::UnregisterProfiles(); |
526 | | - |
527 | | -#if defined(MOZC_ENABLE_WIN_UNIVERSAL_INSTALLER) |
528 | | - // Unlike 32-bit TIP DLL, which is always x86, the expected 64-bit TIP DLL |
529 | | - // can be x64 or ARM64X depending on the target environment. This is why |
530 | | - // only 64-bit TIP DLL is dynamically unregistered here. |
531 | | - mozc::win32::TsfRegistrar::UnregisterCOMServer(); |
532 | | -#endif // defined(MOZC_ENABLE_WIN_UNIVERSAL_INSTALLER) |
| 522 | + mozc::win32::TsfRegistrar::UnregisterCOMServer( |
| 523 | + mozc::win32::COMServerBitness::k64bit); |
| 524 | + mozc::win32::TsfRegistrar::UnregisterCOMServer( |
| 525 | + mozc::win32::COMServerBitness::k32bit); |
533 | 526 |
|
534 | 527 | return ERROR_SUCCESS; |
535 | 528 | } |
|
0 commit comments