October 26th, 2012
After porting Easy2Sync for Files to Unicode I experienced some really weird problems with some foreign characters. Unicode in general worked, Japanese characters were displayed nicely (not that I could read them). But Cyrillic characters failed when printed with TextOut and were displayed as small black rectangles.
Even weirder: Adding just 1 Japanese character to a string with Cyrillic characters caused the entire string to be printed right.
It seems that TextOut is only 50% Unicode compatible (of course Microsoft doesn’t mention this). So one has to use DrawText instead, which doesn’t seem to have these limitations. Since DrawText behaves differently regarding the position and background drawing, here’s a wrapper which fixes this and makes it behave like ExtTextOut:
void FixedExtTextOut (CDC *pDC, int x, int y, UINT nOptions, LPCRECT lpRect, LPCTSTR lpszString, UINT nCount, LPINT lpDxWidths)
CRect rr(x, y, lpRect->right, lpRect->bottom);
pDC->DrawText(lpszString, nCount, &rr, 0);
June 14th, 2012
You're not gonna catch this... (LIttle League baseball, May 2009 - 03 by Ed Yourdon; CC BY-SA 2.0)
C++ exceptions can be surprising. This works easily:
catch(…) //Catch all
But if you replace “throw(1);” with “throw;”, it suddenly doesn’t work anymore. Code compiles, exception is thrown, but it’s not caught. The program is terminated…
June 6th, 2012
By default MFC applies the MouseWheel message to the window that has the focus. Even though most users expect it to apply to the window under the cursor. (And even Microsoft’s style guide recommends that.)
To fix this, override the program’s PreTranslateMessage function and add this:
HWND hWnd = ::WindowFromPoint (point);
if (hWnd && pMsg->hwnd!=hWnd)
::PostMessage(hWnd, pMsg->message, pMsg->wParam, pMsg->lParam);
Please note that you have to add this before calling the default implementation of PreTranslateMessage.
June 1st, 2012
It sounds quite mad, but either of these lines can crash a program: (C++, Visual Studio 2005)
long x = long(my_float_var);
float f = exp(my_float_var);
If the number is too large/small, the program is terminated. (No, try/catch doesn’t help.) And to make it even stranger, this happens only on some computers. And of course it happened on the customer’s computer and not on mine…
To fix this, it helps to turn off the floating point exceptions:
Of course the problem of the large number still exists, but now the program at least continues to run, and I have a chance to handle it.
May 21st, 2012
What items causes which rating with apple? Well, here’s a summary. Please contact me if I missed anything… 😉
May 4th, 2012
It sounds pretty straightforward to enumerate the resources in a file. But it turned out to be rather a lot of work (and waste of time), since the MS doesn’t tell you, that it doesn’t enumerate the strings, but blocks of strings in a binary format that you have to process yourself.
Here’s how to do it:
BOOL CALLBACK EnumResNameProc(HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam)
HRSRC hRes = FindResourceEx(hModule, RT_STRING, MAKEINTRESOURCE(lpszName), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
HGLOBAL hGlo = LoadResource(hModule, hRes);
LPCWSTR lpStr = (LPCWSTR)LockResource(hGlo);
DWORD dwsize = SizeofResource(hModule, hRes);
for (int i=0; i < (int)dwsize; i++)
WORD *pString = lpStr+i+1;
long lString = lpStr[i];
//Process string here
i += lpStr[i];
EnumResourceNames(hModule, RT_STRING, &EnumResNameProc, NULL);
April 1st, 2012
It sounds like an April Fools’ Day prank. But I didn’t make this one up. Promise.
I just entered “iTunes” as search keyword for Google AdWords. I wasn’t surprised that Google didn’t allow it. But it reason was a jaw-dropper:
These entries could not be added due to the following reasons:
Unacceptable Business Practices (Detail)
We’ve detected that your keyword list may contain words related to unacceptable business practices. Google policy does not permit the advertisement of websites that contain unacceptable business practices.
Recommended actions: Please delete or edit these keywords.
So is Google accusing Apple of “Unacceptable Business Practices”? Sounds like it. I know that they didn’t really like each other since Google started Android, but this is pretty heavy stuff.
December 14th, 2011
1. The reason guesser
His goldfish died while the customer was installing your software. So it must be your fault. That’s why he sends you a three-page e-mail.
2. The ignorer
You wrote that the customer should do 1. … 2. … 3. … to solve the problem. The customer writes back that he did something completely different, that it still doesn’t work and that your support sucks.
3. The insister
Tells you that you’re all wrong, ignores everything that you wrote and insists that you’d better send him a solution RIGHT NOW.
And probably there are many more types… 😉
June 2nd, 2011
Just a tiny trick today.
When you’re programming, you’re often…
- typing something
- Then you browse through the same file, look for something
- copy something
- And now you want to get back to the place that you previously edited.
There’s a secret hotkey (actually a sequence) for that which works in most editors: Ctrl+Z, Ctrl+Y.
Works in Visual Studio, Word, text editors, etc.
April 5th, 2011
I recently published a new software: ZeroClickSpellchecker. It’s basically a spell-checker which doesn’t mark errors, but auto-corrects them. At least those that can be corrected safely. (It won’t try to correct kljfhsdakljh, for example.) But quite a lot errors can be corrected, so the program works pretty well. It effectively that speeds up your typing, because you don’t have to stop and correct any more.
It’s great tool when writing e-mails. Basically I wrote it because I was fed up with typing “copmuter” again and again. If you find this (or other typos) in your own e-mails, check out my auto-correction software.