Reputation: 278
I have a problem when calling GetTokenInformation, for some reason it fails on windows server 2003 32bit but succeeds on server 2008 64bit.
PTOKEN_USER pSIDTokenUser = NULL;
DWORD dwReturnLength;
if (!GetTokenInformation(hToken, TokenUser, NULL, 0, &dwReturnLength) && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
{
//handle error
}
pSIDTokenUser = (PTOKEN_USER)new BYTE[dwReturnLength];
memset(pSIDTokenUser, 0, dwReturnLength);
if (!pSIDTokenUser)
//handle error
if (!GetTokenInformation(hToken, TokenUser, pSIDTokenUser, dwReturnLength, NULL))
//handle error
the second call to GetTokenInformation on windows 2003 always return 0 with the error 998 ("Invalid access to memory location"). I assume it has something to do with the pSIDTokenUser size/alignment (I use the default) etc, but could not find the reason.
Thanks.
Upvotes: 0
Views: 976
Reputation: 91925
The final parameter, ReturnLength
is not optional, according to the function annotations. Don't pass NULL in the second call. You appear to be getting away with it on Windows 2008.
Upvotes: 2