[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3501
  • Last Modified:

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


0
maghcc
Asked:
maghcc
1 Solution
 
AxterCommented:
Hi maghcc,
Why not calculate it by using both GetTickCount and GetSystemTime together?

David Maisonave (Axter)
Cheers!
0
 
maghccAuthor Commented:
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
0
 
HemanthaKumarCommented:
If you are very particular then GetTickCount also is not going to work,.. Check out the implmentation for advanced tick count in this thread

http://www.experts-exchange.com/Programming/Programming_Platforms/Win_Prog/Q_20672393.html

~Hemanth
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mrblueCommented:
// 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
0
 
mrblueCommented:
Should be:
tmTime2.wMiliseconds = time_ms;
0
 
mrblueCommented:
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);



0
 
maghccAuthor Commented:
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
0
 
mrblueCommented:
Cast FILETIME onto ULARGE_INTEGER (like suggested in MSDN) and use its .QuadPart member (it is ULONGLONG type - 64 bit unsigned integer)

By the way it should be:

(*(ULARGE_INTEGER *)&fileTime).QuadPart += (GetTickCount() - refTickCount) * 10000;
0
 
maghccAuthor Commented:
Thans so much!

             Mag
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now