If you're using an external DLL, you can put the icon switching message call in the DllMain call. It's executed before compiling.