Shell_NotifyIcon returns FALSE
Posted on 2004-11-22
I have an application that runs as a Windows service and shows up in system tray. I am compiling the application in XP SP1 and everything works fine on XP. When I install this same exe on Windows 2000 server machine and the service is started, the exe runs but it never shows up in the system tray. I added some debug code and it seems that GetLastError after Shell_NotifyIcon is returning error 2, which is 'system cannot find the specified file'. Also when the same exe on Windows 2000 machine is run as a normal application (by double clicking), it appears fine in system tray. The service is set up to interact with the desktop.
Here is the code that adds the icon to system tray and it always returns false when run as service on W2K.
BOOL TaskBarAddIcon (HWND hWnd, UINT uID)
HANDLE hIcon = NULL;
gCurrID = uID;
hIcon = LoadIcon (hInst, MAKEINTRESOURCE (uID));
tnid.cbSize = sizeof (NOTIFYICONDATA);
tnid.hIcon = hIcon;
tnid.hWnd = hWnd;
lstrcpy (tnid.szTip, "My tip");
tnid.uCallbackMessage = MY_TASK;
tnid.uID = uID;
tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
bRet = Shell_NotifyIcon (NIM_ADD, &tnid);
if (hIcon) DestroyIcon (hIcon);
Do you have any suggestions?