将 REG_BINARY 数据转换为 REG_TZI_FORMAT

发布于 2024-09-17 06:39:59 字数 357 浏览 1 评论 0原文

我正在尝试从注册表中提取时区信息,以便可以执行时间转换。注册表数据类型是 REG_BINARY,它保存有关 REG_TZI_FORMAT 的信息 结构。密钥存储在: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows \CurrentVersion\Time Zones\(time_zone_name)

如何获取 REG_BINARY 信息以转换为 REG_TZI_FORMAT 结构? C++、Windows 7 32 位、VS 2008

I'm trying to pull time zone information out of the registry so I can perform a time conversion. The registry data type is REG_BINARY which holds information about a REG_TZI_FORMAT
structure. The key is stored at: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows \CurrentVersion\Time Zones\(time_zone_name)

How do I get the REG_BINARY information to convert to the REG_TZI_FORMAT structure? C++, Windows 7 32 bit, VS 2008

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巨坚强 2024-09-24 06:39:59

您可以使用以下代码来完成此操作:

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

You can do this with the following code:

#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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文