E' tutto spiegato nelle note dell'opzione FORMAT_MESSAGE_ALLOCATE_BUFFER, che tu usi

The function allocates a buffer large enough to hold the formatted message, and places a pointer to the allocated buffer at the address specified by lpBuffer. The lpBuffer parameter is a pointer to an LPTSTR; you must cast the pointer to an LPTSTR (for example, (LPTSTR)&lpBuffer). The nSize parameter specifies the minimum number of TCHARs to allocate for an output message buffer. The caller should use the LocalFree function to free the buffer when it is no longer needed.

E ti faccio notare che, nel tuo codice, manca la chiamata (necessaria) alla LocalFree.

Nel caso non usassi l'opzione FORMAT_MESSAGE_ALLOCATE_BUFFER, allora dovresti allocare (e liberare) tu il buffer e passare semplicemente il puntatore.