1 /* Copyright (C) 2014 InfiniDB, Inc.
2
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public License
5 as published by the Free Software Foundation; version 2 of
6 the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16 MA 02110-1301, USA. */
17
18 #include "idbregistry.h"
19
20 #define WIN32_LEAN_AND_MEAN
21 #define NOMINMAX
22 #include <windows.h>
23 #include <string>
24 using namespace std;
25
IDBreadRegistry(const string & name,bool returnShortName)26 const string IDBreadRegistry(const string& name, bool returnShortName)
27 {
28 HKEY hkResult;
29 LONG lResult;
30 lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Calpont\\InfiniDB", 0, KEY_READ, &hkResult);
31
32 if (lResult != ERROR_SUCCESS)
33 return string();
34
35 DWORD cbData = 1024;
36 TCHAR CfnameBuf[1024];
37 lResult = RegQueryValueEx(hkResult, name.c_str(), 0, 0, (LPBYTE)CfnameBuf, &cbData);
38 CloseHandle(hkResult);
39
40 if (lResult != ERROR_SUCCESS)
41 return string();
42
43 if (!returnShortName)
44 return string(CfnameBuf);
45
46 cbData = 1024;
47 TCHAR snbuffer[1024];
48 lResult = GetShortPathName(CfnameBuf, snbuffer, cbData);
49
50 if (lResult == 0 || lResult > 1024)
51 return string();
52
53 return string(snbuffer);
54 }
55