• Advertisement
Sign in to follow this  

StringCchLength, how do you use it?

This topic is 4301 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've tried but I'm not sure what to put as the third parameter.

Share this post


Link to post
Share on other sites
Advertisement
The third parameter is the place in which the string length will be placed. As opposed to strlen, StringCchLength returns an HRESULT which is used for determining if the function succeeded or not. Here is a usage example:


char myString[256];
size_t maximalStringSize = 256;
HRESULT res;
size_t targetSize;
res = StringCchLength(myString, maximalStringSize, &targetSize);
if (SUCCEEDED(res))
{
// OK - targetSize now contains the length of the string.
}
else
{
// Error - probably couldn't find /0 in the 256 first bytes of the string
}


P.S. Next time when asking a question, try giving some more details. This function is not so popular - I didn't know about it until you've asked :-)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement