Last active
August 29, 2015 14:17
-
-
Save mesaleh/1458d222a275ea1d5078 to your computer and use it in GitHub Desktop.
Used in my blog http://moustafasaleh.blogspot.com/2015/03/using-windows-native-apis-with-cl-and.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
http://moustafasaleh.blogspot.com/ (@msaleh83) | |
Example of using ZwDelayExecution Windows internal API by importing ntdll.lib | |
compile: | |
cl ZwDelayExecution2.cpp kernel32.lib ntdll.lib user32.lib | |
gcc ZwDelayExecution2.cpp -o ZwDelayExecution1.exe -lntdll | |
*/ | |
#define UNICODE | |
#define _UNICODE | |
#include <windows.h> | |
#pragma comment(linker,"/entry:main") // for CL | |
extern "C" | |
{ | |
DWORD __stdcall ZwDelayExecution(BOOLEAN, __int64*); | |
} | |
int foo() | |
{ | |
MessageBox(0,L"Before the delay",L"@msaleh83",0); | |
__int64 x = -20000000; // sleep for 2 seconds (100 ns granuality) | |
ZwDelayExecution(FALSE, &x); | |
MessageBox(0,L"After the delay",L"@msaleh83",0); | |
return 0; | |
} | |
int main(int argc, char* argv[]) { | |
foo(); | |
ExitProcess(0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment