In the parameters to FormatMessage, you are calling GetLastError again. This will not get you a message about your error value, err. It will most likely get you something odd, since you've already called GetLastError prior to the call to FormatMessage. :)
[EDIT]
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0,
NULL
);
You may need to pass in the actual err value that you want a message for. :)