Regedit lab4 cpp Defines the entry point for the console application i

 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Regedit(lab4).cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <Windows.h>
#include<iostream>
#define BUF 256
int _tmain(int argc, _TCHAR* argv[])
{
setlocale(LC_ALL,"RUSSIAN");
HANDLE Cin,Cout;
LONG Err;
LPTSTR SysMsg;
HKEY KeyRes=NULL;
DWORD nIn,nOut,type,size,nEr,dispos=0;
TCHAR text[BUF]={0},Recieve[BUF]={0};
Cin=GetStdHandle(STD_INPUT_HANDLE);
Cout=GetStdHandle(STD_OUTPUT_HANDLE);
Err=RegCreateKeyEx(HKEY_CURRENT_USER, L"BlablaConfig", 0, L"", REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,0,&KeyRes,&dispos);
if (Err!=ERROR_SUCCESS){
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,NULL,Err,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR)&SysMsg,0,NULL);
WriteConsole(Cout,SysMsg,_tcslen(SysMsg),&nEr,NULL);
}
if (dispos==REG_CREATED_NEW_KEY){
_tcprintf(L"Создан новый подключ.\n");
_tcprintf(L"Введите строку для записи в реестр:\n");
ReadConsole(Cin,text,256,&nIn,NULL);
RegSetValueEx(KeyRes,L"Hello",0,REG_SZ,(BYTE*)&text,sizeof(TCHAR)*nIn);
}
if (dispos==REG_OPENED_EXISTING_KEY){
RegQueryValueEx(KeyRes,L"Hello",0,&type,(BYTE*)Recieve,&size);
WriteConsole(Cout,Recieve,_tcslen(Recieve),&nOut,NULL);
_tcprintf(L"\nВведите строку для записи в реестр:\n");
ReadConsole(Cin,text,256,&nIn,NULL);
RegSetValueEx(KeyRes,L"Hello",0,REG_SZ,(BYTE*)&text,sizeof(TCHAR)*nIn);
}
RegCloseKey(KeyRes);
//RegDeleteKey(HKEY_CURRENT_USER,L"BlablaConfig");
return 0;
}