The full example from your second URL should clearly indicate how the length returned from the first call is used. You use this to allocate raw memory of this size - this is a variable ptg- and give it to PTOKEN_GROUPS for use in the second call.
if (!GetTokenInformation(
hToken,
TokenGroups,
(LPVOID) ptg,
0,
&dwLength
))
{
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
goto Cleanup;
ptg = (PTOKEN_GROUPS)HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY, dwLength);
if (ptg == NULL)
goto Cleanup;
}
if (!GetTokenInformation(
hToken,
TokenGroups,
(LPVOID) ptg,
dwLength,
&dwLength
))
{
goto Cleanup;
}
source
share