tlhelp32.h不包含windows.h本身的原因嗎?包含tlhelp32.h之後,我正在處理大量編譯器錯誤,因爲我包含了windows.h。這是一個設計決定還是出於什麼原因?我是新來的C++,所以我沒有得到它。如果一個頭文件有依賴關係,它應該包含它們。C++頭文件本身不包含依賴文件頭
#include <windows.h>
#include <tlhelp32.h>
#include <tchar.h>
std::vector<unsigned long> GetProcessIdsHelper()
{
std::vector<ULONG> result;
auto snapshotHandle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (snapshotHandle == INVALID_HANDLE_VALUE)
return result;
PROCESSENTRY32 processEntry;
if (!Process32First(snapshotHandle, &processEntry))
return result;
do
result.push_back(processEntry.th32ProcessID);
while (Process32Next(snapshotHandle, &processEntry));
return result;
}
不回答爲什麼他們這樣做,但... https://stackoverflow.com/questions/34502661/c-tlhelp32-h-not-working – NathanOliver
它被認爲是一種很好的風格,在.cpp中你可以包括以任意順序選擇任何標題。微軟的某個人不知道或不關心或者有更重要的事情要做。特別是'windows.h'也會''定義'宏'比如'max',然後搞亂標準庫。不要將這些頭文件作爲C++頭文件的例子。 – nwp