我想将系统时间设置为注册表,我确实喜欢这样。 但是有些空字符只能到达那里。
当我给LPCTSTR数据= TEXT(“24/3/2010 \ 0”);
LONG setRes = RegSetValueEx(hkey,value,0,REG_SZ,(LPBYTE)data,100));
thsi已成功添加到注册表中
如何追踪问题
如果可能,请检查我的代码
#include<Windows.H>
#include<TCHAR.H>
#include<iostream>
void Regkey::create_Registry()
{
HKEY hkey;
DWORD dwDisposition,lpData;
SYSTEMTIME time;
GetLocalTime( &time );
int hour = time.wHour;
if (hour > 12) hour -= 12;
char szData[20];
sprintf (szData, "%02d/%02d/%04d", time.wDay, time.wMonth, time.wYear);
if(RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\Sijith\\Test"), 0, NULL, 0, 0, NULL, &hkey, &dwDisposition)==ERROR_SUCCESS)
{
LPCTSTR sk = TEXT("Software\\Sijith\\Test");
LONG openRes = RegOpenKeyEx(HKEY_LOCAL_MACHINE, sk, 0, KEY_ALL_ACCESS , &hkey);
LPCTSTR value = TEXT("CheckSoftwareKey");
LONG setRes = RegSetValueEx (hkey, value, 0, REG_SZ, (CONST BYTE *)szData, sizeof(TCHAR) * (_tcslen(szData) + 1));
RegCloseKey(hkey);
}
}
输出
值名称:CheckSoftwareKey
valueData:㐲〯⼳〲〱
答案 0 :(得分:0)
更改
char szData[20];
sprintf (szData, "%02d/%02d/%04d", time.wDay, time.wMonth, time.wYear);
到
TCHAR szData[20];
_stprintf_s (szData, _countof(szData), _TEXT("%02d/%02d/%04d"), time.wDay, time.wMonth, time.wYear);