Malware Development – A Simple Message Box

Creating Your First Windows App in C++: A Simple Message Box

Code

#include <windows.h>

int WINAPI wWinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    PWSTR lpCmdLine,
    int nCmdShow
) {
    MessageBoxW(
        nullptr,
        L"Hello World",
        L"My Message Box",
        MB_OK | MB_ICONINFORMATION
    );
    return 0;
}

Output

Explication

🧩 1. #include <windows.h>

This is the core Windows header file.

It pulls in the entire Win32 API, which gives you access to thousands of Windows functions such as:

  • MessageBox
  • CreateProcess
  • RegOpenKeyEx
  • CreateFile, and so on.

You must include this header in any Windows desktop (Win32) program.

🧠 2. int WINAPI wWinMain(...)

This is your program’s entry point — the function that Windows calls when your app starts.

It’s like main() in a console program, but for GUI apps.

Let’s break down its parts:

int WINAPI wWinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    PWSTR lpCmdLine,
    int nCmdShow

👉 WINAPI

  • This is a calling convention (__stdcall) used by Windows.
  • It just defines how parameters are passed on the stack — don’t worry much about it yet, but it must match what Windows expects.

👉 HINSTANCE hInstance

  • A handle (pointer-like value) to the current instance of your application.
  • Windows gives this to you; it identifies your program when interacting with the OS.

👉 HINSTANCE hPrevInstance

  • Always NULL on modern Windows.
  • It was used in 16-bit Windows for detecting if another copy of the program was running — now obsolete.

👉 PWSTR lpCmdLine

  • A pointer to the command-line arguments, as a Unicode string (LPWSTR = wchar_t*).
  • Equivalent to argv in console programs, but as a single wide-character string.

👉 int nCmdShow

  • Tells you how the window should appear when first shown (normal, minimized, maximized).
  • You can pass it to ShowWindow() when you create your own window — not used here.

💬 3. MessageBoxW(...)

This is a Win32 API call that displays a simple message box dialog.

MessageBoxW(
    nullptr,
    L"Hello World",
    L"My Message Box",
    MB_OK | MB_ICONINFORMATION
);
ParameterMeaning
nullptrThe parent window handle. nullptr = no parent, standalone box.
L"Hello World"The message shown inside the box. The L means it’s a wide (Unicode) string.
L"My Message Box"The title of the window.
`MB_OKMB_ICONINFORMATION`

💡 You can combine different flags, for example:

  • MB_YESNO | MB_ICONQUESTION
  • MB_OKCANCEL | MB_ICONERROR

🔚 4. return 0;

Returns 0 to Windows — which means “program exited successfully.”

⚙️ Summary Flow

  1. Windows starts your app → calls wWinMain.
  2. Your function calls MessageBoxW, which tells Windows to create and show a dialog box.
  3. When you click “OK,” the function returns.
  4. The program ends and returns 0 to the OS.

That’s the simplest possible Windows GUI program — one API call, one message box.