This code is deeply broken. You're returning a pointer to memory that is freed when the function exits (because the temporary wstring will be destructed). It may seem to work, but that's the horrifying reality of undefined behavior - it often seems to work until it bites you viciously.
+1 for noticing this, I totally read over it to be honestly. Especially noteworth that this can, and will lead to many horrible things happening - for example, in my first resource cache class, I was storing the resources by LPCWSTR. It seemed to work fine while I was only hardcoding everything in the code, but after a while I got an issue where setting constant to my effects was only working sporadically. Turned out the LPCWSTR-keys got trashed, and whenever accessing an effect from the cache, a new isntance was loaded and stored in another key that became trashed, and so forward. Wouldn't even had thought about looking there in the first place, as it appeared to be a graphics-related error. Moral of the story: Always double-check on how you use your strings.