Click here to Skip to main content
15,887,820 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I am using Visual Studio 2008 on Windows CE. I am getting a weird stack overflow after calling the MFC function SetLocalTime. There is no code to step into and no call stack.

Here is my code:

C++
void OnBnClickedButtonSet()
{
  SYSTEMTIME time, new_time;
  GetLocalTime(&time);

  //get the date info
  time.wYear = static_cast<WORD>(i_year);
  time.wMonth = static_cast<WORD>(i_month);
  time.wDay = static_cast<WORD>(i_day);
 
  //get the time info
  DWORD ret = m_Time.GetTime(&new_time);
  if (ret == GDT_VALID)
  {
    time.wHour = new_time.wHour;
    time.wMinute = new_time.wMinute;
    time.wSecond = new_time.wSecond;
    time.wMilliseconds = 0;
  }
  else
  {
    TRACE(_T("not a time format\n"));
    return;
  }
 
  CString str(_T(""));

  //set the date and time
  if (!SetLocalTime(&time))
  {
     str.Format(_T("system time error = %d. \n"), GetLastError());
     TRACE(str);
    return;
  }//here the stack overflow message shows up; it only happens the first time i turn the unit on and if the user chooses new values only for the date (no stack overflow when setting the time).
}

SetLocalTime doesn't return an error and sets the chosen values for date/time, even if WindowsCE crashes and it needs restarting. After restarting, the date and time can be set again without any problems...

The Disassembly Window points here: "40060198 stmdb sp!, {r0, r4, r5, lr}". I don't know if this is helpful or not...

i_year, i_month and i_day are variables as int values for 3 edit controls where the user inputs the day, month and year.

Thanks in advance for your help.

CB

N.B. I tried SecureZeroMemory(&time, sizeof(time)) before GetLocalTime(&time) but no change.
Posted
Updated 14-Nov-13 6:59am
v3

1 solution

 
Share this answer
 
Comments
corina.beer 14-Nov-13 14:24pm    
Yes, sorry...
Albert Holguin 14-Nov-13 15:13pm    
Fortunately or unfortunately, same people watching... :)
corina.beer 14-Nov-13 15:42pm    
Now I know that posting a message = posting a question :) and only to do it in one place.
Albert Holguin 14-Nov-13 15:45pm    
Yeah, not everyone likes the breakup of a Q&A and the forum threads... does lead a lot of people to repost things, so you're not the first and definitely not the last.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900