Re: GetTokenInformation example done right
* Giovanni Dicanio:
One more little "critique" to Alf's code :)
I think this function is not good, because it is ANSI/MBCS only, I think it
won't compile in Unicode:
<code>
std::string stringFromSid( PSID sid )
{
char* p;
ConvertSidToStringSid( sid, &p )
|| throwX( "stringFromSid: ConvertSidToStringSid failed" );
std::string const result = p;
LocalFree( p );
return result;
}
</code>
This is because ConvertSidToStringSid function has this prototype:
BOOL ConvertSidToStringSid(
__in PSID Sid,
__out LPTSTR *StringSid
);
instead in your code you use std::string, which is based on char* (no
TCHAR).
A CString should be better used, or if one likes the STL string classes,
better doing the usual tip-and-trick:
typedef std::basic_string< TCHAR > tstring;
Well, I don't think Windows 9x compatibility (T) is very important here. After
all, at least AFAIK, many of the relevant functions are only implemented on NT
platforms. So for Unicode I'd just use a std::wstring, but still narrow
character strings for the exceptions.
That means an additional signature, perhaps a name change, and that the above
(since Unicode is the only reasonable default) should better use
ConvertSidToStringSidA, assuming that's the narrow character version's name.
Sorry for writing that code in haste. :-)
And thanks for pointing that out.
I was mostly focusing on refactoring the original code.
Cheers,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?