Force Windows to refresh the Desktop (and Start Menu)

February 23rd, 2010

Today I learned a new trick.

When you programatically delete a shortcut from the Desktop folder Windows is “generally” smart enough to update the Desktop and the “recently used programs” section of the Start Menu. But sometimes it does not work and you are left with a “ghost” icon.

As a regular end user, you can hit the F5 key to force a refresh of the Desktop, but for the Start Menu you are left with no alternative than killing/restarting explorer.exe.

I was looking for a better solution for a custom installer application. And after a lot of MSDN scattering and googling around, Eureka, I finally found a magic incantation to programmatically force a refresh of the Desktop.

SHChangeNotify (SHCNE_ASSOCCHANGED, 0, 0, 0);

Aymeric Programming, Windows, c++, win32

Make LoadLibrary() failures silent on Win2k

December 3rd, 2009

For a custom installer application, I have been working on a crude and efficient way to determine whether the particular version of the C runtime (CRT) we need is installed or not. The technique I use is simply to check if a dummy DLL linked to the CRT libraries would load up properly.

This works gloriously well, except for one simple detail. When the CRT is not installed, on Windows 2000 only, the LoadLibrary error would also cause a MessageBox to be displayed. This stops the flow of the installer and of course, is not very elegant…

Win2k LoadLibrary failure

But there is a simple trick to get rid of the MessageBox, using the very obscure SetErrorMode system call.

::SetErrorMode(SEM_FAILCRITICALERRORS);
HMODULE hDll = ::LoadLibrary("CrtCheck.Dll"); // Won't bark
if (hDll)   ; // CRT is installed
else        ; // CRT is NOT installed

Do you guys know a better (yet simple) way to determine if the CRT is installed?

Update: this is not a Windows 2000 specific issue (thanks Ferruccio). It’s also true for older versions of Windows. As far as I know WinXP, Vista and 7 do NOT display a MessageBox under the same circumstances.

Aymeric Programming, Windows, c++, win32

XCode has dropped support for Java!

November 26th, 2009

I guess this is hardly news to anyone but me, since I have not written a single line of Java for the past 4 years, but apparently Xcode has dropped the support for Java projects.

As of Xcode 3.2.1, there is no way to create a command line or Swing application project which is fully managed by Xcode. There is still support for the Java syntax in the text editor and the java compilation tools are also installed, though.

One of the default project templates, JNI library, does actually let you create a project containing java files. However these files are compiled with ANT. This demonstrates that Xcode can still be used for Java development through the use of “external build systems”, but that’s it… Java is no longer a first class citizen in Xcode.

I guess this decision makes sense for Apple. The Cocoa bindings for Java have not been supported since MacOS X 10.4 after all.

Aymeric Java, MacOS X, XCode