|
27 | 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 | 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
|
30 | | -#include "win32/base/input_dll.h" |
| 30 | +// This file will be used to create an import library. Functions in this |
| 31 | +// file must not be called directly. |
31 | 32 |
|
32 | | -#include "base/logging.h" |
33 | | -#include "base/util.h" |
34 | | -#include "base/win_util.h" |
35 | | - |
36 | | -namespace mozc { |
37 | | -namespace win32 { |
38 | | - |
39 | | -const wchar_t kInputDllName[] = L"input.dll"; |
40 | | - |
41 | | -const char kEnumEnabledLayoutOrTipName[] = "EnumEnabledLayoutOrTip"; |
42 | | -const char kEnumLayoutOrTipForSetup[] = "EnumLayoutOrTipForSetup"; |
43 | | -const char kInstallLayoutOrTipName[] = "InstallLayoutOrTip"; |
44 | | -const char kInstallLayoutOrTipUserRegName[] = "InstallLayoutOrTipUserReg"; |
45 | | -const char kSetDefaultLayoutOrTipName[] = "SetDefaultLayoutOrTip"; |
46 | | - |
47 | | -bool InputDll::EnsureInitialized() { |
48 | | - if (not_found_) { |
49 | | - // Previous trial was not successful. give up. |
50 | | - return false; |
51 | | - } |
52 | | - |
53 | | - if (module_ != nullptr) { |
54 | | - // Already initialized. |
55 | | - return true; |
56 | | - } |
57 | | - |
58 | | - bool lock_held = false; |
59 | | - if (!WinUtil::IsDLLSynchronizationHeld(&lock_held)) { |
60 | | - LOG(ERROR) << "IsDLLSynchronizationHeld failed."; |
61 | | - return false; |
62 | | - } |
63 | | - if (lock_held) { |
64 | | - LOG(INFO) << "This thread has loader lock. " |
65 | | - << "LoadLibrary should not be called."; |
66 | | - return false; |
67 | | - } |
68 | | - |
69 | | - const HMODULE input_dll = WinUtil::LoadSystemLibrary(kInputDllName); |
70 | | - if (input_dll == nullptr) { |
71 | | - const int last_error = ::GetLastError(); |
72 | | - DLOG(INFO) << "LoadSystemLibrary(\"" << kInputDllName << "\") failed. " |
73 | | - << "error = " << last_error; |
74 | | - if (last_error == ERROR_MOD_NOT_FOUND) { |
75 | | - not_found_ = true; |
76 | | - } |
77 | | - return false; |
78 | | - } |
79 | | - |
80 | | - enum_enabled_layout_or_tip_ = |
81 | | - reinterpret_cast<FPEnumEnabledLayoutOrTip>( |
82 | | - ::GetProcAddress(input_dll, kEnumEnabledLayoutOrTipName)); |
83 | | - |
84 | | - enum_layout_or_tip_for_setup_ = |
85 | | - reinterpret_cast<FPEnumLayoutOrTipForSetup>( |
86 | | - ::GetProcAddress(input_dll, kEnumLayoutOrTipForSetup)); |
| 33 | +#include <windows.h> |
87 | 34 |
|
88 | | - install_layout_or_tip_ = |
89 | | - reinterpret_cast<FPInstallLayoutOrTip>( |
90 | | - ::GetProcAddress(input_dll, kInstallLayoutOrTipName)); |
91 | | - |
92 | | - install_layout_or_tip_user_reg_ = |
93 | | - reinterpret_cast<FPInstallLayoutOrTipUserReg>( |
94 | | - ::GetProcAddress(input_dll, kInstallLayoutOrTipUserRegName)); |
95 | | - |
96 | | - set_default_layout_or_tip_ = |
97 | | - reinterpret_cast<FPSetDefaultLayoutOrTip>( |
98 | | - ::GetProcAddress(input_dll, kSetDefaultLayoutOrTipName)); |
99 | | - |
100 | | - // Other threads may load the same DLL concurrently. |
101 | | - // Check if this thread is the first thread which updated the |module_|. |
102 | | - const HMODULE original = static_cast<HMODULE>( |
103 | | - ::InterlockedCompareExchangePointer( |
104 | | - reinterpret_cast<volatile PVOID *>(&module_), input_dll, nullptr)); |
105 | | - if (original == nullptr) { |
106 | | - // This is the first thread which updated the |module_| with valid handle. |
107 | | - // Do not call FreeLibrary to keep the reference count positive. |
108 | | - } else { |
109 | | - // |module_| has already been updated by another thread. Call FreeLibrary |
110 | | - // to decrement the reference count which this thread owns. |
111 | | - ::FreeLibrary(input_dll); |
112 | | - } |
113 | | - |
114 | | - return true; |
115 | | -} |
| 35 | +#include "base/logging.h" |
116 | 36 |
|
117 | | -InputDll::FPEnumEnabledLayoutOrTip InputDll::enum_enabled_layout_or_tip() { |
118 | | - return enum_enabled_layout_or_tip_; |
| 37 | +struct LAYOUTORTIPPROFILE; |
| 38 | +struct LAYOUTORTIP; |
| 39 | + |
| 40 | +extern "C" |
| 41 | +UINT WINAPI EnumEnabledLayoutOrTip( |
| 42 | + __in_opt LPCWSTR pszUserReg, |
| 43 | + __in_opt LPCWSTR pszSystemReg, |
| 44 | + __in_opt LPCWSTR pszSoftwareReg, |
| 45 | + __out LAYOUTORTIPPROFILE *pLayoutOrTipProfile, |
| 46 | + __in UINT uBufLength) { |
| 47 | + CHECK(false) |
| 48 | + << "This is a stub function to create an import library. " |
| 49 | + << "Shouldn't be called from anywhere."; |
| 50 | + return 0; |
119 | 51 | } |
120 | 52 |
|
121 | | -InputDll::FPEnumLayoutOrTipForSetup InputDll::enum_layout_or_tip_for_setup() { |
122 | | - return enum_layout_or_tip_for_setup_; |
| 53 | +extern "C" |
| 54 | +UINT WINAPI EnumLayoutOrTipForSetup( |
| 55 | + __in LANGID langid, |
| 56 | + __out_ecount(uBufLength) LAYOUTORTIP *pLayoutOrTip, |
| 57 | + __in UINT uBufLength, |
| 58 | + __in DWORD dwFlags) { |
| 59 | + CHECK(false) |
| 60 | + << "This is a stub function to create an import library. " |
| 61 | + << "Shouldn't be called from anywhere."; |
| 62 | + return 0; |
123 | 63 | } |
124 | 64 |
|
125 | | -InputDll::FPInstallLayoutOrTip InputDll::install_layout_or_tip() { |
126 | | - return install_layout_or_tip_; |
| 65 | +extern "C" |
| 66 | +BOOL WINAPI InstallLayoutOrTip( |
| 67 | + __in LPCWSTR psz, |
| 68 | + __in DWORD dwFlags) { |
| 69 | + CHECK(false) |
| 70 | + << "This is a stub function to create an import library. " |
| 71 | + << "Shouldn't be called from anywhere."; |
| 72 | + return FALSE; |
127 | 73 | } |
128 | 74 |
|
129 | | -InputDll::FPInstallLayoutOrTipUserReg |
130 | | - InputDll::install_layout_or_tip_user_reg() { |
131 | | - return install_layout_or_tip_user_reg_; |
| 75 | +extern "C" |
| 76 | +BOOL WINAPI InstallLayoutOrTipUserReg( |
| 77 | + __in_opt LPCWSTR pszUserReg, |
| 78 | + __in_opt LPCWSTR pszSystemReg, |
| 79 | + __in_opt LPCWSTR pszSoftwareReg, |
| 80 | + __in LPCWSTR psz, |
| 81 | + __in DWORD dwFlags) { |
| 82 | + CHECK(false) |
| 83 | + << "This is a stub function to create an import library. " |
| 84 | + << "Shouldn't be called from anywhere."; |
| 85 | + return FALSE; |
132 | 86 | } |
133 | 87 |
|
134 | | -InputDll::FPSetDefaultLayoutOrTip InputDll::set_default_layout_or_tip() { |
135 | | - return set_default_layout_or_tip_; |
| 88 | +extern "C" |
| 89 | +BOOL WINAPI SetDefaultLayoutOrTip( |
| 90 | + __in LPCWSTR psz, |
| 91 | + DWORD dwFlags) { |
| 92 | + CHECK(false) |
| 93 | + << "This is a stub function to create an import library. " |
| 94 | + << "Shouldn't be called from anywhere."; |
| 95 | + return FALSE; |
136 | 96 | } |
137 | | - |
138 | | -bool InputDll::not_found_; |
139 | | - |
140 | | -volatile HMODULE InputDll::module_; |
141 | | -InputDll::FPEnumEnabledLayoutOrTip InputDll::enum_enabled_layout_or_tip_; |
142 | | -InputDll::FPEnumLayoutOrTipForSetup InputDll::enum_layout_or_tip_for_setup_; |
143 | | -InputDll::FPInstallLayoutOrTip InputDll::install_layout_or_tip_; |
144 | | -InputDll::FPInstallLayoutOrTipUserReg |
145 | | -InputDll::install_layout_or_tip_user_reg_; |
146 | | -InputDll::FPSetDefaultLayoutOrTip InputDll::set_default_layout_or_tip_; |
147 | | - |
148 | | -} // namespace win32 |
149 | | -} // namespace mozc |
0 commit comments