I am trying to develop a native Windows program so I started from
Pavel Yosifovich's video. I wrote the simple.cpp
program as shown in the video, and set options of Visual Studio as explained (SubSystem:Native, C++ security check and runtime checks disabled), but my program doesn't compile and reports LNK2019
errors.
#include<Windows.h>
#include<winternl.h>
// compiler will handle the import of following prototypes
extern "C" {
NTSTATUS NTAPI NtTerminateProcess(_In_opt_ HANDLE ProcessHandle, NTSTATUS ExitStatus);
NTSTATUS NTAPI NtDelayExecution(_In_ BOOLEAN Alertable, _In_opt_ PLARGE_INTEGER DelayInterval);
NTSTATUS NTAPI NtDrawText(_In_ PUNICODE_STRING Text);
}
#define NtCurrentProcess() ( (HANDLE)(LONG_PTR) -1 )
extern "C" void NTAPI NtProcessStartup(PPEB peb){
// peb is accessed here by default!
UNICODE_STRING text;
// create unicode string
RtlInitUnicodeString(&text, L"Hello from NativeApps!");
// show message in boot
NtDrawText(&text);
LARGE_INTEGER interval;
interval.QuadPart = -10000 * 5000;
NtDelayExecution(FALSE, &interval);
// we must close native programs
NtTerminateProcess(NtCurrentProcess(), 0);
}
If programs compiles correctly, by cpoying it to system32 folder and adding the program name to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\BootExecute
, we expect following out:
I searched some books and Google, but couldn't find any helpful resource for Windows native programming.
Note: Native programs aren't launched as normal C and C++ programs(from main
function). Their entry function is NtProcessStartup