Although it has not the wisest implementation (see the previous remarks), your function works in VS6.0 as well.
Probably, you are seeing "garbage" string in watch window in a UNICODE build.
To fix...