rnk is on leave, so I'll jump in.
This is correct, but I have a small suggestion inline to make it more robust against future changes.
I would probably just return the error here rather than break.
When you break, you end up calling GetLastError() again. While that's probably safe, a small future change could end perturb that last error code.