static uint GetTokenInformationLength(SafeCloseHandle token, TOKEN_INFORMATION_CLASS tokenInformationClass) { uint lengthNeeded; bool success; if (!(success = GetTokenInformation( token, tokenInformationClass, null, 0, out lengthNeeded))) { int error = Marshal.GetLastWin32Error(); if (error != UnsafeNativeMethods.ERROR_INSUFFICIENT_BUFFER) { throw FxTrace.Exception.AsError(new Win32Exception(error)); } } Fx.Assert(!success, "Retreving the length should always fail."); return lengthNeeded; }
static extern bool GetTokenInformation ( SafeCloseHandle tokenHandle, TOKEN_INFORMATION_CLASS tokenInformationClass, out uint tokenInformation, uint tokenInformationLength, out uint returnLength );