OpenTTD Source: src/os/windows/win32.h Source File

OpenTTD Source 13.1

win32.h
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #ifndef WIN32_H
11 #define WIN32_H
12
13 #include <windows.h>
14 bool MyShowCursor(bool show, bool toggle = false);
15
16 class DllLoader {
17 public:
18 explicit DllLoader(LPCTSTR filename)
19 {
20 this->hmodule = ::LoadLibrary(filename);
21 if (this->hmodule == nullptr) this->success = false;
22 }
23
24
25 ~DllLoader()
26 {
27 ::FreeLibrary(this->hmodule);
28 }
29
30 bool Success() { return this->success; }
31
32 class ProcAddress {
33 public:
34 explicit ProcAddress(void *p) : p(p) {}
35
36 template <typename T, typename = std::enable_if_t<std::is_function_v<T>>>
37 operator T *() const
38 {
39 return reinterpret_cast<T *>(this->p);
40 }
41
42 private:
43 void *p;
44 };
45
46 ProcAddress GetProcAddress(const char *proc_name)
47 {
48 void *p = reinterpret_cast<void *>(::GetProcAddress(this->hmodule, proc_name));
49 if (p == nullptr) this->success = false;
50 return ProcAddress(p);
51 }
52
53 private:
54 HMODULE hmodule = nullptr;
55 bool success = true;
56 };
57
58 char *convert_from_fs(const wchar_t *name, char *utf8_buf, size_t buflen);
59 wchar_t *convert_to_fs(const char *name, wchar_t *utf16_buf, size_t buflen);
60
61 void Win32SetCurrentLocaleName(const char *iso_code);
62 int OTTDStringCompare(const char *s1, const char *s2);
63
64 #endif /* WIN32_H */
DllLoader::ProcAddress
Definition: win32.h:32
convert_from_fs
char * convert_from_fs(const wchar_t *name, char *utf8_buf, size_t buflen)
Convert to OpenTTD's encoding from that of the environment in UNICODE.
Definition: win32.cpp:580
convert_to_fs
wchar_t * convert_to_fs(const char *name, wchar_t *utf16_buf, size_t buflen)
Convert from OpenTTD's encoding to that of the environment in UNICODE.
Definition: win32.cpp:600
DllLoader
Definition: win32.h:16