Gopi Krishna Komanduri wrote:
> Hi Frnds,
> In the below mentioned code , GetTimeFormat is failing .Sometimes I am
> getting the correct time but some times It is dumping the buffer with junk
> some times . This error is not always reproducing . Only once in 3 to 4 times
> this error is coming up . Even I tried by keeping 0 as last paramenetr to get
> the length and then keeping that integer in the next call . Then also I am
> getting the same error .
> So the alternative I thought is to use GetLocalTime(&sysTime) , but
> strucked up in calculating AM or PM . Please help me for this error .
> CTitleBar::UpdateDateTime(
> BOOL fUpdateDate, //default FALSE
> LPCWSTR szTimeFormat //default NULL
> )
> {
> ENTER_FUNCTION_EX_STATIC
> LOG((RTC_TRACE, ("%s: Enter - Not implemented"), __fxName));
These macros could be messing with things.
> SYSTEMTIME sysTime = {0};
> SYSTEMTIME loctime = {0};
> TCHAR szBuffer[MAX_PATH] = _T("");
MAX_PATH should only be used for buffers that will be used for
_filenames_. And, even then, I personally don't like that macro as it
causes way too many problems.
> DWORD dwFlag = 0;
> ///TIME_ZONE_INFORMATION tzi;
> GetLocalTime(&sysTime);
> //GetTimeZoneInformation(&tzi);
> if(szTimeFormat)
> {
> m_strTimeFormat = szTimeFormat;
> }
> //ARRAYSIZE(szBuffer)
> GetTimeFormat(
> ::GetUserDefaultLCID(),
> TIME_NOSECONDS,
> NULL,
> m_strTimeFormat,
> szBuffer,
> ARRAYSIZE(szBuffer)
> );
What is ARRAYSIZE()? Possibly the cause.
> m_LblTime.SetWindowText(szBuffer);
> if((fUpdateDate) || (sysTime.wDay != m_nCurrentDay))
> {
> m_nCurrentDay = sysTime.wDay;
> CString strDateFormat = L"ddd, MM/dd";
> if(strDateFormat.IsEmpty())
> {
> dwFlag = DATE_SHORTDATE;
> }
> GetDateFormat(
> ::GetUserDefaultLCID(),
> dwFlag,
> NULL,
> strDateFormat,
> szBuffer,
> ARRAYSIZE(szBuffer)
> );
> m_LblDate.SetWindowText(szBuffer);
> }
> //szBuffer = _T("");
> LOG((RTC_TRACE, ("%s: Exit"), __fxName));
Again, you should remove this macro until the problem is solved.
> }
The lack of indentation makes the code hard to read.
You aren't checking return values for errors. MSDN Library clearly
indicates error conditions for both functions.
--
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197
*NEW* MyTaskFocus 1.1
Get on task. Stay on task.
http://www.CubicleSoft.com/MyTaskFocus/