×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

GetSystemTime

GetSystemTime

GetSystemTime

(OP)
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)
 

RE: GetSystemTime

(OP)
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)
 

RE: GetSystemTime

The OP snippet uses uninitializing pointer m_start. Of course, you have run time exception: GetSystemTime writes the value to nowhere.
 

RE: GetSystemTime

(OP)
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)
 

RE: GetSystemTime

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.

RE: GetSystemTime

(OP)
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)
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close