]> git.lyx.org Git - lyx.git/blob - src/support/os_win32.h
Fixup commit 50060053
[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 < 0x0500
40 #   error WINVER must be >= 0x0500
41 #  endif
42 # else
43 #  define WINVER 0x0500
44 # endif
45 # define _WIN32_IE 0x0500
46 #endif
47
48 #include <windows.h>
49 #include <tchar.h>
50 #include <psapi.h>
51
52
53 namespace lyx {
54 namespace support {
55 namespace os {
56
57 /** Win98 and earlier don't have SHGetFolderPath in shell32.dll.
58  *  Microsoft recommend that we load shfolder.dll at run time and
59  *  access the function through that.
60  *
61  *  shfolder.dll is loaded dynamically in the constructor. If loading
62  *  fails or if the .dll is found not to contain SHGetFolderPathA then
63  *  the program exits immediately. Otherwise, the .dll is unloaded in
64  *  the destructor
65  *
66  *  The class makes SHGetFolderPath available through its function operator.
67  *  It will work on all versions of Windows >= Win95.
68  */
69 class GetFolderPath {
70 public:
71         enum folder_id {
72                 /// CSIDL_PERSONAL
73                 PERSONAL,
74                 /// CSIDL_APPDATA
75                 APPDATA
76         };
77
78         GetFolderPath();
79         ~GetFolderPath();
80
81         /** Wrapper for SHGetFolderPathA, returning
82          *  the path asscociated with @c id in utf8 encoding.
83          */
84         std::string const operator()(folder_id id) const;
85 private:
86         typedef HRESULT (__stdcall * function_pointer)(HWND, int, HANDLE, DWORD, LPCSTR);
87
88         HMODULE folder_module_;
89         function_pointer folder_path_func_;
90 };
91
92 } // namespace os
93 } // namespace support
94 } // namespace lyx
95
96 #endif // OS_WIN32_H