31 Ocak 2019 Perşembe

MessageBox metodu

Örnek
Şöyle yaparız.
MessageBox(L"Error while readaing the file");

14 Ocak 2019 Pazartesi

CreateToolhelp32Snapshot metodu

Giriş
Process'leri dolaşabilmeyi sağlar.
1. CreateToolhelp32Snapshot() ile handle açılır
2. Process32First() ile okuma yapılır
3. Process32Next() ile döngü içinde okuma yapılır

Örnek
Şöyle yaparız.
DWORD get_process_id_by_process_name(const char* process_name_){
  PROCESSENTRY32 process_entry = { sizeof(PROCESSENTRY32) };
  HANDLE processes_snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

  // loop through all process to find one that matches the process_name_
  if (Process32First(processes_snapshot, &process_entry)){
    do{
      if (strcmp(process_entry.szExeFile, process_name_) == 0){
        CloseHandle(processes_snapshot);
        return process_entry.th32ProcessID;
      }
    } while (Process32Next(processes_snapshot, &process_entry));
  }

  CloseHandle(processes_snapshot);
  return NULL;
}
Örnek
Şöyle yaparız
HANDLE hSnapshot;

PROCESSENTRY32  hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
proc32.dwSize = sizeof(PROCESSENTRY32);

if(Process32First(hSnapshot, &proc32))
{
  cout << proc32.szExeFile << endl;
  while(Process32Next(hSnapshot, &proc32))
     cout << proc32.szExeFile << endl;
}