# File lib/facter/util/windows/process.rb, line 36
  def get_token_information(token_handle, token_information, &block)
    # to determine buffer size

    FFI::MemoryPointer.new(:dword, 1) do |return_length_ptr|
      result = GetTokenInformation(token_handle, token_information, nil, 0, return_length_ptr)
      return_length = Facter::Util::Windows::FFI.read_dword(return_length_ptr)

      if return_length <= 0
        raise Facter::Util::Windows::Error.new(
            "GetTokenInformation(#{token_handle}, #{token_information}, nil, 0, #{return_length_ptr})")
      end

      # re-call API with properly sized buffer for all results

      FFI::MemoryPointer.new(return_length) do |token_information_buf|
        result = GetTokenInformation(token_handle, token_information,
                                     token_information_buf, return_length, return_length_ptr)

        if result == Facter::Util::Windows::FFI::WIN32_FALSE
          raise Facter::Util::Windows::Error.new(
              "GetTokenInformation(#{token_handle}, #{token_information}, #{token_information_buf}, " +
                  "#{return_length}, #{return_length_ptr})")
        end

        yield token_information_buf
      end
    end

    # GetTokenInformation buffer has been cleaned up by this point, nothing to return

    nil
  end