My understanding of the Windows API call GetLastError() is that it should only be checked when ::GetModuleFileName() returns 0 on error.
Otherwise GetExecutablesPath() could return an error despite nLen being valid if GetLastError() was inconsistent.
Patch updates function to only call GetOSLastError() when nLen == 0
Patch from ewan@codeplay.com