Updating the patch now. Note in particular with the SetLastError() calls, that the error messages immediately after the API calls do print the result of GetLastError(), so it would be good to return the last error to a known state for that.
Thanks! -John Sheu