Artifact b513b5f4430bdfd8dc5edf152a6a8a544472d291
1 //--- K.I.LIB ---
2 // kl_reg.h : registry and ini-file operation
3
4 #ifndef AFX_KIREGKEY_H__4FD5E1B3_B8FE_45B3_B19E_3D30407C94BA__INCLUDED_
5 #define AFX_KIREGKEY_H__4FD5E1B3_B8FE_45B3_B19E_3D30407C94BA__INCLUDED_
6
7 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
8 // レジストリ操作&ini操作
9
10 class kiRegKey
11 {
12 public: //-- 外向きインターフェイス --------------------------
13
14 // 開く&閉じる
15 bool open( HKEY parent, LPCTSTR keyname, REGSAM access = KEY_ALL_ACCESS );
16 bool create( HKEY parent, LPCTSTR keyname, REGSAM access = KEY_ALL_ACCESS );
17 void close()
18 {
19 if( m_hKey )
20 RegCloseKey( m_hKey );
21 }
22
23 // サブキーが存在するや否や
24 bool exist( LPCTSTR keyname )
25 {
26 HKEY k;
27 if( ERROR_SUCCESS==RegOpenKeyEx( m_hKey,keyname,0,KEY_READ,&k ) )
28 {
29 RegCloseKey( k );
30 return true;
31 }
32 return false;
33 }
34 // HKEYへキャスト
35 operator HKEY() const
36 {
37 return m_hKey;
38 }
39
40 // 値を得る
41 bool get( LPCTSTR valname, DWORD* val );
42 bool get( LPCTSTR valname, BYTE* val, DWORD siz );
43 bool get( LPCTSTR valname, kiStr* val );
44
45 // 値を設定
46 bool set( LPCTSTR valname, DWORD val );
47 bool set( LPCTSTR valname, BYTE* val, DWORD siz );
48 bool set( LPCTSTR valname, LPCTSTR val );
49
50 // 削除
51 bool del( LPCTSTR valname );
52 bool delSubKey( LPCTSTR keyname );
53
54 public: //-- 内部処理 -----------------------------------
55
56 kiRegKey()
57 {
58 m_hKey = NULL;
59 }
60
61 virtual ~kiRegKey()
62 {
63 close();
64 }
65
66 private:
67
68 HKEY m_hKey;
69 static bool delSubKeyRecursive( HKEY k, LPCTSTR n );
70 };
71
72 class kiIniFile
73 {
74 public: //-- 外向きインターフェイス --------------------------
75
76 // iniファイル名を設定
77 void setFileName( const char* ini, bool exepath=true );
78 void setSection( const char* section )
79 { m_CurSec = section; }
80
81 // 読み込み
82 // ※ 注意!getStrの返値は内部バッファな為、
83 // ※ 呼び出し直後以外は内容を保証しない。
84 int getInt( const char* key, int defval );
85 bool getBool( const char* key, bool defval );
86 const char* getStr( const char* key, const char* defval );
87
88 // 書き込み
89 bool putStr( const char* key, const char* val );
90 bool putInt( const char* key, int val );
91 bool putBool( const char* key, bool val );
92
93 private: //-- 内部処理 -----------------------------------
94
95 kiPath m_FileName;
96 kiStr m_CurSec;
97 char m_StrBuf[256];
98 };
99
100 #endif