Read and write the registration form

Source: Internet
Author: User

#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include "Winsock.h"
#include <string>
#include <iostream>
#include <Iphlpapi.h>
Using std::cout;using std::string;using Std::iostream;
Using std::endl;using std::ios;using Std::fstream;
Using std::ofstream;using std::cin;
#pragma comment (lib, "Ws2_32.lib")
int Ys_regedit (HKEY key,char *dir,char *sub_key,char date_time[])
{
HKEY hkey;//defines the HKEY to be closed at the end of the query
HKEY Htempkey;
DWORD length = strlen (date_time) +1;
if (error_success = = Regopenkeyexa (HKEY_CURRENT_USER, (LPCSTR) Dir,0,key_set_value, &hkey))
{
if (error_success = = Regcreatekeya (HKey, Sub_key, &htempkey))
{
if (error_success! = Regsetvalueexa (Htempkey, "Start_time", 0, REG_SZ, (unsigned char*) date_time,length))
{
RegCloseKey (Htempkey);
RegCloseKey (HKey);
return-1;
}
}
Else
{
RegCloseKey (HKey);
return-1;
}
RegCloseKey (Htempkey);
RegCloseKey (HKey);
return 0;
}
Else
{
return-1;
}
}
int Ys_read_start_time (char start_time[],dword Size)
{
HKEY hkey;//defines the HKEY to be closed at the end of the query
Open hkey associated with path Data_set
LPCSTR data_set= "SOFTWARE\\YSTEK\\YSTEK_PLR";
To access the registry, HKEY holds the handle to the key opened by this function
if (error_success = = Regopenkeyexa (hkey_current_user,data_set,0,key_read,&hkey))
{
DWORD Dwsztype = REG_SZ;
DWORD dwsize = Size;


if (Regqueryvalueexa (HKEY, "Start_time", 0, &dwsztype, (LPBYTE) start_time, &dwsize)! = ERROR_SUCCESS)
{
return-1;
}
End of program, close open hkey
RegCloseKey (HKEY);
return 0;
}
Else
{
return-1;
}
}
void Main (void)
{
int ret;
Char date_time[16]= "2015:4:7:12:56";
ret = Ys_regedit (HKEY_CURRENT_USER, "Software", "YSTEK\\YSTEK_PLR", date_time);
Char start_time[16];
ret = Ys_read_start_time (start_time,sizeof (start_time));
printf ("###########%s\n", start_time);
while (1)
Sleep (10);
}

Read and write the registration form

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.