Below code is working fine as 32bit application.(Compiled on gcc 4.6.3), I ported same code to 64bit application,it doesn't give the correct output.
#include <iostream>
#include <stdint.h>
using namespace std;
typedef unsigned long DWORD;
typedef unsigned long long int uint64;
typedef long long LONGLONG;
typedef struct _SND_FILETIME
{
DWORD dwLowDateTime;
DWORD dwHighDateTime;
} SND_FILETIME, *SND_PFILETIME, *SND_LPFILETIME;
void FileTimeToUnixTime(const SND_FILETIME *pft, time_t *t)
{
#if BYTE_ORDER == LITTLE_ENDIAN
LONGLONG ll = (LONGLONG)pft->dwHighDateTime;
ll <<= 32;
ll |= (LONGLONG)pft->dwLowDateTime;
#else
LONGLONG ll = (LONGLONG)pft->dwLowDateTime;
ll <<= 32;
ll |= (LONGLONG)pft->dwHighDateTime;
#endif
ll -= 116444736000000000LL;
ll /= 10000000;
*t = (time_t)ll;
struct tm *info = localtime(t);
cout << "Time" << asctime(info) << std::endl;
}
int main()
{
uint64 time64 = 132385716359962190;
SND_FILETIME* ptr = (SND_FILETIME*)&time64;
cout <<"HighPart = " << ptr->dwHighDateTime <<endl;
cout <<"lowPart = " << ptr->dwLowDateTime <<endl;
time_t t;
FileTimeToUnixTime(ptr,&t);
return 0;
}
Output I'm getting for 32bit application:
HighPart = 30823451 lowPart = 2365103694 TimeTue Jul 7 10:30:35 2020
for 64bit application : HighPart = 140730490267024 lowPart = 132385716359962190 TimeTue Aug 11 02:12:08 23514
If I change the input to something like,
uint64 time64 = 132385716359962190;
SND_FILETIME filetime;
filetime.dwHighDateTime = 0;
filetime.dwLowDateTime = 132385716359962190;
SND_FILETIME* ptr=&filetime;
cout <<"HighPart = " << ptr->dwHighDateTime <<endl;
cout <<"lowPart = " << ptr->dwLowDateTime <<endl;
time_t t;
FileTimeToUnixTime(ptr,&t);
64bit application works. but I don't want to do this, as I'll have to change all code. Is there any way to get this work without changing code.
Please help!!!
Thanks,