1. He bought him a cooking book.

2. He bought him a cookbook.

(Which one is correct, 'cooking book' or 'cookbook'?)

3. Who wrote the song to her?
4. Who wrote the song for her?
(Do we have to use 'to' or 'for'? Are both OK?)

I take it that "he" and "him" are two different people? Yes or no?

#4 is correct, but#3 is not.

1. I bought him a cooking book.

2. I bought him a cookbook.

(Thank you. I need to change the subject. Are both expressions OK, 'cookbook' and 'cooking book'?)

No, only "cookbook" is used in this way.

If he is buying the cookbook for himself, then you'd say, "He bought himself a cookbook."

If he is buying the cookbook for someone else, then you'd say, "He bought his brother a cookbook."
(Substitute whatever you need for "his brother.")

1. The correct phrase is "cookbook," not "cooking book." A cookbook is a book that contains recipes and instructions for cooking, while a cooking book does not typically exist as a well-known term. To confirm this, you can consult a reliable dictionary or do a quick internet search to see the commonly used term is "cookbook."

2. Both sentences are grammatically correct, but there is a slight difference in meaning between "to her" and "for her" in these contexts.

- "Who wrote the song to her?" suggests that someone wrote a song specifically with the intention of giving it to her as a gift or expressing their feelings towards her through the song.

- "Who wrote the song for her?" implies that someone wrote a song on behalf of her or dedicated a song to her, without necessarily intending to give it as a gift or expressing personal feelings.

The choice between "to" and "for" depends on the intended meaning you want to convey in the sentence.