Quelle est la bonne façon de convertir une structure FILETIME
en __int64
? Peux-tu me dire s'il te plait?FILETIME to __int64
11
A
Répondre
13
Je ne pense pas que vous êtes supposé: « Ne pas jeter un pointeur sur une structure FILETIME
soit une valeur ULARGE_INTEGER*
ou __int64*
, car il peut causer des défauts d'alignement sur 64 bits de Windows. »
Si vous avez vraiment voulu que ce serait quelque chose comme:
__int64 to_int64(FILETIME ft)
{
return static_cast<__int64>(ft.dwHighDateTime) << 32 | ft.dwLowDateTime;
}
FILETIME ft = // ...
__int64 t = to_int64(ft);
Mais quelque chose comme:
FILETIME ft = // ...
__int64 t = *reinterpet_cast<__int64*>(&ft);
est mauvais.
4
Essayez
(__int64(filetime.dwHighDateTime)<<32) | __int64(filetime.dwLowDateTime)
1
Bien sûr, vous pouvez simplement passer un __int64 à un filetime casted comme suit * (FILETIME *) & int64Val. Cela fonctionnera correctement sous Visual C++.
-à-dire
__int64 createTime = 0;
__int64 accessTime = 0;
__int64 writeTime = 0;
GetFileTime(hFile, *(FILETIME*)&createTime, *(FILETIME*)&accessTime, *(FILETIME*)&writeTime);
7
Il n'y a pas besoin de revenir à des constructions Arcane OU binaire de. L'API Windows dispose de tout ce dont vous avez besoin pour cela.
unsigned __int64 convert(const FILETIME & ac_FileTime)
{
ULARGE_INTEGER lv_Large ;
lv_Large.LowPart = ac_FileTime.dwLowDateTime ;
lv_Large.HighPart = ac_FileTime.dwHighDateTime ;
return lv_Large.QuadPart ;
}
Ou si vous voulez aller directement à __int64.
__int64 convert_to_int64(const FILETIME & ac_FileTime)
{
return static_cast<__int64> (convert(ac_FileTime)) ;
}
1
vous pouvez essayer le code suivre. le code est du projet de chrome
template <class Dest, class Source>
inline Dest bit_cast(const Source& source) {
\t Dest dest;
\t memcpy(&dest, &source, sizeof(dest));
\t return dest;
}
//FILETIME to __int64
__int64 FileTimeToMicroseconds(const FILETIME& ft) {
\t return bit_cast<__int64, FILETIME>(ft)/10;
}
void MicrosecondsToFileTime(__int64 us, FILETIME* ft) {
\t *ft = bit_cast<FILETIME, __int64>(us * 10);
}
int _tmain(int argc, _TCHAR* argv[])
{
\t __int64 nTmpUint64 = 13060762249644841;
\t time_t unixtime;
\t FILETIME nTmpFileTm;
\t MicrosecondsToFileTime(nTmpUint64,&nTmpFileTm);
\t return 0;
}
Questions connexes
- 1. Comment créer FILETIME dans Win32?
- 2. Vous cherchez bon convertisseur FILETIME
- 3. convertir les ticks en time_t ou Filetime()
- 4. Un moyen de transformer boost :: posix_time :: ptime en un __int64
- 5. SOAP to Stream to String
- 6. Sql Query to Linq To Sql
- 7. LINQ to XML et LINQ to Objects syntaxe
- 8. Implémentation many-to-many dans linq-to-sql
- 9. LINQ to Lambda Expressions
- 10. Linq to Entities System.data.Objects
- 11. LINQ to SQL Insert
- 12. MS Extensions To STL
- 13. Ruby to Python bridge
- 14. swf to quicktime
- 15. LINQ to xml
- 16. LINQ to # COALESCE
- 17. javascript to php question
- 18. FormsAuthentication selective to url
- 19. LINQ-to-SQL IN()
- 20. LINQ to SQL, Generalization
- 21. NHibernate Many-to-many
- 22. NHibernate Projection to DTO
- 23. MFC carchive to xml
- 24. Classes LINQ to SQL
- 25. Casting to Enum
- 26. Jquery Ajax to [WebMethod]
- 27. urllib2 read to Unicode
- 28. zcat pipe to grep
- 29. Linq-to-SQL ToDictionary()
- 30. Erreur LINQ to SQL
I était en cours de montage :) – GManNickG
Souhaitez-vous memcpy (<__int64>, & FILETIME, 8); ? Est-ce sûr? – akif
Je trouverais 'memcpy' plus difficile à comprendre, mais je suis sûr que cela fonctionnerait. Le compilateur peut probablement optimiser le décalage et/ou mieux. – GManNickG