OSDN Git Service

b6bd3a5363aecd7bada4df271711c4e189bb97b9
[qt-creator-jp/qt-creator-jp.git] / src / shared / registryaccess / registryaccess.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 // Some functions used by qtcreator.exe and qtcdebugger.exe to check if
35 // qtcdebugger is currently registered for post-mortem debugging.
36 // This is only needed on Windows.
37
38 #ifndef REGISTRYACCESS_H
39 #define REGISTRYACCESS_H
40
41 #include <QtCore/QString>
42 #include <QtCore/QLatin1String>
43
44 #include <Windows.h>
45
46 namespace RegistryAccess {
47
48 static const char *debuggerApplicationFileC = "qtcdebugger";
49 static const WCHAR *debuggerRegistryKeyC = L"Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug";
50 static const WCHAR *debuggerRegistryValueNameC = L"Debugger";
51
52 static inline QString wCharToQString(const WCHAR *w)
53 {
54     return QString::fromUtf16(reinterpret_cast<const ushort *>(w));
55 }
56
57 QString msgFunctionFailed(const char *f, unsigned long error);
58
59 static inline QString msgRegistryOperationFailed(const char *op, const WCHAR *valueName, const QString &why)
60 {
61     QString rc = QLatin1String("Registry ");
62     rc += QLatin1String(op);
63     rc += QLatin1String(" of ");
64     rc += wCharToQString(valueName);
65     rc += QLatin1String(" failed: ");
66     rc += why;
67     return rc;
68 }
69
70 bool registryReadStringKey(HKEY handle, // HKEY_LOCAL_MACHINE, etc.
71                            const WCHAR *valueName,
72                            QString *s,
73                            QString *errorMessage);
74
75 bool openRegistryKey(HKEY category, // HKEY_LOCAL_MACHINE, etc.
76                      const WCHAR *key,
77                      bool readWrite,
78                      HKEY *keyHandle,
79                      QString *errorMessage);
80
81 QString debuggerCall(const QString &additionalOption = QString());
82
83 bool isRegistered(HKEY handle, const QString &call, QString *errorMessage, QString *oldDebugger = 0);
84
85 } // namespace RegistryAccess
86
87 #endif // REGISTRYACCESS_H