Before exiting, Control Panel sends the CPL_STOP message once for each application in the DLL. The lParam1 and lParam2 parameters sent with the CPL_STOP message correspond to the application number and the lData value. After Control Panel sends the last CPL_STOP message, it sends a CPL_EXIT message and then calls the FreeLibrary function to free the DLL.
When the CPL_STOP and CPL_EXIT cases in the switch statement are exe-cuted, the DLL frees memory that it allocated. Typically, the DLL frees memory associated with individual applications when the CPL_STOP case is executed and frees any other allocated memory when the CPL_EXIT case is executed.