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