Melissa McCarthy plays cantankerous, frumpy, down-on-her-luck writer Lee Israel.

Melissa McCarthy has often been wasted in movies not worthy of her talent.

Dreadful comedies like “The Happytime Murders” and “The Boss,” for instance. Or the recent “Ghostbusters.”

With the seriocomic “Can You Ever Forgive Me?” she’s finally given some challenging material, and she makes the most of it.

Based on a true story, it stars McCarthy as cantankerous, frumpy, down-on-her-luck writer Lee Israel. Because of her off-putting personality and her insistence on writing about subjects foreign to modern readers (a biography of Fanny Brice, for instance), Lee is out of work, out of money, and out of prospects.

Meanwhile, the rent is due, vet bills are due (she admits she likes cats more than people), and alcohol costs money – and Lee, along with her other issues, is an alcoholic. She’s so hard up that she steals a few rolls of toilet paper from her agent (Jane Curtin).

Desperate, she starts forging and selling “rare” letters from dead celebrities such as Noel Coward and Dorothy Parker, making sure to add juicy details to get a better price for them. Finally, she’s found a way to make money – and she feels a sense of artistic accomplishment, since the witty phrases that often delight buyers are actually made up by her.

She shares her secret with her unlikely new drinking buddy, the charming but dissolute Jack Hock (Richard E. Grant), who becomes her accomplice. Of course, it’s only a matter of time before things start going horribly wrong.

Directed by Marielle Heller (“The Diary of a Teenage Girl”), “Can You Ever Forgive Me?” is, in a way, like its central character. Just as Lee Israel is told by her agent that readers aren’t interested in Fanny Brice, Hollywood wisdom might suggest that moviegoers might not rush to see a movie about a character like Lee. She isn’t a lovable or even, necessarily, likable. And we’re not encouraged to feel too sorry for her (most of the time), or to accept her criminal activities as some comical quirk (see “The Old Man & the Gun”).

So for director Heller, and McCarthy, the film seems a risk.

But it pays off, in part because it doesn’t yield to commercial compromise, while still entertaining us with its offbeat story and the magic that occurs whenever McCarthy and Grant are on the screen together. Though their characters have similarities (both gay, both alcoholic, both rebellious in their ways), their personalities are so different – Lee is so prickly; Jack, so vivacious. It’s fascinating to watch as they find in each other a kindred spirit. This relationship overshadows the forgery plot.

Grant actually steals the picture as the flamboyant social outcast Jack. But McCarthy certainly comes out a winner, too. Hopefully, she’ll get more ambitious roles like this.