模块“executable.exe”中的地址发生访问冲突。读取地址

发布于 2024-11-19 08:50:21 字数 1236 浏览 2 评论 0原文

我在网上读到了一些“访问冲突”的问题,但这对我来说很奇怪

我已经测试了一些“解决方案”但没有结果

这是一段代码:

TDateTime CFileVersionInfo::GetFileDate() const
{
    FILETIME local;
    SYSTEMTIME st;
    TDateTime res;

    FILETIME    ft;
    ft.dwLowDateTime = m_FileInfo.dwFileDateLS;
    ft.dwHighDateTime = m_FileInfo.dwFileDateMS;

    FileTimeToLocalFileTime(&ft, &local);
    FileTimeToSystemTime(&local, &st) ;
    //GetLocalTime(st);
    res = SystemTimeToDateTime(st) ;

    return res;
}

我可以毫无问题地制作或构建程序,但是当我运行程序时,它会显示访问冲突错误,如果我评论该函数:

// TDateTime dateTime = fvi.GetFileDate();

程序运行完美

我不是 C++ 专业人士我只是想制作一个供个人使用的程序,所以我向专家提出这个问题

编辑:

我已经解决了 问题

TDateTime CFileVersionInfo::GetFileDate() const
{
    _FILETIME local;
    _SYSTEMTIME st;
    TDateTime res;

    FILETIME    ft;
    ft.dwLowDateTime = m_FileInfo.dwFileDateLS;
    ft.dwHighDateTime = m_FileInfo.dwFileDateMS;

    FileTimeToLocalFileTime(&ft, &local);
    FileTimeToSystemTime(&local, &st) ;
    GetLocalTime(&st);           // <-- This is the solution.. for now...
    res = SystemTimeToDateTime(st) ;

    return res;
}

I've read some problems with "Access Violation" on the net but this is very weird for me

I have tested some "solutions" but with no results

This is the piece of code:

TDateTime CFileVersionInfo::GetFileDate() const
{
    FILETIME local;
    SYSTEMTIME st;
    TDateTime res;

    FILETIME    ft;
    ft.dwLowDateTime = m_FileInfo.dwFileDateLS;
    ft.dwHighDateTime = m_FileInfo.dwFileDateMS;

    FileTimeToLocalFileTime(&ft, &local);
    FileTimeToSystemTime(&local, &st) ;
    //GetLocalTime(st);
    res = SystemTimeToDateTime(st) ;

    return res;
}

I can Make or Build the program with no problems but when I run the program it show me the Access Violation error, if I comment the function:

// TDateTime dateTime = fvi.GetFileDate();

The program run perfectly

I'm not a C++ pro I just want to make a program for personal use so I ask this question to expert

EDIT:

I've resolved the problem

TDateTime CFileVersionInfo::GetFileDate() const
{
    _FILETIME local;
    _SYSTEMTIME st;
    TDateTime res;

    FILETIME    ft;
    ft.dwLowDateTime = m_FileInfo.dwFileDateLS;
    ft.dwHighDateTime = m_FileInfo.dwFileDateMS;

    FileTimeToLocalFileTime(&ft, &local);
    FileTimeToSystemTime(&local, &st) ;
    GetLocalTime(&st);           // <-- This is the solution.. for now...
    res = SystemTimeToDateTime(st) ;

    return res;
}

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

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

发布评论

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

评论(2

作业与我同在 2024-11-26 08:50:21

您没有执行任何错误检查来确保 API 转换成功,因此您可能正在尝试转换垃圾数据。始终检查错误,例如:

TDateTime CFileVersionInfo::GetFileDate() const
{
    FILETIME local;
    SYSTEMTIME st;

    FILETIME ft;
    ft.dwLowDateTime = m_FileInfo.dwFileDateLS;
    ft.dwHighDateTime = m_FileInfo.dwFileDateMS;

    if( FileTimeToLocalFileTime(&ft, &local) )
    {
        if( FileTimeToSystemTime(&local, &st) )
            return SystemTimeToDateTime(st);
    }

    return 0.0;
}

You are not doing any error checking to make sure the API conversions are succeeding, so you could be trying to convert trash data. Always check for errors, eg:

TDateTime CFileVersionInfo::GetFileDate() const
{
    FILETIME local;
    SYSTEMTIME st;

    FILETIME ft;
    ft.dwLowDateTime = m_FileInfo.dwFileDateLS;
    ft.dwHighDateTime = m_FileInfo.dwFileDateMS;

    if( FileTimeToLocalFileTime(&ft, &local) )
    {
        if( FileTimeToSystemTime(&local, &st) )
            return SystemTimeToDateTime(st);
    }

    return 0.0;
}
缘字诀 2024-11-26 08:50:21

我已经解决了问题

TDateTime CFileVersionInfo::GetFileDate() const
{
    _FILETIME local;
    _SYSTEMTIME st;
    TDateTime res;

    FILETIME    ft;
    ft.dwLowDateTime = m_FileInfo.dwFileDateLS;
    ft.dwHighDateTime = m_FileInfo.dwFileDateMS;

    FileTimeToLocalFileTime(&ft, &local);
    FileTimeToSystemTime(&local, &st) ;
    GetLocalTime(&st);           // <-- This is the solution.. for now...
    res = SystemTimeToDateTime(st) ;

    return res;
}

I've resolved the problem

TDateTime CFileVersionInfo::GetFileDate() const
{
    _FILETIME local;
    _SYSTEMTIME st;
    TDateTime res;

    FILETIME    ft;
    ft.dwLowDateTime = m_FileInfo.dwFileDateLS;
    ft.dwHighDateTime = m_FileInfo.dwFileDateMS;

    FileTimeToLocalFileTime(&ft, &local);
    FileTimeToSystemTime(&local, &st) ;
    GetLocalTime(&st);           // <-- This is the solution.. for now...
    res = SystemTimeToDateTime(st) ;

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