用RegQueryValueEx讀取數據,應該放在哪種數據類型中呢,求有效代碼~
下面這段是自己的提取TypedURLsTime的代碼。不知問題在哪。。
int main()
{
HKEY hKey;
DWORD lpType = REG_BINARY;
BYTE time[64];
DWORD timeSize = sizeof(time);
RegOpenKeyEx(HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\TypedURLsTime", 0, KEY_ALL_ACCESS, &hKey);//打開鍵。
RegQueryValueEx(hKey, "url1", NULL, &lpType, (LPBYTE)time, &timeSize);//提取內容。
printf("%s", time);
system("pause");
}
#include
#include
#include //調用FILIETIME等函數。
int main()
{
HKEY hKey;
DWORD lpType = REG_BINARY;
DWORD timeSize;
if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\TypedURLsTime", 0, KEY_ALL_ACCESS, &hKey) == 0)//打開鍵。
{
RegQueryValueEx(hKey, "url1", NULL, &lpType, NULL, &timeSize);
DWORD time = new DWORD[timeSize];
if (RegQueryValueEx(hKey, "url1", NULL, &lpType, (LPBYTE)time, &timeSize) == 0)
{
LONGLONG *t = (LONGLONG)time;//強制類型轉換將地址賦給LONGLONG型。
LONGLONG time1 = *t;//time1為注冊表中存儲的二進制時間。
FILETIME filetime;//filetime為UTC。
filetime.dwHighDateTime = time1 >> 32;//filetime的前半段。
filetime.dwLowDateTime = time1 & 0xffff;//filetime的後半段。
FILETIME localfiletime;//localfiletime為UTC+8。
FileTimeToLocalFileTime(&filetime, &localfiletime);
SYSTEMTIME systemtime;
FileTimeToSystemTime(&localfiletime, &systemtime);
printf("時間為:\n%d年%d月%d日%d時%d分%d秒\n", systemtime.wYear, systemtime.wMonth, systemtime.wDay, systemtime.wHour, systemtime.wMinute, systemtime.wSecond);
}
}
system("pause");
}