1

I am having difficulty determining what the exact size of a Word should be in the context of the Windows API function mbstowcs_s. Here is the relevant information from the MSDN as well as the link.

mbstowcs_s, _mbstowcs_s_l

Converts a sequence of multibyte characters to a corresponding sequence of wide characters. Versions of mbstowcs, _mbstowcs_l with security enhancements as described in Security Features in the CRT.

Parameters

[out] pReturnValue - The number of characters converted.

[out] wcstr - Address of buffer for the resulting converted wide character string.

[in] sizeInWords - The size of the wcstr buffer in words.

[in] mbstr - The address of a sequence of null terminated multibyte characters.

[in] count - The maximum number of wide characters to store in the wcstr buffer, not including the terminating null, or _TRUNCATE.

Here is the link to the MSDN page: https://msdn.microsoft.com/en-us/library/eyktyxsx.aspx

Any ideas?

HighExodus
  • 104
  • 2
  • 11
  • It's the number of `wchar_t`s in the buffer that `wcstr` points to – Praetorian Mar 04 '15 at 19:11
  • @Praetorian So it is essentially the length (in wide characters) of the buffer... seems like WORD was the wrong _word_ choice to describe the parameter... If you post this as an answer I will accept it. I do not have enough of a reputation to up-vote your comment at this time. – HighExodus Mar 04 '15 at 19:16
  • 2
    I agree, better wording would've been exactly as you put it ... number of wide characters in the buffer. I suspect this is a case of Windows API terminology leaking into the docs, because WinAPI uses `WORD` as a typedef for a 16-bit unsigned int, and `wchar_t` is also 16-bit on Windows. Anyway, you already have an answer (although I disagree with his first sentence, and it digresses a bit from answering the actual question), I won't add another one because I don't really have any proof, if you will, that what I said is correct. – Praetorian Mar 04 '15 at 19:23

1 Answers1

0

Normally a word means 16 bits.

To make sure, allocate a buffer of let's say 100 bytes, fill them all with 0xff. Then pass 16 for sizeInWords and an mbstr of at least 16 characters. In the debugger inspect wcstr when the call is done. If I'm right, the first 32 bytes of the buffer will have character values, the rest will still be 0xff. (of course this ignores the fact that some values of wcstr may be 0xff)

Sebastiaan M
  • 5,775
  • 2
  • 27
  • 28