Sign in to follow this  
etsuja

StringCchLength, how do you use it?

Recommended Posts

DadleFish    150
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this