]> git.lyx.org Git - lyx.git/blob - src/support/os_win32.h
Update Win installer for new dictionary links. Untested.
[lyx.git] / src / support / os_win32.h
1 // -*- C++ -*-
2 /**
3  * \file os_win32.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  *
11  * These classes should be used only on Windows machines.
12  */
13
14 #ifndef OS_WIN32_H
15 #define OS_WIN32_H
16
17 #include <string>
18
19 #if !defined(_WIN32)
20 # error os_win32.h should be compiled only under Windows.
21 #endif
22
23 /* The GetLongPathNameA function declaration in
24  * <winbase.h> is protected by the WINVER macro which is
25  * defined to a default value in <windef.h> under MinGW and Cygwin.
26  *
27  * SHGFP_TYPE_CURRENT is defined in <shlobj.h> for __W32API_VERSION >= 3.2
28  * where it is protected by _WIN32_IE, also defined to a default value
29  * in <windef.h> under MinGW and Cygwin.
30  * It is missing in earlier versions of the MinGW w32api headers.
31  *
32  * We need to #include <windows.h> now to make available the
33  * DWORD, HMODULE et al. typedefs, so first define WINVER, _WIN32_IE.
34  *
35  * Note: __CYGWIN__ can be defined here if building in _WIN32 mode.
36  */
37 #if defined(__MINGW32__)  || defined(__CYGWIN__) || defined(__CYGWIN32__)
38 # if defined(WINVER)
39 #  if WINVER < 0x0600
40 #   error WINVER must be >= 0x0600
41 #  endif
42 # else
43 #  define WINVER 0x0600
44 # endif
45 # define _WIN32_IE 0x0600
46 #endif
47
48 #include <windows.h>
49 #include <tchar.h>
50 #include <psapi.h>
51
52 #ifdef IN
53 #undef IN // used in Length::UNIT enum
54 #endif
55
56 namespace lyx {
57 namespace support {
58 namespace os {
59
60 /** Win98 and earlier don't have SHGetFolderPath in shell32.dll.
61  *  Microsoft recommend that we load shfolder.dll at run time and
62  *  access the function through that.
63  *
64  *  shfolder.dll is loaded dynamically in the constructor. If loading
65  *  fails or if the .dll is found not to contain SHGetFolderPathA then
66  *  the program exits immediately. Otherwise, the .dll is unloaded in
67  *  the destructor
68  *
69  *  The class makes SHGetFolderPath available through its function operator.
70  *  It will work on all versions of Windows >= Win95.
71  */
72 class GetFolderPath {
73 public:
74         enum folder_id {
75                 /// CSIDL_PERSONAL
76                 PERSONAL,
77                 /// CSIDL_APPDATA
78                 APPDATA
79         };
80
81         GetFolderPath();
82         ~GetFolderPath();
83
84         /** Wrapper for SHGetFolderPathA, returning
85          *  the path associated with @c id in utf8 encoding.
86          */
87         std::string const operator()(folder_id id) const;
88 private:
89         typedef HRESULT (__stdcall * function_pointer)(HWND, int, HANDLE, DWORD, LPCSTR);
90
91         HMODULE folder_module_;
92         function_pointer folder_path_func_;
93 };
94
95 } // namespace os
96 } // namespace support
97 } // namespace lyx
98
99 #endif // OS_WIN32_H