21 Haziran 2018 Perşembe

RegCreateKeyEx metodu

Giriş
İlk parametre KEY_CURRENT_USER,HKEY_LOCAL_MACHINE olabilir.

Örnek
Şöyle yaparız.
HKEY hKey;
LPCTSTR sk = TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion
\\Image File Execution Options\\notepad.exe"); //notepad.exe is the key I want to create

LONG createResKey = RegCreateKeyEx(HKEY_LOCAL_MACHINE, sk, 0, NULL,
 REG_OPTION_BACKUP_RESTORE, KEY_ALL_ACCESS, NULL, &hKey, NULL);

if (createResKey == ERROR_SUCCESS) {
    qDebug() << "Success creating key.";
}

18 Haziran 2018 Pazartesi

RegFlushKey metodu

Giriş
Açıklaması şöyle. Bu metodu çağırmak pahalı bir işlem.
Calling RegFlushKey is an expensive operation that significantly affects system-wide performance as it consumes disk bandwidth and blocks modifications to all keys by all processes in the registry hive that is being flushed until the flush operation completes. RegFlushKey should only be called explicitly when an application must guarantee that registry changes are persisted to disk immediately after modification. All modifications made to keys are visible to other processes without the need to flush them to disk.
Alternatively, the registry has a 'lazy flush' mechanism that flushes registry modifications to disk at regular intervals of time. In addition to this regular flush operation, registry changes are also flushed to disk at system shutdown. Allowing the 'lazy flush' to flush registry changes is the most efficient way to manage registry writes to the registry store on disk.

4 Haziran 2018 Pazartesi

SetWindowsHookEx metodu

Giriş
Bu metodun tersini UnhookWindowsHookEx yapar.

Örnek - WH_KEYBOARD_LL
Şöyle yaparız.
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
  PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT) lParam;
  ...
  return CallNextHookEx(NULL, nCode, wParam, lParam);
}

HOOKPROC LockerPraq()
{
  HHOOK hook_install = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc,
    NULL, 0);
  if (NULL == hook_install)
    return(0);

  MSG msg;
  while (GetMessage(&msg, NULL, 0, 0))
  {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }

  UnhookWindowsHookEx(hook_install);

  return(0);
}
Örnek
Elimizde şöyle bir kod olsun.
LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
  if (nCode == HC_ACTION)
  {
    auto &ms = * (const MOUSEHOOKSTRUCT *) lParam;
    if (wParam == WM_MOUSEMOVE)
    {
      cout << "X : " << ms.pt.x << " Y: " << ms.pt.y << "\n";
    }
  }
  return CallNextHookEx(hMSHook, nCode, wParam, lParam);
}
Şöyle yaparız.
int _tmain() {
  HMODULE hInstance = GetModuleHandle(NULL);
  hMSHook = SetWindowsHookEx(WH_MOUSE_LL, MouseProc, hInstance, NULL);

  MSG Msg;

  while (GetMessage(&Msg, NULL, 0, 0)) { DispatchMessage(&Msg); }
  ::ReleaseDC(0, dc);

  return 0;
}

GetModuleHandle metodu

Örnek
Şöyle yaparız.
 HMODULE hInstance = GetModuleHandle(NULL);