Handling WM_NOTIFY Messages

Plug-in code should not assume when receiving a WM_NOTIFY message that lParam is always a pointer to a structure of type OFNOTIFY. The lParam parameter should always be interpreted as a pointer to an object of type struct NMHDR. If NMHDR::code is between [CDN_LAST, CDN_FIRST and is equal to CDN_INITDONE, lParam could then be interpreted as a pointer to a OFNOTIFY struct.

Here's a code snipped that correctly interprets the lParam parameter received with a WM_NOTIFY message sent to a file I/O hook procedure:

static INT_PTR CALLBACK HookProc(
  HWNDhWnd, UINTmsg, WPARAMwParam, LPARAMlParam)
{
  switch (msg) {
    case WM_NOTIFY: {
      LPNMHDRpNMHDR = (LPNMHDR)lParam;
      if (CDN_INITDONE == pNMHDR->code){
         OFNOTIFY* pOfnotify = (OFNOTIFY*)lParam;
        // Do something with pOfnotify
      }
      break;
    }
    // react to more messages
  }
return FALSE;
}