I tested your code and received the error
EILSEQ (42)
, which indicates that a character was found in the string that cannot be converted.
[edit]
Feedback from OP suggests that the
WideCharToMultiByte
function has been used to resolve the problem.
[/edit]