Link to home
Start Free TrialLog in
Avatar of maghcc
maghcc

asked on

Absolute Time measure in milliseconds on pocket pc

Hi Expert :

I need to measure absolute time until milliseconds on pocket pc device.
Because I want to measure time to compare with other device.
When I using GetSystemTime() , the wMilliseconds field always return zero.
When I using  function : GetTickCount() or timeGetTime() ,  
they are all reterive the time elapsed since the system started.

Is any idea can get current time that time units until milliseconds?

My platform is pocket pc2003 , using VC++ development

Thanks very much!

                mag


Avatar of Axter
Axter
Flag of United States of America image

Hi maghcc,
Why not calculate it by using both GetTickCount and GetSystemTime together?

David Maisonave (Axter)
Cheers!
Avatar of maghcc
maghcc

ASKER

Hi Export:

How to use them togother?

Does GetTickCount()  reterive the time elapsed since the system started?

Is like this ?

GetSystemTime() + GetTickCount()  ??


Thanks very much !


           Mag
If you are very particular then GetTickCount also is not going to work,.. Check out the implmentation for advanced tick count in this thread

https://www.experts-exchange.com/questions/20672393/Windows-System-Tick-Time-Resolution-Networking-Select-loop.html

~Hemanth
// initialization
startTime = GetSystemTime();

while(startTime == GetSystemTime());  // wait till time changes (second changes)

refTickCount = GetTickCount();             // get refernce tick count

// usage
tmTime = GetSystemTime();         // without ms

time_ms = (GetTickCount() - refTickCount) % 1000;  // modulo to get

tmTime2 = GetSystemTime();        

if(tmTime != tmTime2) { // has time hanged in the meantime ?
   time_ms = 0;
};

tmTime2.wMiliseconds += time_ms;

More or less
Should be:
tmTime2.wMiliseconds = time_ms;
or maybe better (if it works on your platform)

// initialization
startTime = GetSystemTime();

while(startTime == GetSystemTime());  // wait till time changes (second changes)

refTickCount = GetTickCount();             // get refernce tick count

// usage (simply add elapsed ms to startTime)
SystemTimeToFileTime(&startTime, &fileTime);

// * 10000 because FILETIME is expressed in 100 ns units
*(ULARGE_INTEGER *)&fileTime += (GetTickCount() - refTickCount) * 10000;  

FileTimeToSystemTime(&fileTime, &resTime);



Avatar of maghcc

ASKER

Hi Expert:

I deeply appreciate your help.

But have one problem. Here is my code segment.

SYSTEMTIME startTime;
SYSTEMTIME secondTime;
DWORD refTickCount = 0;

// initialization
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) {
   GetSystemTime(&startTime);

    while (1){
        GetSystemTime(&secondTime);
        if ((startTime.wMinute != secondTime.wMinute) || (startTime.wSecond != secondTime.wSecond))
          break;
     }

     refTickCount = GetTickCount();             // get refernce tick count
   
     some code statements;
}


DWORD WINAPI DoWaitNotifThread(PVOID pArg)
{
     FILETIME fileTime;
     SYSTEMTIME resTime;

     // usage (simply add elapsed ms to startTime)
     SystemTimeToFileTime(&startTime, &fileTime);

    // * 10000 because FILETIME is expressed in 100 ns units
    *(ULARGE_INTEGER *)&fileTime += (GetTickCount() - refTickCount) * 10000;

    FileTimeToSystemTime(&fileTime, &resTime);

    SystemTimeToFileTime(&startTime, &fileTime);

}


Is FILETIME structure by declare in fileTime variables ?

If using FILETIME structure , I don't know what fields either dwLowDateTime or dwHighDateTime which be used?

Thanks very much!!

                 Mag
ASKER CERTIFIED SOLUTION
Avatar of Dariusz Dziara
Dariusz Dziara
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of maghcc

ASKER

Thans so much!

             Mag