Pelles C forum

C language => Pocket PC and Smartphone questions => Topic started by: gromit on July 14, 2012, 12:33:25 pm

Title: DelKey Produces date
Post by: gromit on July 14, 2012, 12:33:25 pm

Hi folks Is this prob weird or what

This is my get todays date routine

Does what it says on the tin
wchar_t  *ReturnTodaysDateString()
wchar_t *xstr=L"";
wchar_t daystr[10];   
wchar_t mnthstr[10];
wchar_t yrstr[10];
if (st.wDay<10)
swprintf(daystr, L"0%d/",st.wDay);
swprintf(daystr, L"%d/",st.wDay);

if (st.wMonth<10)
swprintf(mnthstr, L"0%d/",st.wMonth);
swprintf(mnthstr, L"%d/",st.wMonth);

swprintf(yrstr, L"%d",st.wYear);

return xstr;


This is a  sip delete button handler used it for years no problem
// It is my own alphanumertic sip ( slightly larger than the one that the pda uses by default)

// Handle Delete____________________________________________________________
// g_editfocus is the edit control i am deleteing in
   SendMessage(GetDlgItem(h, g_editfocus),EM_GETSEL ,(WPARAM)&start,(LPARAM)&end);
   if (end>start && end!=0)
      SendMessage(GetDlgItem(h, g_editfocus),EM_REPLACESEL ,(WPARAM)TRUE,PARAM)L"");
   if (end==start && end!=0)
   SendMessage(GetDlgItem(h, g_editfocus),EM_SETSEL   ,(WPARAM)start-1,(LPARAM)end);
   SendMessage(GetDlgItem(h, g_editfocus),EM_REPLACESEL   ,(WPARAM)TRUE,(LPARAM)L"");
   SetFocus(GetDlgItem(h, g_editfocus));

return 0;

Now for the problem

No matter what dialog i am using or what control every time i tap delete instead of deleteing a character it prints the date into the edit box ?????????????????
Del key works fine until i call the date function

I have never been able to get _wcsdate(wchar_t * dst) to work always get unresolved externals error

i have tried setting todays datestr to both global and local variables and still same problem

Any help woul be appreciated
Title: Re: DelKey Produces date
Post by: TimoVJL on July 14, 2012, 01:25:56 pm
Try this:
Code: [Select]
wchar_t *ReturnTodaysDateString(void)
static wchar_t xstr[11];
swprintf(xstr, L"%04d-%02d-%02d",st.wYear,st.wMonth,st.wDay);
return xstr;
Title: Re: DelKey Produces date
Post by: gromit on July 14, 2012, 05:03:56 pm

Thanks timovjl 
:) :) :) :) :)
Whilst i am none the wiser as to why the bug occurred your code whacked it full on.
Now works perfectly.
Obviously a lot to be said for a better understanding of formatting text.

I Can only assume my wscpy ing of the various strings had some bearing on it

Once again big thanks have been struggling on that one for a couple of nights now :)