Merge branch 'vim'
[MacVim.git] / src / VisVim / Reg.cpp
blobb4378e5452cadf59029449f9720152081c71f03b
1 #include "stdafx.h"
3 // Returns key for HKEY_CURRENT_USER\"Software"\Company\AppName
4 // creating it if it doesn't exist
5 // responsibility of the caller to call RegCloseKey() on the returned HKEY
6 //
7 HKEY GetAppKey (char* AppName)
9 HKEY hAppKey = NULL;
10 HKEY hSoftKey = NULL;
11 if (RegOpenKeyEx (HKEY_CURRENT_USER, "Software", 0, KEY_WRITE | KEY_READ,
12 &hSoftKey) == ERROR_SUCCESS)
14 DWORD Dummy;
15 RegCreateKeyEx (hSoftKey, AppName, 0, REG_NONE,
16 REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_READ, NULL,
17 &hAppKey, &Dummy);
19 if (hSoftKey)
20 RegCloseKey (hSoftKey);
22 return hAppKey;
25 // Returns key for
26 // HKEY_CURRENT_USER\"Software"\RegistryKey\AppName\Section
27 // creating it if it doesn't exist.
28 // responsibility of the caller to call RegCloseKey () on the returned HKEY
30 HKEY GetSectionKey (HKEY hAppKey, LPCTSTR Section)
32 HKEY hSectionKey = NULL;
33 DWORD Dummy;
34 RegCreateKeyEx (hAppKey, Section, 0, REG_NONE,
35 REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL,
36 &hSectionKey, &Dummy);
37 return hSectionKey;
40 int GetRegistryInt (HKEY hSectionKey, LPCTSTR Entry, int Default)
42 DWORD Value;
43 DWORD Type;
44 DWORD Count = sizeof (DWORD);
45 if (RegQueryValueEx (hSectionKey, (LPTSTR) Entry, NULL, &Type,
46 (LPBYTE) &Value, &Count) == ERROR_SUCCESS)
47 return Value;
48 return Default;
51 bool WriteRegistryInt (HKEY hSectionKey, char* Entry, int nValue)
53 return RegSetValueEx (hSectionKey, Entry, NULL, REG_DWORD,
54 (LPBYTE) &nValue, sizeof (nValue)) == ERROR_SUCCESS;