Link to home
Start Free TrialLog in
Avatar of howardsd
howardsd

asked on

2nd process to call Shell_NotifyIcon of an icon added by a diff process

I have a DLL that is loaded by two different exe's.

The first instance of the DLL loads an icon into the tray.

When a specific event occurs in the second instance I need the second exe to call a Shell_NotifyIcon(NIM_MODIFY, &nid) on the icon.

I'm using a shared data segment to declare the icon structure thinking that because it's shared across the DLLs the second instance of the DLL will be calling Shell_NotifyIcon with the correct nID and hWnd, which I have verified to be true.  Unfortunately, the Shell_NotifyIcon called by the second instance returns false.  Calling a GetLastError() after Shell_NotifyIcon failure only returns 0, which isn't any help.

#pragma data_seg(".shared")

NOTIFYICONDATA nid = {0};

#pragma data_seg()


I'm wondering if it's failing because the Shell_NotifyIcon is not being called by the original process.  Although, I've been unable to find any documentation that states that it's not possible to have a different process modify the icon.

Any help would be appreciated!
Avatar of jkr
jkr
Flag of Germany image

>>I've been unable to find any documentation that states that it's not possible to have a different process
>>modify the icon.

The hWnd in NOTIFYICONDATA will be diferent and the hIcon invalid - what are you actually trying to change?
Avatar of howardsd
howardsd

ASKER

> The hWnd in NOTIFYICONDATA will be diferent

Even if shared between the two instances of the DLL?  I've tested and the hWnd is the same when Shell_NotifyIcon is called by both processes, at least in my debug output.  

> what are you actually trying to change?

I'm attempting to change the actual hIcon if a certain condition is met, as well as the szTip.

The icon is probably the biggest challenge here, since icon handles are only valid in one process, and not in the other...
i was able to move the szTip change to the dialogproc, but still can't change the icon.
Just a moment - it should work if you do a 'LoadIcon()' in the DLL and assign it to the hIcon member in the NOTIFYICONDATA struct.
that's how it's being done, but i'm actually using LoadImage().  

the Shell_NotifyIcon still fails when being called by the second instance, even when using the handle from the first instance during the LoadImage() called by the second instance. (sorry, that was a little wordy)

i'm curious how the Shell_NotifyIcon fails but the GetLastError() returns a an error code of 0.

ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial