I know this was posted 9 years ago, but i couldnt help seeing a question that had no response
Theres not enough information provided to answer the question properly, if you want a proper answer you must include ALL the code so we can see what is happening, it is foolish to assume that all the other code is right, and we aren't psychic.
If there really is only a call to WideCharToMultiByte and the params are correct, all you need to do to see the problem is go to MSDN's page about WideCharToMultiByte. It is obvious that it is a dangerous call if misused and prone to give you errors. Most new programmers make the mistake of thinking that converting Wide chars (WCHAR) to multibyte is the same as converting it to 8-bit ascii. IT ISNT. The second mis-assumption is that the string will always be shorter. Depending on the content (and the params used calling the proc), you could end up with a string bigger than the one you started with, MBSTRs use the high bits to flag that the char is not a simple one and expands into 1 or more additional bytes to describe it. I don't know the specifics because I dont work with MBSTRs but I do know that they are not strictly all 1-byte-per-character. Sure, most strings would be, thats the deception.. and the first time you have to process a string with multi-byte chars, your dead.... I believe there is a proc or something that tells you how long the resulting string would be maybe even the same one your using, like I said, I dont work with em... just had to say this so others who come here via searches know that....
remember: old threads are constantly read upon and the information they contain are widely used even if they are wrong, it is our job to put things right -- even if it takes 9 years or more ---- http://paradisim.uuuq.com