#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;//定义有关的hKEY,在查询结束时要关闭
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;//定义有关的hKEY,在查询结束时要关闭
//打开与路径data_Set相关的hKEY
LPCSTR data_Set= "Software\\ystek\\ystek_plr";
//访问注册表,hKEY则保存此函数所打开的键的句柄
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;
}
//程序结束,关闭打开的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);
}
#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;//定义有关的hKEY,在查询结束时要关闭
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;//定义有关的hKEY,在查询结束时要关闭
//打开与路径data_Set相关的hKEY
LPCSTR data_Set= "Software\\ystek\\ystek_plr";
//访问注册表,hKEY则保存此函数所打开的键的句柄
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;
}
//程序结束,关闭打开的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);
}