views:

107

answers:

1

Hi

I want to set system time to registry, i did like this. But some null characters only getting there.

when i am giving LPCTSTR data = TEXT("24/3/2010\0");

LONG setRes = RegSetValueEx (hkey, value, 0, REG_SZ, (LPBYTE)data, 100));

thsi is sucessfully adding into registry

How to trace the issue

IF possible please check my code

 #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);
    }

    }

output

value name: CheckSoftwareKey

valueData: 㐲〯⼳〲〱

A: 

Change

char szData[20];
sprintf (szData, "%02d/%02d/%04d", time.wDay, time.wMonth, time.wYear); 

to

TCHAR szData[20];
_stprintf_s (szData, _countof(szData), _TEXT("%02d/%02d/%04d"), time.wDay, time.wMonth, time.wYear); 
VitalyVal
Thanks i got the answer