toWCharArray() returns the length. Shouldn't it be wsave_path[len] = '\0'; ?