티스토리 뷰

공부/코드

Vista vs XP Registry 관련 함수

광주아이 2009. 1. 16. 10:24
1. 레지스트리에서 값 읽어오기

 - 비스타에서 작업할 때
stdafx.h 파일에 
#define _WIN32_WINNT 0x0600
#include <Winreg.h> (include Windows.h)


LONG WINAPI RegGetValue(
  __in              HKEY hkey,
  __in_opt       LPCTSTR lpSubKey,
  __in_opt       LPCTSTR lpValue,
  __in_opt       DWORD dwFlags,
  __out_opt     LPDWORD pdwType,
  __out_opt     PVOID pvData,
  __inout_opt  LPDWORD pcbData
);
ex)
CString SubKey = "";
LPCTSTR lpKey = "SoftwareName";
LPCTSTR lpSubKey = "Data";
LPCTSTR pValue = "test";
DWORD cbData, cbType;
BYTE lpkData[256];

SubKey.Format("%s%s%s%s", "Software\\", lpKey, "\\", lpSubKey);
// -> HKEY_CURRENT_USER\Software\SoftwareName\Data

RegGetValue(
    HKEY_CURRENT_USER, 
    SubKey, 
    pValue, 
    RRF_RT_ANY, 
    &cbType, 
    lpkData, 
    &cbData);
// -> HKEY_CURRENT_USER\Software\SoftwareName\Data 에서 pValue의 값이 test인 키의 값을 뽀려온다. 이 값은 lpkData에 들어온다.

AfxMessageBox(lpkData);

 - XP에서 작업할 때
stdafx.h 파일에
#define _WIN32_WINNT 0x0501
#include <shlwapi.h>


LSTATUS SHGetValue(
    HKEY          hkey,
    LPCTSTR     pszSubKey,
    LPCTSTR     pszValue,
    LPDWORD   pdwType,
    LPVOID       pvData,
    LPDWORD   pcbData
);
ex) 
SHGetValue(
    HKEY_CURRENT_USER, 
    SubKey, 
    pValue, 
    &cbType, 
    lpkData, 
    &cbData);

///////////////////////////////////////////////////////////////////////////////////////////////

이런거 하나도 쓰기 귀찮구먼..
오늘은 여기까지.. 내일은 다른거..ㅋㅋ

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함