The original text was first published in Baidu Space 2010-02-22.
1, put ntapi.h, ntdll.lib in a directory, and then set the tool---------Project and Solution--vc++ Directory--Include the file, the new directory is set in the file, and then set the library file, the new directory is set in the file.
The settings above are unified to make it easy for new projects to be used later, and if you want to set up individual items, follow these steps:
Put ntapi.h, ntdll.lib in a directory, right-click on the project--property--c/c++--general--Additional include directory--set the directory path just now, in the linker--general--Additional library directory set just the directory path, in the linker--input-- Additional dependency Settings ntdll.lib.
2, the new header file ABC.h, the contents are as follows:
#ifndef abc_h__
#define ABC_H__
#ifndef Cplusplus
extern "C"
#endif
#include "ntapi.h"
#pragma comment (lib, "Ntdll.lib")
#endif//abc_h__
3, put abc.h in and ntapi.h the same directory, so you can call the NT function statically, using the following example:
#include "stdafx.h"
#include "iostream"
#include "windows.h"
#include "abc.h"
int _tmain (int argc, _tchar* argv[])
{
int pid;
std::cout<< "Please input pid:";
std::cin>>pid;
HANDLE kk=openprocess (0X1F0FFF, false,pid);
NTSTATUS nstatus = ntterminateprocess(kk,0);
std::cin>>pid;
return 0;
}
How C + + calls NT functions statically in R3