This is a quite ugly patch, adds unnecessary wstring copying. Why not: wsprintfW(buf, url_format, full_path, (index && index[0] == '/') ? empty : slash, index);