2010-09-01 15 views
1

J'essaie d'extraire les informations de fuseau horaire du registre afin que je puisse effectuer une conversion de temps. Le type de données de registre est REG_BINARY qui contient des informations sur un REG_TZI_FORMAT structure. La clé est stockée sous: HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Fuseaux horaires \ (time_zone_name)Convertir les données REG_BINARY en REG_TZI_FORMAT

Comment obtenir les informations REG_BINARY à convertir dans la structure REG_TZI_FORMAT? C++, Windows 7 32 bits, VS 2008

Répondre

1

Vous pouvez le faire avec le code suivant:

#include <Windows.h> 
#include <stdio.h> 
#include <tchar.h> 

// see http://msdn.microsoft.com/en-us/library/ms724253.aspx for description 
typedef struct _REG_TZI_FORMAT 
{ 
    LONG Bias; 
    LONG StandardBias; 
    LONG DaylightBias; 
    SYSTEMTIME StandardDate; 
    SYSTEMTIME DaylightDate; 
} REG_TZI_FORMAT; 

int main() 
{ 
    DWORD dwStatus, dwType, cbData; 
    int cch; 
    TCHAR szTime[128], szDate[128]; 
    HKEY hKey; 
    REG_TZI_FORMAT tzi; 

    dwStatus = RegOpenKeyEx (HKEY_LOCAL_MACHINE, 
     TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\E. Europe Standard Time"), 
     0, KEY_QUERY_VALUE, &hKey); 
    if (dwStatus != NO_ERROR) 
     return GetLastError(); 

    cbData = sizeof(REG_TZI_FORMAT); 
    dwStatus = RegQueryValueEx (hKey, TEXT("TZI"), NULL, &dwType, (LPBYTE)&tzi, &cbData); 
    if (dwStatus != NO_ERROR) 
     return GetLastError(); 

    _tprintf (TEXT("The current bias: %d\n"), tzi.Bias); 
    _tprintf (TEXT("The standard bias: %d\n"), tzi.StandardBias); 
    _tprintf (TEXT("The daylight bias: %d\n"), tzi.DaylightBias); 

    // I don't use GetDateFormat and GetTimeFormat to decode 
    // tzi.StandardDate and tzi.DaylightDate because wYear can be 0 
    // and in this case it is not real SYSTEMTIME 
    // see http://msdn.microsoft.com/en-us/library/ms725481.aspx 

    return 0; 
}