Archive for the ‘microsoft’ Category

Dangerous MakeLower

Thursday, May 2nd, 2013

Got weird crashes at customers with foreign languages? Microsoft’s MFC’s MakeLower could be the culprit. Seems to be poorly written because it can crash if it doesn’t like the string. I could even reproduce it here by switching the Windows-Locale for non-unicode apps the Japanese and process some strings contains German umlauts. Bottom-line? Don’t use, write your own… 🙁

Using Visual Studio 2012… Safely…

Thursday, January 10th, 2013

Microsoft Visual Studio 2012 isn’t so bad. 😉 I actually even like new dark looks. But (for C++) you shouldn’t use the default settings, our you’ll get problems with your older customers.


1. Making it run with XP

Go to “configuration properties > general” and switch the “Platform toolset” to “Visual Studio 2012 – Windows XP (v110_xp)”.


2. Making it run on older systems

This caused me hours of work. By default VS2012 will “optimize” fp-operations. But it doesn’t work on all systems. Don’t know if it’s the older processors but I had at least 2 customers where a simple statement as “myfpvar=1” caused the program to terminate without error message. To fix this go to “C++> Code generation” and set “Enable enhanced instruction set” to “No Enhanced Instructions (/arch:IA32)”.

Weird TextOut Unicode problems

Friday, 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->FillSolidRect(lpRect, pDC->GetBkColor());
 pDC->DrawText(lpszString, nCount, &rr, 0);

Devloping asp.NET websites in 3 simple steps…

Tuesday, December 7th, 2010

Step 1: Waste hours researching to find out how to do something trivial. (Like renaming the insert link)

Step 2: Curse Microsoft

Step 3: Throw out the MS way and program it yourself.

Repeat for every trivial issue.

Visual Studio 2005: Speeding up compiles

Tuesday, October 19th, 2010

There’s a hidden switch in Visual Studio 2005 while doubles compile speed.

I know, it sounds ridiculous.  But I’ve tested it. It’s MUCH faster now. The switch works by enabling multi-core processing. I have no idea why Microsoft has hidden this, instead of making it a big, obvious feature.

Anyways. You can enable it by adding /MP to the “Additional options” in “Configuration properties > C/C++ > Commandline”.

(Found it at 1 and 2)

Don’t force me to reboot on updates… (Windows XP)

Sunday, March 1st, 2009

I just experienced a kind of terribly bad ideas part II for software design.

Microsoft has rolled out a new update. It’s  great that it was downloaded automatically. It would certainly have been nice if Microsoft had ASKED me for permission before installing it.

And it would have been VERY nice  if Microsoft would just have accepted that Ihad better things to do than to reboot my computer right now. That stupid messages comes every few minutes. Now, what part of NO don’t you understand?

The inevitable thing happened. I was away from the PC for a few minutes, couldn’t click on the “no” button and the computer rebooted. I can only assume it, but I doubt that the reboot process would have stopped if I had any unsaved data. (Because Opera told me on start-up that it hadn’t been closed normally.) Data loss by design. Great idea, Microsoft!

Now here’s the fix. You can download this reg-file and double-click it. It will insert 2 keys into your registry and should protect you against this very bad default behaviour.

Tips for minimizing your app to the Tray

Friday, November 28th, 2008

It’s a nice feature for your software if your customer can minimize it as an icon to the system tray. From our “minimize to tray” program I learned a few things about. Here’s a rundown of the basic and not-so-basic tricks.

  1. You can add / modify / remove a tray icon with Shell_NotifyIcon. You can specify a callback message (for example WM_USER) to react to left/right clicks on the icon. To hide your program when minimized simply use ShowWindow.
  2. To minimize to the tray when your user click the minimize button, handle the WM_NCLBUTTONDOWN message and watch for the HitTest HTMINBUTTON (or HTCLOSE if you want to override the X-button).
  3. If you want to prevent Windows from hiding the icon, make a tiny chnge to the icon every now and then. (Do this only if you have good reason!)
  4. You can use DrawAnimatedRects for a minmize animation. Use FindWindow(“Shell_TrayWnd”, …) to find the location (= target reactangle for the animation)
  5. If the windows explorer crashes, the tray icons are gone and your user can’t get your application back. To detect this, use Shell_NotifyIcon(NIM_MODIFY, … every now and then and check the return value. If the function fails, then your icon is gone and you have to add in again.
  6. Don’t forget to remove the tray icon if your program closes while being minimized.

Vista doesn’t like Demos

Sunday, September 14th, 2008

Vista is known to be “special” in some aspects. What’s perhaps not so well-known is that it doesn’t like anything called “Demo”. In fact, it will show an increased warning level for any installation file that has “_demo” in the filename.

A signed installer name “test_demo.exe” will generate a red warning. If you rename it to “test_trial.exe”, you’ll only get a yellow warning. Don’t ask me why, I got no idea (please contact me if YOU have). But I don’t call my demo “demo” any more…