Handle application paths larger than MAX_PATH, and fix potential buffer overflow