Our illusions come in five varieties, some of which are painful, others painless.
The important thing to remember in all cases, though, is that they are, ultimately, illusions. Our imagining winning the lottery may make us happy in the short term, but in the long term we will likely be hurt when we do not win. Remembering a departed loved one may seem painful initially, but if they passed after a long illness, perhaps we will come to see that it was a blessing that they were released from suffering.
Ultimately, though, these states of pain and pleasure are transitory. They are not our true state of being. When we vest importance in them, we are setting ourselves up for disappointment.