26 장. 레지스트리 26-1 INI 파일 26-2 레지스트리 Windows API. 26-1 INI 파일 정보의 저장.

Slides:



Advertisements
Similar presentations
Prof. Muhammad Saeed. Procedure-Driven Programming Event-Driven Programming Events Messages Event Handlers GUI Windows and Multitasking Queues ( System.
Advertisements

NT Net Lib Roteiro da apresentação: diagrama de fluxo de chamadas da API Win32 explicação das chamadas apresentação da classe Uma mini-biblioteca com as.
Introduction to C# Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Introduction to Windows Programming. First Windows Program This program simply displays a blank window. The following code is the minimum necessary to.
1 Windows Goodies CIS 577 Bruce R. Maxim UM-Dearborn.
The Windows Registry Adapted from
CS 140 Lecture Notes: Processes and ThreadsSlide 1 UNIX Fork/Exec Example int pid = fork(); if (pid == 0) { exec("foo"); } else { waitpid(pid, &status,
Simple Gui in C++. Project Selecting So Far Registering the window class Creating the window.
Simple Gui in C++. Project Selecting So Far Registering the window class Creating the window.
First Windows Program Hello Windows. 2 HELLOWIN.C #include LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; int WINAPI WinMain (HINSTANCE hInstance,
1 JMH Associates © 2004, All rights reserved Chapter 2-3 Supplement Registry Programming.
Building a Win32API Application Raw access to the API.
1 JMH Associates © 2004, All rights reserved Chapter 1 Getting Started with Win32/64.
GVE, Hallym University, Song, Chang Geun, Ph.D. 컴퓨터 그래픽스 응용 한림대학교 컴퓨터공학부 송 창근.
1 Microsoft Windows Internals, 4 ed Chapter 4. Management Mechanisms The Registry 謝承璋 2008 年 05 月 07 日.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Software attacks Software Attacks DLL injection & API patching.
Overview of Previous Lesson(s) Over View  Visual C++ provides us with 3 basic ways of creating an interactive Windows application  Using the Windows.
计算机系 信息处理实验室 Lecture 6 Management Mechanisms
Chapter 1: Hello, MFC Windows Programming Model Department of Digital Contents Sang Il Park.
Lecture Two Event Handling Keyboard and Mouse Input.
Douglas Boling President Boling Consulting Inc. SESSION CODE: WEM304.
Jason Browne Software Engineering Manager Bsquare Corporation ECE307 Inside the Radio Interface Layer (RIL)
Winsock Programming Blocking and Asynchronous Sockets for Windows.
Direct3D Workshop November 17, 2005 Workshop by Geoff Cagle Presented by Players 2 Professionals.
Windows thread programming
GAM666 – Introduction To Game Programming You must use special libraries (aka APIs – application programming interfaces) to make something other than a.
Plug And Play For Network Connected Devices Cameron Brodeur and Kristina Hotz Program Managers Windows Device Experience Group Microsoft Corporation.
Cody, Brian, and Jerry. Contains configuration options for a boot menu. The file is hidden and read-only to protect it from user configuration. Microsoft’s.
Lecture 7 Menu, controls, scroll bars. Menu Menu item sends WM_COMMAND message to the application window Menu is attached to window when the window is.
Lecture 12. Windows registry Structure of the registry Loading and storing data in registry.
개정번호개정장개정내역작성자시행일자 0.1 전체 시작강선영 Demux Part 추가 “ 개정이력 Jaram TS Reader 문서번호버전 0.1 쪽 1 작성자강선영최종수정일자 작업단계시스템 모듈.
GUI-Based Programming ECE 417/617: Elements of Software Engineering Stan Birchfield Clemson University.
Dialog boxes Modal and modeless dialog boxes Displaying about dialog box: case WM_COMMAND : switch (LOWORD (wParam)) { case IDM_APP_ABOUT : DialogBox (hInstance,
Chapter 6: FILE I/O and Serialize CFile class. FILE I/O Serialization and the CArchive Class.
Quanta Confidential QUANTA WBU Study Report 1 昭正 2008/08/01.
영상 획득 영상 저장 카메라 파라메터 커스텀 이미지
Programming Input Devices. Getting the device state Schemes for processing input – Polling – Callbacks Ways to intercept messages from input devices –
Creating a DirectX Project A DirectPLay Chat Program.
The WM_NCHITTEST Message  This is an internal message used by Windows for generating all the other mouse messages.  Though it almost never needs to be.
9. 메뉴와 기타 자원. 1. 자원 – 아이콘, 커서, 메뉴, 대화상자는 모두 Windows 의 자원이다. – 자원은 데이터로 생각할 수 있으며, 프로그램의 EXE 파일에 저장된 다. – 실행 가능한 프로그램의 데이터 영역에는 존재하지 않는다. 자원은 프로그램 소스코드에.
System Programming Course introduction Getting Started …
Chapter 6: FILE I/O and Serialize CFile class. FILE I/O Serialization and the CArchive Class.
Our good old first Win32 programme of lecture 8 #include int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
W indows Programming Lecture 08. Brief History of Win Windows is announced 1984 Work begins on Word for Windows 1.0 November 1985: Windows 1.0.
Windows Programming Lecture 14. WM_PAINT message Whenever an application receives the WM_PAINT message, whether the entire window needs repainting? WM_PAINT.
Lecture Lecture 25 Review of Last Lecture DLL’s DLL’s Processes Processes Threads Threads Memory Management Memory Management.
Mario Tayah and Jim Fawcett CSE 775 – Distributed Objects Spring 2007
Windows Programming Lecture 10.
Windows Programming Lecture 09.
Window.
18 & 19.
File Management.
The program in traditional OS
null, true, and false are also reserved.
Linux Fork/Exec Example
UNIX Fork/Exec Example
Files in Windows API David Halbig Lopez.
Windows Programming Lecture 12
28.
Windows Programming Lecture 13
UNIX Fork/Exec Example
Windows Programming Lecture 15
21-22.
Programming Language C Language.
Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/10.
Linux Fork/Exec Example
Welcome back to Software Development!
Graphics Laboratory Korea University
GUI Socket Application
Presentation transcript:

26 장. 레지스트리 26-1 INI 파일 26-2 레지스트리 Windows API

26-1 INI 파일 정보의 저장

함수 BOOL WritePrivateProfileString ( LPCTSTR lpAppName // 기록할 섹선이름, LPCTSTR lpKeyName // 기록할 키이름 NULL- 섹션삭제,LPCTSTR lpString // 키값을 정의하는 문자열, LPCSTR lpFileName //ini 파일명 )

UINT GetPrivateProfileInt ( LPCTSTR lpAppName, // 기록할 섹선이름 LPCTSTR lpKeyName, // 기록할 키이름 NULL- 섹션삭제 INT nDefault, // 디폴트 값 LPCTSTR lpFileName //ini 파일명 )

DWORD GetPrivateProfileString ( LPCSTR lpAppName, LPCSTR lpKeyName, LPCSTR lpDefault, LPTSTR lpReturnedString, // 문자열을대입받을버퍼 DWORD nSize, // 버퍼의크기 LPCSTR lpFileName, )

inifile

Left+X,Top+Y,Right+X,Bottom+Y

26-2 레지스트리 가.INI 파일의 단점 1. 텍스트파일 포맷으로 저장 - 사용자임의조작가능 -> 오작동 가능 성. 2. 디스크공간 낭비 3. 복수사용자 지원하지 않음. 4. 손상시 복구 불가. 5. 느리다.

LONG RegCreateKeyEx( HKEY hKey, // 새로 만들어 지는 키의 부모키 LPCTSTR lpSubKey, // "Software\\KanamSoft\\RegiTest\\Position", DWORD Reserved, // 예약된 인수 LPTSTR lpClass, // 생성된 키의 클래스 지정 DWORD dwOption, // 생성하는 키의 옵션 REGSAM samDesired, // 키의 보안속성 LPSECURITY_ATTRIBUTES lpSecurityAttributes, // 생성된 키값이 차일드로 상속될것인가 ? NULL- 상속안됨 PHKEY phkResult, // 키값이 대입되는 변수 포인터 LPDWORD lpdwDisposition // 생성되었는지 오픈되었는지 출력 용변수 )

LONG RegSetValueEx( HKEY hKey, LPCTSTR lpvalueName, // 값의 이름지정 DWORD Reserved, DWORD dwType, CONST BYTE *lpData, // 저장하고자하는 데이터 DWORD cbData )

LONG RegQueryValueEx( HKEY hKey, LPTSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, // 읽을값의 타입받을변수포인터 LPBYTE lpData, LPDWORD lpcbData //lpData 의 크기 )

LONG RegCloseKey(HKEY hKey) LONG RegOpenKeyEx( HKEY hKey, LPCTSTR lpSubKey, DWORD ulOptions, PHKEY phkResult )

Regi LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam) { RECT rt; HKEY key; DWORD dwDisp; DWORD Size; switch(iMessage) { case WM_CREATE: RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\KanamSoft\\RegiTest\\Position",0,NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,NULL,&key,&dwDisp); Size=sizeof(LONG); if (RegQueryValueEx(key, "Left", 0, NULL,(LPBYTE)&rt.left, &Size) !=ERROR_SUCCESS) rt.left=0; Size=sizeof(LONG); if (RegQueryValueEx(key, "Top", 0, NULL,(LPBYTE)&rt.top, &Size) !=ERROR_SUCCESS) rt.top=0;

Size=sizeof(LONG); if (RegQueryValueEx(key, "Right", 0, NULL,(LPBYTE)&rt.right, &Size)!=ERROR_SUCCESS) rt.right=100; Size=sizeof(LONG); if (RegQueryValueEx(key, "Bottom", 0, NULL,(LPBYTE)&rt.bottom, &Size) !=ERROR_SUCCESS) rt.bottom=100;; RegCloseKey(key); MoveWindow(hWnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE); return 0;

case WM_DESTROY: RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\KanamSoft\\RegiTest\\Position",0,NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,NULL,&key,&dwDisp); GetWindowRect(hWnd, &rt); RegSetValueEx(key, "Left",0,REG_DWORD,(LPBYTE)&rt.left, sizeof(LONG)); RegSetValueEx(key, "Top",0,REG_DWORD,(LPBYTE)&rt.top, sizeof(LONG)); RegSetValueEx(key, "Right",0,REG_DWORD,(LPBYTE)&rt.right, sizeof(LONG)); RegSetValueEx(key, "Bottom",0,REG_DWORD, (LPBYTE)&rt.bottom,sizeof(LONG)); RegCloseKey(key); PostQuitMessage(0); return 0; } return(DefWindowProc(hWnd,iMessage,wParam,lParam)); }

26-3 레지스트리 관리 가. 미리정의된 키 –HKEY_USER –HKEY_LOCAL_MACHINE –HKEY_CURRENT_USER –HKEY_CLASSES_ROOT –HKEY_CURRENT_CONFIG

나. 비우기 LONG RegFlushKey( HKEY hKey ) 다. 삭제 LONG RegDeleteKey(HKEY hKey, LPCTSTR lpValueName )

라. 정보조사 LONG RegQueryInfoKey( HKEY hKey, // 조사하고자하는 키의 핸들 LPTSTR lpClass, // 클래스 스트링 LPDWORD lpcbClass, // 클래스 스트링의 버퍼크기 LPDWORD lpReserved, // 예약 LPDWORD lpcSubKeys, // 서브키의 개수 LPDWORD lpcbMaxSubKeyLen, // 가장긴이름의 서브키의 길이 LPDWORD lpcbMaxClassLen, // 가장 긴 이름의 클래스길이 LPDWORD lpcValues, // 값의 개수 LPDWORD lpcbMaxValueNameLen, // 가장긴 이름의 값길이 LPDWORD lpcbMaxValueLen, // 가장 긴 데이터길이 LPDWORD lpcbSecurityDescriptor, // 보안속성의 길이 PFILETIME lpftLastWriteTime // 최후수정시간 );

마. 열거 LONG RegEnumKeyEx( HKEY hKey, // handle to key to enumerate DWORD dwIndex, // index of subkey to enumerate LPTSTR lpName, // address of buffer for subkey name LPDWORD lpcbName, // address for size of subkey buffer LPDWORD lpReserved, // reserved LPTSTR lpClass, // address of buffer for class string LPDWORD lpcbClass, // address for size of class buffer PFILETIME lpftLastWriteTime // address for time key last written to );

LONG RegEnumValue( HKEY hKey, // handle to key to query DWORD dwIndex, // index of value to query LPTSTR lpValueName, // address of buffer for value string LPDWORD lpcbValueName, // address for size of value buffer LPDWORD lpReserved, // reserved LPDWORD lpType, // address of buffer for type code LPBYTE lpData, // address of buffer for value data LPDWORD lpcbData // address for size of data buffer );

RegEnum void RegEnum(HKEY); void DblClk(void); void SelChange(void); // 차일드 컨트롤들 #define ID_LISTBOX 100 #define ID_EDIT 101 #define ID_BUTTON 102 HWND hList; HWND hEdit; HWND hButton; HWND hStatic; LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam) {HKEY key; char str[MAX_PATH]; switch(iMessage) {

// 차일드 윈도우를 만든다. case WM_CREATE: hList=CreateWindow("listbox",NULL,WS_CHILD | WS_VISIBLE | WS_BORDER |LBS_NOTIFY | WS_VSCROLL, 10,50,200,400,hWnd,(HMENU)ID_LISTBOX,g_hInst,NULL); hEdit=CreateWindow("edit","software",WS_CHILD | WS_VISIBLE | WS_BORDER |ES_AUTOHSCROLL, 10,10,400,25,hWnd,(HMENU)ID_EDIT,g_hInst,NULL); hButton=CreateWindow("button","Enumerate",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,420,10,100,25, hWnd,(HMENU)ID_BUTTON,g_hInst,NULL); hStatic=CreateWindow("static"," 표시할 내용이 없습니다.", WS_CHILD | WS_VISIBLE,,0,0,0,0,hWnd,(HMENU)-1,g_hInst,NULL); // 프로그램 시작 직후에 software 아래의 키를 조사한다. SendMessage(hWnd,WM_COMMAND,MAKEWPARAM(ID_BUTTO N,BN_CLICKED),(LPARAM)hButton); return 0;

case WM_COMMAND: switch (LOWORD(wParam)) { // 버튼 누름 : 에디트의 키값으로 순회한다. case ID_BUTTON: GetWindowText(hEdit,str,MAX_PATH); if (RegOpenKeyEx(HKEY_CURRENT_USER, str,0,KEY_ALL_ACCESS,&key) == ERROR_SUCCESS) { RegEnum(key); RegCloseKey(key); } else { MessageBox(hWnd," 지정한 키를 열 수 없습 니다 "," 에러 ",MB_OK); } break; // 리스트 박스의 클릭과 더블 클릭 처리 case ID_LISTBOX: switch (HIWORD(wParam)) { case LBN_DBLCLK: DblClk(); break;

case LBN_SELCHANGE: SelChange(); break; } break; } return 0; case WM_SIZE: MoveWindow(hEdit,10,10,LOWORD(lParam)-130,25,TRUE); MoveWindow(hButton,LOWORD(lParam)- 110,10,100,25,TRUE); MoveWindow(hList,10,50,LOWORD(lParam)- 20,HIWORD(lParam)-80,TRUE); MoveWindow(hStatic,10,HIWORD(lParam)- 30,LOWORD(lParam)-20,25,TRUE); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return(DefWindowProc(hWnd,iMessage,wParam,lParam)); }

void RegEnum(HKEY key) { char lpSubKey[MAX_PATH]; char lpValue[MAX_PATH]; char lpBuffer[MAX_PATH]; DWORD i; LONG Result; DWORD Size; FILETIME FileTime; SendMessage(hList,LB_RESETCONTENT,0,0); SendMessage(hList,LB_ADDSTRING,0,(LPARAM)" ^^^ 한 단계 위 로 ^^^ "); // 서브키의 목록의 조사해 리스트 박스에 채워 넣는다. Result=ERROR_SUCCESS; for (i=0;Result==ERROR_SUCCESS;i++) { Size=MAX_PATH;

Result=RegEnumKeyEx(key,i,lpSubKey,&Size,NULL,NULL,NULL,& FileTime); if (Result==ERROR_SUCCESS) { wsprintf(lpBuffer,"K : %s",lpSubKey); SendMessage(hList,LB_ADDSTRING,0,(LONG)lpBuffer); } // 값의 목록을 조사해 리스트 박스에 채워 넣는다. Result=ERROR_SUCCESS; for (i=0;Result==ERROR_SUCCESS;i++) { Size=MAX_PATH; Result=RegEnumValue(key,i,lpValue,&Size,NULL,NULL,NULL,NULL); if (Result==ERROR_SUCCESS) { wsprintf(lpBuffer,"V : %s",lpValue); SendMessage(hList,LB_ADDSTRING,0,(LONG)lpBuffer); }

void DblClk(void) { int index; char buffer[MAX_PATH]; char Caption[MAX_PATH]; char Post[MAX_PATH]; char *backslash; index=SendMessage(hList,LB_GETCURSEL,0,0); // 한단계 위로 처리 if (index==0) { GetWindowText(hEdit,Caption,MAX_PATH); backslash=strrchr(Caption, '\\'); if (backslash==NULL) { MessageBox(g_hWndMain," 더 올라갈 곳이 없습니다요 "," 잠깐 !",MB_OK); return; } backslash[0]=0; SetWindowText(hEdit,Caption);

SendMessage(g_hWndMain,WM_COMMAND, MAKEWPARAM(ID_BUTTON,BN_CLICKED),(LPARAM)hButt on); return; } // 키를 더클릭했을 경우 해당 키를 조사한다. SendMessage(hList,LB_GETTEXT,index,(LPARAM)buffer); strcpy(Post,buffer+4); if (buffer[0]=='K') { GetWindowText(hEdit,Caption,MAX_PATH); wsprintf(buffer,"%s\\%s",Caption,Post); SetWindowText(hEdit,buffer); SendMessage(g_hWndMain,WM_COMMAND,MAKEWPARA M(ID_BUTTON,BN_CLICKED), (LPARAM)hButton); }

void SelChange(void) { int index; char buffer[MAX_PATH]; char Caption[MAX_PATH]; char Post[MAX_PATH]; HKEY key; DWORD cSubKeys, cValues; DWORD Type, Size; BYTE Data[MAX_PATH]; index=SendMessage(hList,LB_GETCURSEL,0,0); // 한단계 위로에 대해서는 전혀 반응하지 않는다. if (index==0) return; SendMessage(hList,LB_GETTEXT,index,(LPARAM)buffer); strcpy(Post,buffer+4);

// 키에 속한 서브키와 값의 개수 조사 if (buffer[0]=='K') { GetWindowText(hEdit,Caption,MAX_PATH); wsprintf(buffer,"%s\\%s",Caption,Post); if (RegOpenKeyEx(HKEY_CURRENT_USER, buffer,0,KEY_ALL_ACCESS,&key) == ERROR_SUCCESS) { RegQueryInfoKey(key,NULL,NULL,NULL,&cSubKeys,NULL,NULL,&cValues,NULL,NULL,NULL,NULL); RegCloseKey(key); wsprintf(Caption," 서브키의 수 :%d, 값의 수 :%d",cSubKeys,cValues); SetWindowText(hStatic,Caption); }

else if (buffer[0]=='V') { GetWindowText(hEdit,Caption,MAX_PATH); if (RegOpenKeyEx(HKEY_CURRENT_USER, Caption,0,KEY_ALL_ACCESS,&key) == ERROR_SUCCESS) { Size=MAX_PATH; RegQueryValueEx(key,Post,NULL,&Type,Data,&Size); RegCloseKey(key); switch (Type) { case REG_DWORD: wsprintf(Caption," 데이터 타입 : 정수형, 데이 터 :%d",*(LPDWORD)Data); break; case REG_SZ: wsprintf(Caption," 데이터 타입 : 문자열, 데이 터 :%s",Data); break; default: wsprintf(Caption," 데이터 타입 :%d, 데이 터 :%s",Type,Data); break; } SetWindowText(hStatic,Caption); }