As mentioned in my comment, I changed the value from Long to LongPtr for the variable lpfnEnum in the declaration of function EnumDisplayMonitors. Now the code compiles without any errors!
Long
LongPtr
lpfnEnum
EnumDisplayMonitors