본문 바로가기

old drawer/C, C++, MFC

[MFC/C++] 레지스트리 값 쓰기/읽기

http://sbrich.tistory.com/1771

      <- also good reference~

 

[레지스트리 값 쓰기]

CRegKey RegKey;

RegKey.Create(HKEY_LOCAL_MACHINE,"SOFTWARE\\test");
RegKey.SetValue("저장할 변수명", "test");
RegKey.Close();



[레지스트리 값 읽기]

DWORD dwType = REG_SZ;
DWORD dwSize = 128;
HKEY hKey;
LONG lResult;
TCHAR szBuffer[128];

lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\test", 0, KEY_READ, &hKey);
if(lResult == ERROR_SUCCESS)
{
    RegQueryValueEx(hKey, "test", NULL, &dwType, (LPBYTE)szBuffer, &dwSize);
}


출처 : http://cafe.naver.com/itwillcampus.cafe?iframe_url=/ArticleRead.nhn%3Farticleid=835

 

 

= 읽기 =

DWORD dwType = REG_SZ;
DWORD dwSize = 128;
HKEY hKey;
TCHAR szBuffer[128] = {'\0' ,};

LONG lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE , "SOFTWARE\\TestProg" , 0 , KEY_READ , &hKey);
if(ERROR_SUCCESS == lResult)
{
 RegQueryValueEx(hKey , "Date" , NULL , &dwType , (LPBYTE)szBuffer , &dwSize);
}

 

= 쓰기 =

SYSTEMTIME stTime;
GetLocalTime(&stTime);

CString rInstalledDate;
rInstalledDate.Format("%d-%d-%d" , stTime.wYear , stTime.wMonth , stTime.wDay);

CRegKey RegKey;
RegKey.Create(HKEY_LOCAL_MACHINE , "SOFTWARE\\TestProg");
RegKey.SetValue(rInstalledDate , "Date");
RegKey.Close();