CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2004
    Location
    China
    Posts
    16

    [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?

  2. #2
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    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.
    "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()!

  3. #3
    Join Date
    Aug 2004
    Location
    China
    Posts
    16

    Question Re: call GetTokenInformation cause error

    But,how to resolve the problem?

  4. #4
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    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);
    "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
  •  





Click Here to Expand Forum to Full Width

Featured