FILETIME to __int64

后端 未结 6 2065
日久生厌
日久生厌 2021-01-04 10:11

What is the proper way to convert a FILETIME structure into __int64? Can you please tell me?

6条回答
  •  醉梦人生
    2021-01-04 10:33

    you can try the code follow. the code is from chromium project

    template 
    inline Dest bit_cast(const Source& source) {
        Dest dest;
        memcpy(&dest, &source, sizeof(dest));
        return dest;
    }
    
    //FILETIME to __int64
    
    __int64 FileTimeToMicroseconds(const FILETIME& ft) {
        return bit_cast<__int64, FILETIME>(ft) / 10;
    }
    
    void MicrosecondsToFileTime(__int64 us, FILETIME* ft) {
        *ft = bit_cast(us * 10);
    }
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        __int64 nTmpUint64 = 13060762249644841;
    
        time_t unixtime;
        FILETIME nTmpFileTm;
        MicrosecondsToFileTime(nTmpUint64,&nTmpFileTm);
    
        return 0;
    }
    

提交回复
热议问题