السلام عليكم و رحمة الله و بركاته
يمكن المثال المرفق من الإطلاع على قائمة الprocesses النشطة في حاسوب الكف/الهاتف الذكي
extern "C" __declspec(dllexport) BSTR _stdcall ListProcess()
{ char StrPsg[200];
char StrHnd[200];
memset(StrHnd, TEXT('\0'), 200);
memset(StrPsg, TEXT('\0'), 200);
CString Error="";
// first check the OS we are running on...
OSVERSIONINFO osinfo;
// this structure size must be set prior to calling GetVersionEx
osinfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
if (!GetVersionEx(&osinfo))
{ Error = "Unable to get OS version!\n";
return Error.AllocSysString();
}
// Enumerate the proces list of the system
// "0" means to createsnapshot in context of our process
HANDLE hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if (!hSnapshot)
{ Error = "Unable to create snapshot!";
return Error.AllocSysString();
}
// prepare to enumerate the processes.
PROCESSENTRY32 pe;
ULONG count=0;
// remember to init the structure...
pe.dwSize=sizeof(PROCESSENTRY32);
BOOL retval=Process32First(hSnapshot,&pe);
CString ProcessList = "";
while(retval)
{ // Store process info in a CString
sprintf(StrHnd,L"%s", pe.th32ProcessID);
sprintf(StrPsg,L"%s", pe.th32ParentProcessID);
// Get process name
ProcessList += " " +(CString)pe.szExeFile
// Get Process parent Identifier
+ " " + (CString)StrPsg
// Get process identifier
+ " " + (CString)StrHnd + "*";
// move to next process
retval=Process32Next(hSnapshot,&pe);
}
//close the snapshot handle
CloseHandle(hSnapshot);
return ProcessList.AllocSysString();
}