Having seen how MAKELONG uses two parameters of the Word type (16 bits), and Msg.Message and Msg.HWnd - 32 bits, it is not surprising that you get range checking errors. In general, window messages are <$ 8000, so I doubt this is a problem. However, the integral value of HWnd can be across the map and, of course,> $ FFFF quite often. Because of this, the above code does not actually make sense, except that it seems to have left an artifact from the 16-bit version long ago.
Since range checking is enabled, this clearly emphasizes the fact that the above code needs to be rethought. In Win32, you can no longer accommodate the message value and window handle in 32 bits.
I hope I have given you some tips on how to proceed. Without taking into account the code that calls this function, it is impossible to offer an alternative implementation.
source share