请问如下关于进程快照的程序本人没调试通过请问那里出错了?
// Find each process and display it.
ListView1->Items->Clear();
HANDLE snapshot ;
PROCESSENTRY32 processinfo ;//PROCESSENTRY32为列举进程快照函数
processinfo.dwSize = sizeof (processinfo) ;//dwSize为字节分配
snapshot = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0) ;//CreateToolhelp32Snapshot创建一个快照
if (snapshot == NULL)
return ;
bool status = Process32First (snapshot, &processinfo) ;
while (status)
{
TListItem *li = ListView1->Items->Add () ;
String buffer ;
int length ;
buffer.SetLength (512) ;
length = sprintf(buffer.c_str (), "%08X", processinfo.th32ProcessID);
buffer.SetLength (length) ;
li->Caption = buffer;
buffer.SetLength (512) ;
length = sprintf (buffer.c_str (), "%08X", processinfo.th32ParentProcessID) ;
buffer.SetLength (length) ;
li->SubItems->Add (buffer) ;
li->SubItems->Add (processinfo.szExeFile) ;
status = Process32Next (snapshot, &processinfo) ;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
// Find each process and display it.
ListView1->Items->Clear();
HANDLE snapshot ;
PROCESSENTRY32 processinfo ;
processinfo.dwSize = sizeof (processinfo) ;
snapshot = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0) ;
if (snapshot == NULL)
return ;
bool status = Process32First (snapshot, &processinfo) ;
while (status)
{
TListItem *li = ListView1->Items->Add () ;
String buffer ;
int length ;
buffer.SetLength (512) ;
length = sprintf(buffer.c_str (), "%08X", processinfo.th32ProcessID);
buffer.SetLength (length) ;
li->Caption = buffer;
buffer.SetLength (512) ;
length = sprintf (buffer.c_str (), "%08X", processinfo.th32ParentProcessID) ;
buffer.SetLength (length) ;
li->SubItems->Add (buffer) ;
li->SubItems->Add (processinfo.szExeFile) ;
status = Process32Next (snapshot, &processinfo) ;
}
此快照只能反映某个时间片段的进程