Hi Thomas ,
I even tried by keeping some hardcoded value like 15 in the place of
ARRAYSIZE(szBuffer) in GetTimeFormat() api . But then also it didn't help me .
Regarding return types , Actually GetTimeFormat() will return number of bytes
copies into buffer in success case . And it returns 0 in failure , When I
debugged it , I always get 9 as number of bytes transfered . The value is
varying to some other number (but not to 0) in case of junk . So GetlastError()
also didn't help me much . GetDateformat is working fine . The issue is only
with GetTimeFormat() .
Is there any way to know whether it is AM or PM with out using GetTimeFormat()
? Because , we can get the time using GetLocalTime() . But I need to show even
AM PM also .
I don't have privilige to use ctime library I guess.
Regards,.
Gopi.k
Thomas Hruska <[EMAIL PROTECTED]> wrote: 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;
> }
>
> 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/
GopiKrishna Komanduri
Software engineer
Hyderabad
[EMAIL PROTECTED]
---------------------------------
Download prohibited? No problem. CHAT from any browser, without download.
[Non-text portions of this message have been removed]