SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // clang-cl main.cpp -Fe -link user32.lib
  2. #include <windows.h>
  3. #include <iostream>
  4.  
  5. #define _SECOND 10000000
  6.  
  7. VOID CALLBACK LogFunc(LPVOID lpArg, DWORD dwTimerLowValue, DWORD dwTimerHighValue)
  8. {
  9.   // Formal parameters not used in this example.
  10.   UNREFERENCED_PARAMETER(lpArg);
  11.   UNREFERENCED_PARAMETER(dwTimerLowValue);
  12.   UNREFERENCED_PARAMETER(dwTimerHighValue);
  13.  
  14.   std::cout << "hello from LogFunc\n";
  15. }
  16.  
  17. VOID CALLBACK HelloFunc(ULONG_PTR dwParam)
  18. {
  19.   std::cout << "hello from the APCFunc " << dwParam << "\n";
  20. }
  21.  
  22. int main(void)
  23. {
  24.   uint32_t counter = 100;
  25.  
  26.   LARGE_INTEGER liDueTime;
  27.   liDueTime.LowPart = (DWORD)(-5 * _SECOND & 0xFFFFFFFF);
  28.   liDueTime.HighPart = (LONG)(-5 * _SECOND >> 32);
  29.  
  30.   HANDLE hTimer = ::CreateWaitableTimer(NULL, FALSE, NULL);
  31.   ::SetWaitableTimer(hTimer, &liDueTime, 2000, LogFunc, &counter, FALSE);
  32.  
  33.   for (uint16_t i = 0; i < 2; ++i)
  34.   {
  35.     ::QueueUserAPC(HelloFunc, ::GetCurrentThread(), i);
  36.   }
  37.  
  38.   for (; counter < 1000; counter += 100)
  39.   {
  40.     ::SleepEx(INFINITE, TRUE);
  41.   }
  42.  
  43.   ::CloseHandle(hTimer);
  44.  
  45.   return 0;
  46. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top