2005-09-30 12:24:50 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file os_win32.h
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Angus Leeming
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*
|
|
|
|
* These classes should be used only on Windows machines.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OS_WIN32_H
|
|
|
|
#define OS_WIN32_H
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#if !defined(_WIN32)
|
|
|
|
# error os_win32.h should be compiled only under Windows.
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* The GetLongPathNameA function declaration in
|
2005-09-30 21:19:31 +00:00
|
|
|
* <winbase.h> is protected by the WINVER macro which is
|
|
|
|
* defined to a default value in <windef.h> under MinGW and Cygwin.
|
2005-09-30 12:24:50 +00:00
|
|
|
*
|
2005-09-30 21:19:31 +00:00
|
|
|
* SHGFP_TYPE_CURRENT is defined in <shlobj.h> for __W32API_VERSION >= 3.2
|
|
|
|
* where it is protected by _WIN32_IE, also defined to a default value
|
|
|
|
* in <windef.h> under MinGW and Cygwin.
|
|
|
|
* It is missing in earlier versions of the MinGW w32api headers.
|
|
|
|
*
|
2005-10-02 21:49:52 +00:00
|
|
|
* We need to #include <windows.h> now to make available the
|
2005-09-30 21:19:31 +00:00
|
|
|
* DWORD, HMODULE et al. typedefs, so first define WINVER, _WIN32_IE.
|
2005-09-30 12:24:50 +00:00
|
|
|
*
|
|
|
|
* Note: __CYGWIN__ can be defined here if building in _WIN32 mode.
|
|
|
|
*/
|
|
|
|
#if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__CYGWIN32__)
|
2005-09-30 21:19:31 +00:00
|
|
|
# if defined(WINVER) && WINVER < 0x0500
|
2005-09-30 12:24:50 +00:00
|
|
|
# error WINVER must be >= 0x0500
|
|
|
|
# endif
|
2005-09-30 21:19:31 +00:00
|
|
|
# define WINVER 0x0500
|
|
|
|
# define _WIN32_IE 0x0500
|
2005-09-30 12:24:50 +00:00
|
|
|
#endif
|
|
|
|
|
2005-10-02 21:49:52 +00:00
|
|
|
#include <windows.h>
|
2005-09-30 12:24:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace support {
|
|
|
|
namespace os {
|
|
|
|
|
|
|
|
/** Win98 and earlier don't have SHGetFolderPath in shell32.dll.
|
|
|
|
* Microsoft recommend that we load shfolder.dll at run time and
|
|
|
|
* access the function through that.
|
|
|
|
*
|
|
|
|
* shfolder.dll is loaded dynamically in the constructor. If loading
|
|
|
|
* fails or if the .dll is found not to contain SHGetFolderPathA then
|
|
|
|
* the program exits immediately. Otherwise, the .dll is unloaded in
|
|
|
|
* the destructor
|
|
|
|
*
|
|
|
|
* The class makes SHGetFolderPath available through its function operator.
|
|
|
|
* It will work on all versions of Windows >= Win95.
|
|
|
|
*/
|
|
|
|
class GetFolderPath {
|
|
|
|
public:
|
|
|
|
enum folder_id {
|
|
|
|
/// CSIDL_PERSONAL
|
|
|
|
PERSONAL,
|
|
|
|
/// CSIDL_APPDATA
|
|
|
|
APPDATA
|
|
|
|
};
|
|
|
|
|
|
|
|
GetFolderPath();
|
|
|
|
~GetFolderPath();
|
|
|
|
|
|
|
|
/** Wrapper for SHGetFolderPathA, returning
|
2007-01-18 20:47:27 +00:00
|
|
|
* the path asscociated with @c id in utf8 encoding.
|
2005-09-30 12:24:50 +00:00
|
|
|
*/
|
|
|
|
std::string const operator()(folder_id id) const;
|
|
|
|
private:
|
|
|
|
typedef HRESULT (__stdcall * function_pointer)(HWND, int, HANDLE, DWORD, LPCSTR);
|
|
|
|
|
|
|
|
HMODULE folder_module_;
|
|
|
|
function_pointer folder_path_func_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace os
|
|
|
|
} // namespace support
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
|
|
#endif // OS_WIN32_H
|