Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetSystemTime

Status
Not open for further replies.

bkelly13

Programmer
Aug 31, 2006
98
US
Windows XP, Visual Studio 2008, C++
I am having a problem with this system call.
Code:
LPSYSTEMTIME   m_start;
LPSYSTEMTIME  *mp_start;
...
mp_start = &m_start;
...
GetSystemTime(  m_start );   // run time exception
GetSystemTime( &m_start );   // compile error , cannot convert  from LPSYSTEMTIME * to LPSYSTEMTIME  
GetSystemTime( *mp_start );  // run time exception
GetSystemTime(  mp_start );  // compile error, cannot convert  from LPSYSTEMTIME * to LPSYSTEMTIME

I found some example code and using that format doesn't work for me. I think I have tried all the possibilities. There must be something I don't understand. How do I get this to work?

We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)
 
On my home computer I found and ran:
Code:
SYSTEMTIME start_time;
...
GetSystemTime( &start_time );
Which works fine. I am pretty sure I obtained LPSYSTEMTIME from the help VS facility at work. Visual Studio 2008 are running on both computers. I wonder why the difference and why the LPSYSTEMTIME does not work.
I will shift to SYSTEMTIME on Monday and see how that goes.


We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)
 
The OP snippet uses uninitializing pointer m_start. Of course, you have run time exception: GetSystemTime writes the value to nowhere.
 
The OP contains:
Code:
mp_start = &m_start;
If that is not a valid initialization please advise.

At work I shifted to the type SYSTEMTIME and it works as expected. A second check of the VS2008 help utility shows LPSYSTEMTIME and not SYSTEMTIME. I find that rather curious in that it differs from VS2008 that I have at home.

Mark this thread resolved.



We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)
 
In the original posting, you have
Code:
LPSYSTEMTIME   m_start;
LPSYSTEMTIME  *mp_start;
...
mp_start = &m_start;
Which should have given you a compile warning. The reason why you are getting a runtime exception is space. m_start is only 4 bytes long (32 bits). As you have discovered,
Code:
SYSTEMTIME m_start;
GetSystemTime (&m_start);
works because m_start now has a valid amount of space. I think that should solve your mystery.
 
Now I see my error. I was not reading carefully and did not recognize that LPSYSTEMTIME is a pointer to SYSTEMTIME. I was thinking that LPSYSTEMTIME was just a variant (one of many types, not variant as in BASIC) of the system time structure.

I could have written
Code:
SYSTEMTIME right_now;
LPSYSTEMTIME p_right_now = &right_now;

Thanks for your patience!

We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top