Question about SetLocalTime failure of the program of WinCE Release version

Source: Internet
Author: User

========================================================== ==================================

Title: Problem about SetLocalTime failure of the WinCE Release version Program

Note: wince6 + vs2005

Date: 2011.6.14

Name: Zhu minglei

========================================================== ==================================

// Set the system date <br/> void CCalrDlg: OnBnClickedBtnUse () <br/>{< br/> SYSTEMTIME smCurSel, smCurTime, smSetTime; <br/> m_MCC.GetCurSel (& smCurSel); <br/> GetLocalTime (& smCurTime); <br/> smSetTime. wYear = smCurSel. wYear; <br/> smSetTime. wMonth = smCurSel. wMonth; <br/> smSetTime. wDay = smCurSel. wDay; <br/> smSetTime. wHour = smCurTime. wHour; <br/> smSetTime. wMinute = smCurTime. wMinute; <br/> smSetTime. wSecond = smCurTime. wSecond; <br/> SetLocalTime (& smSetTime); <br/> m_MCC.SetToday (smSetTime); </p> <p >}</p> <p>

This code has no problem in the Debug version and can be set successfully. However, problems may occur in the Release version. At first, I thought it was a problem somewhere else. Later I found that the SetLocalTime call failed. The error code returned through GetLastError is 87, which indicates that the parameter is invalid. After a breakpoint was set up, it was found that the value of wMilliseconds, a millisecond member of smSetTime, is a five-digit value. If the parameter is invalid, it means it.

// Set the system date <br/> void CCalrDlg: OnBnClickedBtnUse () <br/>{< br/> SYSTEMTIME smCurSel, smCurTime, smSetTime; <br/> m_MCC.GetCurSel (& smCurSel); <br/> GetLocalTime (& smCurTime); <br/> smSetTime. wYear = smCurSel. wYear; <br/> smSetTime. wMonth = smCurSel. wMonth; <br/> smSetTime. wDay = smCurSel. wDay; <br/> smSetTime. wHour = smCurTime. wHour; <br/> smSetTime. wMinute = smCurTime. wMinute; <br/> smSetTime. wSecond = smCurTime. wSecond; <br/> smSetTime. wMilliseconds = 0; <br/> SetLocalTime (& smSetTime); <br/> m_MCC.SetToday (smSetTime); </p> <p >}</p> <p>

If wMilliseconds is assigned 0, the SetLocalTime call is successful. In fact, if you maintain a good programming habit and initialize the variable during definition, this problem can be avoided.

// Set the system date <br/> void ccalrdlg: onbnclickedbtnuse () <br/>{< br/> systemtime smcursel = {0}, smcurtime = {0 }, smsettime = {0 }; <br/> m_mcc.getcursel (& smcursel); <br/> getlocaltime (& smcurtime); <br/> smsettime. wyear = smcursel. wyear; <br/> smsettime. wmonth = smcursel. wmonth; <br/> smsettime. wday = smcursel. wday; <br/> smsettime. whour = smcurtime. whour; <br/> smsettime. wminute = smcurtime. wminute; <br/> smsettime. wsecond = smcurtime. wsecond; <br/> setlocaltime (& smsettime); <br/> m_mcc.settoday (smsettime); <br/>}</P> <p>

The Release version does have much stricter requirements than the Debug version.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.