就是用getLastErr可以得到錯誤号,同時,會将需要的長度寫到參數裡,再進行第二次調用,以此來節約記憶體空間。
神奇的長見識了。
相關說法如下:
======================
The error occurs because the buffer is insufficient. :-) It's not large enough for the content. Once again, I refer you to the documentation. If the function fails, the <code>ReturnLength</code> parameter is set to the size of the buffer needed, so you can allocate sufficient memory and call the function again. The general rule for many API calls that have variable buffer requirements is "Call the function once with a NULL buffer to determine the buffer size needed, allocate the memory, and then call it again to actually retrieve the information"
The <code>TOKEN_USER</code> structure contains pointers (in particular, a pointer to a <code>SID</code> that itself has variable length). Those pointers have to point somewhere. The API function will expect a buffer big enough to hold not only the the <code>TOKEN_USER</code> structure, but also all the things that structure points to. The function tells you how much memory it needs for everything. It will all reside in adjacent memory.
最近又在重新編寫一些以前已經實作過的功能, 一來是溫習之前學的一些東西, 二是希望多次重寫一個功能的過程中提升自己現有的程式設計技術和水準, 今天這篇文章算是一個小的總結.
在寫之前請容許我唠叨片刻, 文章中涉及的技術與代碼示例可能早遍布在百度與GOOGLE上的各種原創或轉載文章中, 是以我的内容多少也會與那些文章中的東西有所相同, 對于那些已經看過那些文章或者早已熟悉這些技術朋友可能會略顯平庸, 不過這都算是自己對技術積累的心得吧, 見笑了, 那麼言歸正傳了.
Win32 API中提供了GetTokenInformation與SetTokenInformation函數, 這2個函數别分是檢索與設定一個通路令牌的資訊, 關于通路令牌的具體細節有興趣的朋友可以去MSDN上找, 因為與文章主題沒有直接的關系, 是以就不在具體細說了.
以下是GetTokenInformation的API原型(如果想對這個函數的細節做更多了解, 可以去MSDN上查詢它的詳細資訊)