|
-
March 30th, 2006, 08:56 AM
#1
[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?
-
March 30th, 2006, 11:02 AM
#2
Re: call GetTokenInformation cause error
122 is the code for ERROR_INSUFFICIENT_BUFFER.
 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.
"inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
Club of lovers of the C++ typecasts cute syntax: Only recorded member.
Out of memory happens! Handle it properly!
Say no to g_new()!
-
March 30th, 2006, 08:18 PM
#3
Re: call GetTokenInformation cause error
But,how to resolve the problem?
-
March 31st, 2006, 05:37 AM
#4
Re: call GetTokenInformation cause error
 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);
"inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
Club of lovers of the C++ typecasts cute syntax: Only recorded member.
Out of memory happens! Handle it properly!
Say no to g_new()!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|