问题
I created a deskband on taskbar. When I want to update the DLL of the deskband, I hide it , unregister it,but unfortunately the explorer still keeps this DLL in the memory.
How can I update the dll without restart the explorer process? There is any Windows api for such a case?
回答1:
"Unsupported" (aka hack) solution (C/C++):
HWND hWnd = FindWindowW(L"Shell_TrayWnd", NULL);
if (hWnd != NULL)
PostMessageW(hWnd, WM_TIMER, 0x18, 0);
This will force the call of CoFreeUnusedLibraries function in the explorer process.
Tested on Windows 7 Ultimate SP1 64-bit and Windows XP Professional SP3 32-bit.
BTW, you can hit Windows+D (to minimize all windows) and wait for 3 minutes. The programmatic hack is based on this behaviour. It just calls the timer handler inside explorer process. And the handler code (C/C++) is:
KillTimer(hWnd, 0x18);
CoFreeUnusedLibraries();
There is no harm in calling of KillTimer function for non-existent timer.
回答2:
No, there's no supported way to do this. The earliest the DLL might unload would be if it returned true from DllCanUnloadNow a couple of times with a delay in between -- triggered for example by a CoFreeUnusedLibraries which would have to come from within the explorer process. Unregistering it will have no impact.
If you are developing this kind of DLL, you need to get comfortable with restarting explorer.
Martyn
回答3:
As Martyn says there is no supported way to do exactly what you are asking.
But you can still make the update process less intrusive. Just have your plugin DLL serve as only a barebones interface to explorer, and offload everything else to a separate DLL which you can explicitly load and unload from the process. Then you only need to reload explorer when something has to change with the interface. If done right you should rarely have to update the plugin DLL.
来源:https://stackoverflow.com/questions/8222711/how-can-i-remove-a-deskband-and-delete-its-dll-without-restart-the-explorer-proc