[RESOLVED] call GetTokenInformation cause error
Code as follow:
HANDLE hToken;
if(!OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, TRUE, &hToken))
{
if(!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
{
return kcy_err;
}
}
//didn't return,above two function are success
DWORD dwUserSize = 0;
GetTokenInformation(hToken, TokenUser, NULL, 0, &dwUserSize);
//GetTokenInformation return FALSE,call GetLastError get error code is 122,what's the mean?
Re: call GetTokenInformation cause error
122 is the code for ERROR_INSUFFICIENT_BUFFER.
Quote:
Originally Posted by msdn
TokenInformation
[out] Pointer to a buffer the function fills with the requested information. The structure put into this buffer depends upon the type of information specified by the TokenInformationClass parameter, as shown in the following table.
NULL The function returns ERROR_INSUFFICIENT_BUFFER and stores the size required for the buffer in ReturnLength. The caller can then allocate a buffer with the required size and pass the address of the buffer as TokenInformation in another call to this function.
MSDN is not exact here.
In fact, the function doesn't return ERROR_INSUFFICIENT_BUFFER, but returns FALSE and set the last error to ERROR_INSUFFICIENT_BUFFER.
Re: call GetTokenInformation cause error
But,how to resolve the problem?
Re: call GetTokenInformation cause error
Quote:
Originally Posted by halfman
But,how to resolve the problem?
Hey, you want a TOKEN_USER!
So, pass a pointer to it:
Code:
TOKEN_USER tkUser;
GetTokenInformation(hToken, TokenUser, &tkUser, sizeof(tkUser), &dwUserSize);