Intro to C on Windows - Day 1

Intro to C on Windows - Day 1 — Molly Rocket

Molly Rocket

AI-assisted summary of Intro to C on Windows - Day 1 — original source. Check the original for full context.

Source published:

Key ideas

  • Casey Muratori initiates the Handmade Hero project to document the end-to-end development of a complete game written from scratch in C on Windows. (0:02)
  • Setting up native C development on Windows typically requires Microsoft Visual Studio Express or Community to obtain the full MSVC compiler and linker toolchain. (2:23)
  • Windows maintains a strict architectural split between console applications and graphical windowed software, requiring an explicit choice during project setup. (5:00)
  • The compilation pipeline relies on cl.exe to produce intermediate object files and link.exe to resolve external symbols into the final executable. (25:45)
  • Graphical Windows applications use WinMain as their default user entry point, accepting OS handles, command lines, and display parameters defined in windows.h. (35:36)

Detailed notes

## Background Published on YouTube by Molly Rocket on November 13, 2014, this video kicks off the introductory C programming on Windows series for the Handmade Hero project. According to the description, the stream introduces viewers to C on Windows by covering how to acquire a compiler through Visual Studio, set up an empty Win32 project, compile and debug code, and understand the WinMain entry point and basic function calls.

## TL;DR Host Casey Muratori prepares viewers for building a complete game from scratch in C by establishing the core fundamentals of compiling and running native code on Windows. After navigating Visual Studio to configure an empty Win32 project with a blank C++ source file, he demystifies the multi-stage build pipeline, contrasting compiler syntax errors against unresolved linker externals. He then breaks down the WinMain entry point signature, explaining how Windows headers, calling conventions, and legacy Hungarian notation operate under the hood. The stream concludes by defining and invoking a custom function that outputs diagnostic text to the Visual Studio debug pane using OutputDebugString.

## Atmosphere & style The presentation has an unhurried, transparent, and conversational tone, blending meticulous architectural explanations with dry, irreverent humor targeting corporate software bloat and archaic Microsoft conventions. Muratori speaks as an experienced systems programmer who prefers stripping away unnecessary IDE scaffolding to expose raw text and hardware mechanics. Watching the stream feels like an intimate, behind-the-scenes apprenticeship, where technical patience for beginners is balanced with an honest critique of operating system quirks.

## Bulletin - [00:02](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=2s) Casey Muratori initiates the Handmade Hero project to document the end-to-end development of a complete game written from scratch in C on Windows. - [02:23](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=143s) Setting up native C development on Windows typically requires Microsoft Visual Studio Express or Community to obtain the full MSVC compiler and linker toolchain. - [05:00](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=300s) Windows maintains a strict architectural split between console applications and graphical windowed software, requiring an explicit choice during project setup. - [25:45](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=1545s) The compilation pipeline relies on cl.exe to produce intermediate object files and link.exe to resolve external symbols into the final executable. - [35:36](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=2136s) Graphical Windows applications use WinMain as their default user entry point, accepting OS handles, command lines, and display parameters defined in windows.h.

## Key takeaways - [00:02](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=2s) Handmade Hero is designed to create a complete, playable game from scratch in C while streaming and documenting every line of code without external dependencies. - [02:23](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=143s) Unlike Linux environments where toolchain setup is straightforward, Windows development typically relies on Microsoft Visual Studio Express or Community to provide the complete native C/C++ compiler toolchain. - [05:00](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=300s) Windows uniquely enforces an upfront subsystem choice between console-based applications and graphical Win32 projects at creation time. - [07:56](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=476s) Visual Studio organizes source trees using 'solutions' and 'projects', though an empty Win32 project strips unnecessary enterprise scaffolding for custom engine development. - [10:03](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=603s) C and C++ development fundamentally revolves around plain, unadorned text files that compilers parse directly into machine instructions. - [13:57](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=837s) Build configurations like Debug and Release dictate whether the compiler includes diagnostic symbols and asserts or optimizes machine code for performance. - [16:57](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=1017s) Modern compilers utilize multithreading across hardware CPU cores and logical hyper-threads to compile independent source files concurrently. - [25:45](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=1545s) The build pipeline separates compilation of source files into intermediate object (.obj) files from the final linking phase that stitches them into an executable (.exe). - [30:58](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=1858s) Linker errors like unresolved external symbols occur when required function signatures lack an actual definition across compiled units or libraries. - [32:18](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=1938s) The Windows OS loader reads binary executable headers to locate the entry point address written by the linker before transferring control to the application. - [35:36](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=2136s) WinMain serves as the standard entry point for graphical Win32 applications, requiring four specific parameters passed by the operating system. - [41:25](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=2485s) Hungarian notation prefixes like 'H' for handles and 'LP' for long pointers are legacy 16-bit Windows conventions that harm modern code readability. - [44:43](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=2683s) Directional SAL annotations from MSDN documentation (such as _In_ and _Out_) should be removed from source implementations to avoid compiler confusion. - [46:18](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=2778s) Calling OutputDebugString sends text directly from the application process to the development environment's debug output pane. - [50:23](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=3023s) C functions require matching declarations and definitions, enforcing return types, parameter contracts, and statement semicolons. - [57:24](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=3444s) The CALLBACK macro specifies a low-level binary calling convention ensuring the OS and application agree on stack and register management. - [59:24](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=3564s) Graphical applications still receive shell execution arguments through lpCmdLine, passed via shortcut properties or command-line launches. - [01:04:05](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=3845s) Missing identifier errors halt the compiler immediately, whereas forward declarations allow compilation to proceed until the linker checks for definitions. - [01:07:30](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=4050s) The preprocessor directive #include <windows.h> literally injects a massive cascade of operating system declarations and types into the compilation translation unit.

## Detailed walkthrough ### [00:02](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=2s) Project Announcement and Stream Objectives

Casey Muratori introduces the stream as a preparatory run before starting an ambitious programming project on Monday: coding a complete game from scratch in C. He acknowledges that tackling an entire game live on stream might seem ill-advised, but he has decided to commit to it. His goal is to produce an end-to-end, live-recorded documentation of every single step required to build a playable game from the ground up, whether anyone tunes in early on or only notices once the project is well underway.

Before launching into the main project, he wants to test the streaming infrastructure to uncover any computer reliability quirks beforehand. He uses these preliminary streams productively by teaching basic C programming on a PC. As Muratori explains, “If anyone wants to follow along as I program the game in C and go through all the explanations of why I'm writing the game code that way, I won't be wanting to stop and explain little things like what is the question mark operator or how does the stack work or something like that unless that's exactly relevant topic at the time.” These introductory videos will be archived as a primer for absolute beginners so they can build enough familiarity to follow the game's development.

[02:23](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=143s) Finding a C Compiler on Windows

To start programming in C on a modern PC, a developer needs a C compiler. On Linux, setting up a toolchain is straightforward, but Windows presents an annoying barrier because standalone command-line tooling like LLVM cannot handle the complete build process on Windows out of the box. Consequently, beginners must obtain Microsoft Visual Studio Express (or Visual Studio Community), which provides Microsoft's professional C/C++ compilation environment for free.

Muratori navigates Microsoft’s download portal, pointing out the bloated ecosystem of distractions presented to users:

```mermaid flowchart TD accTitle: Microsoft Visual Studio Offerings accDescr: Diagram illustrating the unwanted software options versus the required Visual Studio version for C/C++ development.

subgraph Unwanted["Unwanted Offerings"] TFS["Team Foundation Server"] WEB["Express for Web (ASP.NET)"] end

subgraph Target["Selected Package"] VS["Express 2013 for Windows Desktop / Community"] end

DOWNLOAD["Microsoft Download Page"] --> TFS DOWNLOAD --> WEB DOWNLOAD --> VS VS --> CPP["C/C++ Compiler & IDE"] ```

He mocks tools like Team Foundation Server, observing, “Since you're just someone who's trying to program C at home, you probably don't have a team, or if you do, they probably don't have a foundation, or don't want their foundation to be comprised primarily of something from Microsoft anyway.” He directs viewers specifically toward Express for Windows Desktop (or Community) rather than Express for Web, which is aimed at ASP.NET development. Downloading the software requires navigating a Microsoft account login, identity provider screens, and system reboots.

- **Recommended Tool:** Microsoft Visual Studio Express 2013 for Windows Desktop (or the later Visual Studio Community edition). - **Target Language Support:** Provides the necessary MSVC toolchain to compile native C and C++ code. - **Prerequisites:** Requires a Microsoft account login and usually a full PC reboot post-installation.

[05:00](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=300s) Creating a Win32 Project in Visual Studio

Because restarting his machine would interrupt the live broadcast, Muratori demonstrates the environment using Visual Studio 2008, which is already installed on his system. He notes that the interface will show recent files from his day job—mentioning he cannot open any proprietary files from *The Witness*—before creating a fresh project by selecting **File > New > Project**.

The project creation dialog displays an overwhelming array of templates, including.NET components and legacy MFC (Microsoft Foundation Classes) libraries. For raw C/C++ development, only two options matter: a **Win32 Console Application** and a **Win32 Project**. Muratori highlights an architectural quirk dating back to the earliest versions of Windows: the operating system strictly segregates console-driven programs from standard graphical windowed applications. Unlike macOS or Linux, where a single executable can interact seamlessly with terminal standard streams and window managers, Windows forces a developer to pick one subsystem up front. Because game development revolves around windows and graphical rendering, he selects **Win32 Project**. In the application wizard that follows, he checks the **Empty project** checkbox to discard pre-generated scaffolding, leaving a clean workspace with no unwanted boilerplate.

[07:56](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=476s) The Solution Explorer and Adding a Source File

Inside Visual Studio, the primary view for managing code is the **Solution Explorer**, which can be toggled via **View > Solution Explorer** if accidentally closed. Muratori critiques Microsoft's terminology, noting that what every programmer naturally considers a project directory or file manager is instead called a "solution":

> “Solution was just something that they started calling a project at some point, and so really a solution is just their word for a thing that you are going to build—it's like a basically a list of things that need to get built and how they're going to build them and so instead of having an intuitive name like Files Explorer, Project Explorer, it's called Solution Explorer.”

The Solution Explorer displays a hierarchical tree of virtual folders and filters. Rather than relying on Microsoft's default organizational filters, developers can create, delete, or rename them as desired. To begin writing real code, the compiler needs a concrete source file. Muratori ignores the dozens of specialized file options in the **Add New Item** dialog (such as SQL scripts or class diagrams) and creates a plain C++ source file (`test.cpp`). This opens a blank text buffer ready for writing C code.

[10:03](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=603s) C and C++ as Raw Text Files

Casey Muratori points out that while computing hardware has leaped forward, the foundational workflow of C programming has remained remarkably static. C++ emerged in the early 1980s, and C traces its lineage a full decade earlier, yet the core interaction model is unchanged: developers edit plain, unadorned text files. Unlike a rich document created in Microsoft Word, a source code file carries no hidden styling, annotations, or metadata—it is simply raw text that will eventually be interpreted and translated by development tools.

To illustrate how the Visual Studio editor tracks edits, Casey types arbitrary text into the newly created file. A yellow vertical bar immediately appears along the left margin next to the modified lines, indicating uncommitted changes made since the file was opened. An asterisk also attaches to the file name on the document tab, signaling an unsaved state. Once he saves the file—either via the menu or by pressing `Ctrl+S`—the asterisk disappears, and the indicator bar flips to green, meaning those modifications are now preserved on disk.

Casey summarizes the fundamental nature of the craft: > “Basically just understand that nothing we're going to do is going to be anything other than entering text into a computer.”

- **C & C++ lineage:** C++ originated in the early 1980s; C originated roughly a decade before that. - **Visual Studio editor margin indicators:** - *Yellow bar:* Modified line not yet saved to disk. - *Green bar:* Modified line saved to disk since the session began. - *Asterisk (`*`) on tab:* Active file has unsaved changes.

---

[12:14](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=734s) Building the Solution and the Output Window

When it is time to turn source text into a functioning program, the user invokes the **Build Solution** command. If the Output window is not already visible, Visual Studio pops it open automatically to stream the results of the build process. The log begins by declaring the target: `Build started: Project: test`. Casey explains that the solution container (`test`) holds an active default project (also named `test`), displayed in bold text in the Solution Explorer.

```mermaid flowchart TD accTitle: Solution and Project Hierarchy accDescr: Visual Studio organizes source files inside projects, which reside within a solution.

subgraph SolutionScope["Solution: test"] subgraph ProjectScope["Default Startup Project: test (bold)"] File1["test.cpp (Raw text source)"] end end ```

Casey highlights that Visual Studio permits stacking multiple projects within a single solution, with settings like *Set as StartUp Project* dictating execution order. While enterprise applications often rely on complex multi-project structures, he dismisses that overhead for indie game development, noting: > “Most of that is not really necessary when you're doing development unless you start developing a very large and complex project, but if you're just building a game by yourself it's not like you'll need to ever do anything like that.”

He mentions that as the series progresses, he will show how to build projects directly without leaning on Visual Studio’s heavy project management UI.

---

[13:57](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=837s) Build Configurations and the Meaning of Compilation

The build log reports a configuration line specifying `Debug Win32`. Casey explains that a build configuration instructs the toolchain on how to process the source code and what environment to target. A developer might produce a 32-bit (`Win32`) binary or a 64-bit (`x64`) binary, depending on the targeted operating system. Furthermore, configurations govern internal build settings: a `Debug` build incorporates extra diagnostic code, asserts, and internal developer tools or game editors, whereas a `Release` (or `Retail`) build strips out diagnostics and applies optimizations for end-user distribution.

The next phase listed in the log is compilation. While people casually toss around the term "compilation," Casey clarifies that it fundamentally means translating data from one format into another. In software, a compiler parses human-readable text, interprets its semantic intent, and converts it into native instructions—such as x86 or x64 machine code—that a real CPU can execute directly rather than dealing with abstract high-level notions. The compiler processes the project's single source file, `test.cpp`, as the first major stage of producing a standalone `.exe` executable.

Casey defines the compiler's primary job: > “The compilation step is basically in charge of doing the majority of the work to translate our text file from something humans read into something that a CPU can read.”

---

[16:57](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=1017s) Hardware Concurrency: CPUs, Cores, and Hyper-Threading

Observing the build output, Casey notes a small number prefix followed by a greater-than symbol (e.g., `1>`) alongside each log entry. While largely irrelevant to day-to-day coding, it represents the worker thread processing the file. To illustrate why modern compilers parallelize work this way, Casey presses `Ctrl+Shift+Esc` to open Windows Task Manager and points to the CPU Usage History graphs, showing a large grid of activity monitors.

```mermaid flowchart TD accTitle: CPU Hierarchy from Physical Socket to Hyper-Thread accDescr: Diagram showing how a physical CPU socket breaks down into cores and logical hyper-threads.

subgraph Socket["Physical CPU (Silicon Chip & Heatsink)"] subgraph Core0["Core 0"] T0["Logical Processor / Hyper-thread 0"] T1["Logical Processor / Hyper-thread 1"] end subgraph Core1["Core 1"] T2["Logical Processor / Hyper-thread 2"] T3["Logical Processor / Hyper-thread 3"] end subgraph CoreN["Core N..."] TN["Additional Hyper-threads..."] end end ```

He takes a detour into modern processor architecture to define what those graphs actually represent:

1. **Physical Processors:** The physical silicon chips seated in motherboard sockets beneath heatsinks. Most desktop consumers have a single physical CPU, whereas enterprise servers may hold two, four, or dozens of separate physical processors. 2. **Cores:** Individual execution engines fabricated inside a single physical CPU chip. A modern chip commonly integrates four, eight, or more cores. Each core acts like a self-contained legacy CPU, equipped with its own arithmetic logic units, registers, and pathways to communicate across the system bus and memory. 3. **Hyper-Threads (Logical Processors):** An architectural design where a single physical core duplicates architectural state to present itself to the operating system as multiple logical execution units. Even though the underlying core execution hardware runs instructions from one stream at any given slice of time, it maintains the context of multiple threads concurrently to eliminate switching latencies.

Casey reflects on the utility of Task Manager's shortcut: > “If I basically just use the hotkey—one of my favorite hotkeys, Control+Shift+Escape to bring up the Task Manager—you will notice that this machine has a lot of processors.”

[20:39](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=1239s) CPU Cores, Hyper-Threading, and Compiler Parallelism

A physical CPU core is responsible for actively executing an application's instructions, but modern processor architectures often maintain multiple execution states on a single core. Similar to how an operating system taskbar switches among multiple running tasks, a physical core can hold distinct hardware thread states. Although it executes instructions from only one thread at any given instant, it can rapidly switch between preserved states. The operating system surfaces these hardware threads as individual logical processors. Looking at the Task Manager on his development machine, Casey Muratori inspects the hardware topology, observing that it contains dual Intel Xeon processors (identifying them as Xeon W5580 CPUs) with several logical units per socket, showing real-time utilization graphs for each thread.

Compilers take advantage of these multi-core and multi-threaded setups to accelerate build times. Because processing large codebases can be noticeably slow, modern compilers routinely spawn multiple worker threads to compile source files across several logical execution units simultaneously. Casey highlights a small sequence indicator printed in the build window, noting that it reflects the compilation worker or job instance responsible for printing that specific build message. Because this initial test project contains only a single source file, the build system invokes only one worker thread instead of launching an entire parallel build across all available logical cores.

[24:18](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=1458s) Compiler Errors and Build Logs

Attempting to compile the project with initial placeholder text immediately triggers a compilation error. Casey explains that a compiler error fundamentally means the compiler tried to read the provided text file according to the grammar of the programming language, but “it did not like what it found.” Double-clicking the error notification in the IDE navigates directly to the offending line of code where the parser stalled out. Once the compiler encounters fatal issues or exceeds an internal error threshold, it aborts the process, reporting zero succeeded files, one failed file, and zero skipped files.

Visual Studio also writes an HTML build log to disk detailing the full output of the build run. While Casey notes that these logs can serve administrative or automated remote build tracking workflows, he dismisses them for day-to-day interactive debugging:

> “It also saves a build log for you, which are pretty useless most of the time...”

[25:45](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=1545s) The Resource Compiler and the Linking Stage

To advance past basic syntax errors, Casey types the minimal valid C++ code necessary for the compiler to process the file cleanly. Upon rebuilding, the compiler processes `test.cpp` without complaints and transitions into the next build phases. The build pipeline invokes the Microsoft Resource Compiler (`rc.exe`) because the default project template created a `.rc` resource file. Casey clarifies that despite its grand name, a resource compiler is not meant to package complex game assets, but rather to bundle OS-level shell metadata—such as embedding the application icon into the final executable so that Windows Explorer can display it.

```mermaid flowchart TD accTitle: C and C++ Build Pipeline Stages accDescr: Flowchart illustrating how source and resource files are processed by compilers into intermediate files, then combined by the linker into an executable.

subgraph Inputs["Source Inputs"] CPP["test.cpp"] RC["Project.rc"] end

subgraph Compilers["Compilation Stage"] CL["C/C++ Compiler (cl.exe)"] RCC["Resource Compiler (rc.exe)"] end

subgraph Intermediate["Intermediate Artifacts"] OBJ["test.obj"] RES["Project.res"] end

subgraph FinalStage["Linking Stage"] LINK["Linker (link.exe)"] EXE["Target Executable (.exe)"] end

CPP --> CL RC --> RCC CL --> OBJ RCC --> RES OBJ --> LINK RES --> LINK LINK --> EXE ```

Once the resource compiler finishes, the build system enters the linking stage (`link.exe`), which Casey breaks down in detail:

- **Intermediate Object Generation**: Rather than translating text files directly into an executable, the compiler compiles each separate source file into an intermediate object file containing mostly raw machine code alongside unresolved cross-file symbols. - **Incremental Builds**: Intermediate files only need rebuilding when their specific underlying source file changes; unchanged files (such as a hypothetical `foo.cpp` or `bar.cpp`) are skipped to reduce compilation times. - **Symbol Resolution**: Because the compiler only examines one source file at a time, it cannot resolve symbols, function calls, or shared data structures defined in external translation units. - **Linker Aggregation**: The linker collects all intermediate object files and compiled resources, matches external references across files, and packages everything into an executable `.exe` binary. - **Opaque Linker Errors**: Unlike the compiler, which pinpoints the exact line number of a syntax error, the Visual Studio linker produces notoriously cryptic messages that list only the unresolved symbol and the enclosing function where the reference occurred.

While discussing the shipping of finished binaries, Casey reflects on the historical simplicity of software distribution:

> “Now when I say which you can then ship, that was the good old days; there's a lot of reasons why you can't actually just do that, thanks to Microsoft and their tireless pursuit of making building applications complicated...”

[30:58](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=1858s) Understanding Linker Errors and Unresolved Externals

Looking at the build output in Visual Studio, Casey Muratori points out the error message: `unresolved external symbol _WinMain@16 referenced in function __tmainCRTStartup`. The compiler marks this as a fatal error, reporting that one unresolved external was encountered. Casey explains that an external symbol is simply an identifier that is external to the translation unit where it is being referenced. When `test.cpp` compiles, it produces an object file. If the linker examines the references inside that object file and cannot find an actual implementation or definition in any other compiled unit or library, it cannot complete the link.

```mermaid flowchart TD accTitle: Linker failure on missing WinMain accDescr: Shows the compilation unit producing an object file with an unresolved external symbol, which causes the linker to fail. subgraph Compilation["Compilation Unit"] A["test.cpp"] -->|"Compile"| B["test.obj"] end subgraph Linking["Linker Resolution"] B -->|"Requires WinMain"| C{"Search Libraries & Units"} C -->|"Not found"| D["Error: LNK2019 Unresolved External _WinMain@16"] end ```

The linker output indicates two errors, though it fundamentally stems from a single failure to resolve `WinMain`. Linker errors are usually straightforward to decipher because they indicate specifically which symbol is missing. Because the linker cannot determine where the execution should begin or what function to invoke, the build halts.

- The error message specifically targets `_WinMain@16`, referenced by the C runtime startup code `__tmainCRTStartup`. - An "external" refers to any symbol declared or required outside the immediate compilation unit. - Visual Studio reports two errors for this failure, but the secondary error is just an artifact of the primary unresolved symbol.

[32:18](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=1938s) How Windows Loads and Executes Programs

When an executable runs, the operating system and the user program interact through a structured handoff. The computer's processor is executing Windows itself, and Windows must be told how to begin running the new code. The user's code and Windows were never compiled or linked together into a single monolithic binary. Casey points out that the linking process in any application is never truly complete unless one is writing the entire operating system kernel:

> “The linking process, even though it seems like we're going to finish it here in a minute, is never actually really finished in an executable, unless what you're building is the whole operating system.”

Even if someone were building a kernel from scratch, the hardware BIOS must still know how to locate, load, and jump into the kernel code on disk.

Under an operating system like Windows, an executable file (an `.exe`) is a specific binary format on disk, structured much like a bitmap or any other structured asset. The OS loader opens the file, reads its metadata headers, loads the relevant segments into memory, performs relocations and setup work, and determines the precise memory address where execution should begin. The entry point address written into that executable header is placed there by the linker. By default, the linker searches the object files for a standard, predefined symbol name to use as that entry point. While linker settings can be reconfigured to designate an arbitrary entry point name, standard Windows development relies on the default entry function.

[35:36](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=2136s) WinMain, MSDN Documentation, and Visual Studio Build Settings

Casey introduces `WinMain` as the standard entry point function for graphical Windows applications. Rather than memorizing every API detail, Casey stresses the habit of consulting the official documentation on Microsoft Developer Network (MSDN), which is the primary reference manual for platform-specific C programming on Windows:

> “I always am looking things up on MSDN, which if you type WinMain into your Google search box, you will get the first hit as this site called msdn.microsoft.com, which we are going to be using a lot as we learn to program C in Windows.”

On the MSDN reference page, the documentation presents a formal function prototype showing how `WinMain` must be declared and the parameters it expects when the operating system launches the process. Casey reassures beginners that feeling overwhelmed by Windows terminology is completely normal. The series will deliberately revisit and unpack complex topics rather than rushing past them.

Casey copies the prototype into `test.cpp` and triggers a build using the keyboard shortcut `F7`. During this step, Casey notes that Visual Studio automatically saves unsaved dirty buffers (indicated by lines transitioning from yellow to green in the editor margin) before building. This behavior is managed under **Tools → Options → Projects and Solutions → Build and Run**, where the option "Before building: Save all changes" is enabled by default.

[39:17](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=2357s) Win32 Types and the Low-Level C Approach

Attempting to compile the raw `WinMain` prototype immediately causes the compiler to output several errors because the specialized Windows types are not recognized by plain C++. To make these definitions available, the source code must include the core Windows header (`windows.h`).

The `WinMain` signature relies heavily on Windows-specific type definitions such as `HINSTANCE`, `LPSTR`, and `int`:

```mermaid flowchart LR accTitle: WinMain entry point parameters accDescr: Displays the standard WinMain parameters expected by the Windows operating system loader. subgraph WinMainSignature["WinMain Parameters"] A["HINSTANCE hInstance"] B["HINSTANCE hPrevInstance"] C["LPSTR lpCmdLine"] D["int nShowCmd"] end WinMainSignature -->|"Entry Point"| E["Process Execution"] ```

Casey highlights that high-level programming languages (such as C#) hide and abstract away these underlying operating system details, whereas writing low-level C requires interacting with them directly:

> “Even an experienced C programmer who's never programmed in Windows before would not know what LPSTR meant, so it is not the fact that I haven't explained what this definition is or how any of this stuff in this file works that is why you don't understand it if you're a beginner.”

- `WinMain` takes four parameters: an instance handle `hInstance`, a legacy instance handle `hPrevInstance`, a command-line pointer `lpCmdLine`, and a display flag `nShowCmd`. - Strange Win32 type monikers such as `LPSTR` ("Long Pointer to String") stem from legacy Windows architectural conventions rather than standard C syntax. - Bypassing heavy frameworks and wrappers to interact directly with the Win32 API gives developers complete control over how their software communicates with the operating system.

[41:25](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=2485s) Hungarian Notation and Windows Type Prefixes

The parameters of `WinMain` look like total gobbledygook to anyone who hasn't previously written Windows software, because they are entirely made-up identifiers invented by Microsoft to refer to specific operating system concepts. While terms like `Instance` (an instance of a running program), `PrevInstance` (previous instance), `CmdLine` (command line), and `Str` (a string of characters) are recognizable, the cryptic prefixes like `H` and `LP` are deeply confusing. Casey Muratori explains that these prefixes are artifacts of Hungarian notation, an antiquated convention named after its creator—believed to be Charles Simonyi—who was Hungarian. The concept behind Hungarian notation was that every variable or type name should be prefixed with characters indicating its underlying type or purpose.

In this scheme, `P` stood for pointer, and `L` meant "long"—a leftover from the old 16-bit Windows days referring to a far pointer pointing to memory outside a program's default data segment. The prefix `H` designates a "handle," an opaque reference used to identify operating system resources when communicating with Windows. Muratori expresses strong distaste for the practice: “Cannot emphasize enough please don't do this is a terrible idea.” While modern programmers might still see mild variations, such as prefixing member variables with `m_` in object-oriented programming or using `p` for pointers, the strict system of prefixes merely harms readability. Knowing the history helps in deciphering archaic Windows APIs, but it is not a convention developers should adopt in their own code.

- `HINSTANCE` / `hInstance`: Handle to an instance of a running program. - `hPrevInstance`: Handle to a previous instance (vestigial from 16-bit cooperative multitasking). - `LPSTR` / `lpCmdLine`: Long Pointer to a String containing the command line. - Charles Simonyi is credited with introducing Hungarian notation at Microsoft.

---

[44:43](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=2683s) MSDN Annotations and Sal Macros (`_In_`, `_In_opt_`)

Beyond Hungarian notation, code copied directly from Microsoft documentation often features annotations such as `_In_`, `_In_opt_`, or `_Out_`. These annotations are not standard C code designed for compilation; rather, they serve documentation systems and tools like the MIDL (Microsoft Interface Definition Language) compiler, which generates files for COM, OLE (Object Linking and Embedding), and other Windows subsystems. These directional annotations indicate whether a parameter passes data into the operating system (`_In_`) or returns data back out to the caller (`_Out_`).

Because these annotations belong in header files or documentation rather than in user function definitions, Muratori strips them out of the `WinMain` parameter list. Leaving them in source definitions can cause compilation issues. Once the directional macros are removed, the source code compiles cleanly, producing a functional executable.

```mermaid flowchart LR accTitle: WinMain Parameter Flow Annotations accDescr: Diagram showing how _In_ and _Out_ annotations indicate data flow direction between the application and Windows. subgraph App["Application Code"] direction TB Caller["Caller / WinMain"] end subgraph OS["Windows Subsystem"] direction TB API["OS API / Runtime"] end

Caller -->|"_In_ (data sent to OS)"| API API -->|"_Out_ (data returned to caller)"| Caller ```

---

[46:18](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=2778s) Running the Executable and Debug Output with `OutputDebugString`

With a clean build, the executable can be run directly from Visual Studio via the `Debug -> Start Debugging` menu. Running the program at this stage appears to do nothing visible because it lacks any windowing or execution logic; the operating system simply loads the process, loads dependent modules, and immediately terminates it upon returning from `WinMain`. The debugger's output pane confirms this sequence, displaying internal startup and DLL loading messages.

```c OutputDebugString("This is a test\n"); ```

To make the program do something tangible, Muratori inserts a call to `OutputDebugString`. Re-running the application confirms that the custom text string prints directly to the Visual Studio debug output window. Muratori jokes about the milestone: “If you can print something out of the debug window, how much more work could it even be to make a game?” Although rendering a complete game requires far more effort, getting an application to compile, execute, and communicate through the debugger marks the foundational first step of Windows development.

---

[48:26](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=2906s) Function Definitions and Function Calls in C

Having established a working entry point, Muratori breaks down the fundamental mechanics of a function definition in C. A function is a reusable unit of execution that bundles statements together so they can be executed from anywhere in a program without duplicating logic. “Basically what a function is is it's something, it's sort of a reusable piece of our program,” Muratori notes. “It's very very difficult if you were to sit down and write the entire program in one function, that would be really really difficult to do.”

To demonstrate function flow, he creates a function named `foo` and moves the `OutputDebugString` line inside it:

```c void foo(void) { OutputDebugString("This is a test\n"); } ```

When running the program with the code simply sitting inside `foo`, nothing prints to the debug window because the function has only been defined, not invoked. Adding an explicit call—`foo();`—inside `WinMain` causes the execution flow to jump into `foo`, execute `OutputDebugString`, and return, restoring the debug message in the output pane.

---

[50:23](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=3023s) Anatomy of a C Function: Return Types and Parameters (`void`)

Every function declaration in C specifies how it interfaces with the caller through its return type and its argument list. The declaration begins with the return type, placed immediately before the function name, which defines what value the function sends back upon completion. In the case of `void foo(void)`, the first `void` keyword signifies that the function returns nothing to the caller: “The `void` in front of `foo` just says this function produces no value for its caller, it does not actually return anything to the person who called it.”

The second `void`, enclosed within the parentheses following the function name, governs the parameter list. It dictates what inputs the function expects from the caller to perform its work. Specifying `void` inside the argument parentheses indicates that the function takes no arguments whatsoever. Because `OutputDebugString` within `foo` simply writes a hardcoded string literal, `foo` requires no input parameters to do its job. Visual Studio also provides editor UI features, such as plus and minus collapse toggles, allowing developers to visually fold function bodies when navigating large source files.

[52:13](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=3133s) Function Prototypes, Bodies, and Comment Syntax

Every function in C is structured into two primary components: the function prototype (or signature) and the function body. The prototype defines the interface and calling circumstances of the function, declaring what arguments it accepts and what kind of value it returns to its caller. Directly following the prototype is the function body, enclosed in curly braces (`{ }`), which contains the actual code executed whenever the function is invoked. Before delving deeper into the code within the body, Casey notes the presence of comments. Comments allow a programmer to leave notes to themselves that have nothing to do with compiled machine code, providing insight into thought processes without affecting execution.

C and C++ offer two distinct styles of comments. The first style, inherited from classic C and reminiscent of HTML comment blocks, uses slash-star syntax (`/*... */`). The compiler treats everything following `/*` as an ignored comment until it encounters the matching `*/`, allowing notes to span across multiple lines. The second style (`//`), introduced in C++, instructs the compiler to ignore everything from the double slashes up to the literal end of the line. As Casey observes regarding the end-of-line style: “And that's just a sweet way to cut down on some typing, it means you didn't have to type one of these at the end.” While not fundamentally changing what you can express, single-line comments offer a quick convenience when writing notes.

- `/*... */`: Traditional multi-line block comment that ignores all enclosed text across lines until closed. - `//`: C++ single-line comment that ignores all characters from the slashes to the end of the text line. - Prototype: Specifies the name, parameter list, and return type of a function. - Body: The code enclosed within curly braces `{}` that runs sequentially upon invocation.

[53:44](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=3224s) Invoking Functions and String Literals

Inside the custom function’s body, execution is straightforward because it simply delegates to another function called `OutputDebugStringA`. Calling a function follows a syntax mirror to its prototype: the name of the function followed by parentheses containing the arguments being passed. While the custom function takes no parameters (marked as `void`), `OutputDebugStringA` expects a string. In C, a basic string literal is created simply by enclosing text inside double quotation marks (`"..."`), which packages the enclosed characters together and passes them to the target function to be displayed in the development environment's debug output window.

`OutputDebugStringA` acts as an operating system service provided by Windows, relaying diagnostic text straight to the debugger's output panel. While Casey notes that deep-dive Windows debugging internals will be deferred until the fundamentals of C are firmly established, this call demonstrates the simplest mechanism for getting feedback out of a running Win32 application.

```mermaid flowchart TD accTitle: Function Call Flow to OutputDebugStringA accDescr: Diagram showing a custom function passing a string literal to the Windows OutputDebugStringA API. subgraph CustomFunction["Custom Function Body"] A["Caller Invokes Function"] --> B["Evaluate string: '...'"] B --> C["Call OutputDebugStringA(...)"] end subgraph Win32["Windows OS Subsystem"] C --> D["Output to Debugger Window"] end ```

[55:30](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=3330s) Semicolons, Statements, and Whitespace Rules

Every logical line of executable code in C ends with a semicolon (`;`), creating what the language defines as a statement. Casey remarks on the syntactic necessity of the semicolon with some skepticism about its actual utility in modern language design, noting: “It is a relatively useless piece of syntax.” While languages like Python derive meaning from line endings and indentation, C and C++ largely treat line breaks and whitespace as interchangeable formatting tools intended solely for human readability. A single logical statement can span multiple physical lines of text, or multiple statements can sit on one line, provided each ends with a semicolon.

The only scenario where whitespace alters compiler behavior is when it breaks apart an identifier or token. Indenting code inside braces helps the programmer visualize nesting, but the compiler ignores those spaces entirely. However, inserting whitespace into the middle of a token—such as writing `output debug string a` instead of `OutputDebugStringA`—forces the compiler to see separate unfamiliar names, immediately triggering a compilation error because it can no longer resolve what the symbol means.

- **Statement Terminator**: The semicolon tells the compiler that a logical instruction has concluded. - **Whitespace Agnosticism**: Spaces, tabs, and newlines do not alter program logic outside of string literals. - **Token Integrity**: Whitespace must never split identifiers, keywords, or composite operators.

[57:24](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=3444s) Decoding the WinMain Signature and Calling Conventions

Moving from the simple custom function down to the entry point invoked by the operating system reveals a much more decorated signature: `int CALLBACK WinMain(...)`. The very first keyword, `int`, establishes the return type, indicating that upon exiting, the function will return a signed integer—a whole number such as `-5` or `12`—back to the operating system caller. The second token, `CALLBACK`, is not a native C language keyword but a preprocessor macro defined within `windows.h`. It expands to specialized compiler decorations governing calling conventions.

Because Windows system binaries and user applications are compiled separately by different tools at different times, both sides must agree on low-level binary protocols—such as how arguments are placed on the stack or in registers, and who is responsible for cleaning up the stack frame upon return. The `CALLBACK` macro provides this contract. As Casey emphasizes: “It is a function that must adhere to a special convention because since Windows was not compiled as part of our program and our program is not compiled as part of Windows, they will have to agree on how functions are called.”

```mermaid flowchart LR accTitle: Anatomy of the WinMain Declaration accDescr: Breakdown of the components of the WinMain function signature including return type, calling convention macro, function name, and parameter list. subgraph WinMainSignature["WinMain Signature Anatomy"] RT["int\n(Return Type)"] CC["CALLBACK\n(Calling Convention Macro)"] FN["WinMain\n(Entry Point Name)"] PL["(HINSTANCE, HINSTANCE, LPSTR, int)\n(Parameter List)"] RT --- CC --- FN --- PL end ```

[59:24](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=3564s) WinMain Parameters: Instances and Command Lines

The parameter list for `WinMain` supplies four inputs passed directly from the operating system when the program boots up. The first parameter, `hInstance`, represents a handle to the application instance itself. This handle acts as a token identifying the program’s executable image loaded into memory, which can be passed back to Windows APIs when requesting process-specific resources or debugging services. Casey points out that modern Win32 development rarely needs to track `hInstance` manually since it can be queried dynamically. The second parameter, `hPrevInstance`, is a pure artifact of legacy 16-bit Windows multitasking architecture: “`hPrevInstance` you can completely ignore, it's a legacy thing; you will never need it in game programming.”

The third parameter, `lpCmdLine`, passes the execution arguments as a string. Even though the project is configured as a non-console Win32 graphical application rather than a console tool, it still receives command line text. To illustrate, Casey opens the Windows Command Prompt (`cmd.exe`) via Accessories to demonstrate launching applications like Notepad with extra string arguments. He explains that even regular desktop shortcuts and graphical shell launches pass target parameters through this mechanism, meaning graphical games and utilities still rely on `lpCmdLine` to read startup options, file paths, and launch flags.

- `HINSTANCE hInstance`: Base memory address handle representing the running executable instance within the OS. - `HINSTANCE hPrevInstance`: Obsolete 16-bit Windows holdover that is always passed as `NULL` in 32-bit and 64-bit Windows. - `LPSTR lpCmdLine`: A pointer to a character string containing any command-line arguments provided when launching the executable. - Command Line Accessibility: GUI programs receive command-line strings just like console programs, often supplied via shell shortcuts or launcher configurations.

[01:02:17](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=3737s) WinMain Startup Parameters: lpCmdLine and nCmdShow

The parameters provided to the `WinMain` entry point correspond to how an application is launched within the Windows shell. Even when software is not run directly from a console, shortcuts in Windows have a "Target" property that allows command-line parameters to be appended after the executable path. Consequently, software that an end user would never run from an actual shell command line can still receive and process command-line arguments via the `lpCmdLine` string.

```mermaid flowchart TD accTitle: WinMain Startup Parameters accDescr: Diagram showing how OS shortcut properties map to WinMain parameters. subgraph ShortcutProperties["Windows Shortcut / OS Shell"] TargetField["Target: app.exe [args]"] RunState["Run State: Normal / Min / Max"] end subgraph WinMainArgs["WinMain Parameters"] CmdLine["lpCmdLine (Command line string)"] CmdShow["nCmdShow (Integer window state flag)"] end TargetField --> CmdLine RunState --> CmdShow ```

The final parameter, `nCmdShow`, represents how the window should initially display. Shortcut properties retain legacy options to specify whether an application launches minimized, maximized, or in a normal window state. Windows translates these configurations into an integer value passed directly into `nCmdShow`. While these parameters will be explored in greater detail later, they are fed into `WinMain` alongside the instance handles, leading directly into the execution of the main function body.

- The "Target" line in Windows shortcut properties passes trailing arguments directly to `lpCmdLine`. - `nCmdShow` provides an integer code representing window display states such as normal, minimized, or maximized.

[01:04:05](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=3845s) Compiler Errors vs. Linker Errors and Forward Declarations

Calling a function that has been deleted or omitted produces a compilation error rather than a linker error. In C and C++, the compiler enforces strict ordering: “One of the reasons that that happens is because C and C++ are languages in which you are never allowed to use something which has not been defined yet.” While older C rules were somewhat looser, modern C++ strictly forbids referencing an unknown identifier. Without a prior declaration or definition, compilation halts with an identifier not found error before the linking phase is ever reached.

```mermaid flowchart LR accTitle: Compilation vs Linker Error Resolution accDescr: Contrasting full function definition, forward declaration to linker, and missing identifiers. subgraph CompilationPhase["Compilation Step"] Unknown["No Declaration"] -->|"Compile Error"| Fail["Identifier Not Found"] Decl["Forward Declaration (Signature;)"] -->|"Generates Call Stub"| Obj["Object File + Unresolved Symbol"] end subgraph LinkPhase["Linking Step"] Obj -->|"Search symbols"| Linker{"Find Definition?"} Linker -->|No| LinkFail["Link Error: Unresolved External"] Linker -->|Yes| Bin["Final Executable"] end ```

To invoke a function whose full definition is not yet present, the language provides forward declarations. Functions consist of two distinct elements: 1. **The Declaration (Prototype):** The return type, name, and argument types followed by a terminating semicolon (`;`), omitting the body. 2. **The Definition:** The complete prototype accompanied by the code block enclosed in braces (`{... }`).

Providing just the forward declaration gives the compiler the function's signature—what arguments it requires and what type it returns—allowing it to generate the call site code. The compiler then leaves a marker instructing the linker to resolve the function's final address once it locates the definition across all object files. If that definition is absent during linking, the unresolved symbol manifests as a link error rather than a compiler error.

[01:07:30](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=4050s) Header Files, `#include <windows.h>`, and Translation Units

In Visual Studio, syntax highlighting colors language keywords blue—built-in elements such as `int`, `return`, and control structures that are universally standard across every compliant C compiler. Identifiers that do not highlight blue (such as `CALLBACK`, `HINSTANCE`, or the Win32 API functions) are not language keywords; they must be imported from external headers.

```mermaid flowchart TD accTitle: Preprocessor Include Hierarchy accDescr: Illustrates how an include directive recursively embeds operating system headers into the source file. SourceFile["test.cpp"] --> Preprocessor["#include <windows.h>"] subgraph WindowsHeaders["Windows SDK Headers"] WinH["windows.h"] SubH1["windef.h"] SubH2["winbase.h"] SubH3["wingdi.h"] WinH --> SubH1 WinH --> SubH2 WinH --> SubH3 end Preprocessor --> WindowsHeaders WindowsHeaders --> ExpandedSource["Expanded Translation Unit (Massive text stream)"] ```

The preprocessor directive `#include <windows.h>` acts as a literal file paste instruction. It locates the requested header file and injects its entire contents directly into the source file at that position. Although forward slashes (`/`) or backslashes (`\`) can specify paths, forward slashes remain the preferred cross-platform standard for include paths. Examining `windows.h` reveals that it is not merely a single definitions file, but a massive cascade of nested `#include` statements importing operating system definitions, macros, and API signatures. This sprawling chain transforms a concise twelve-line source file into an extensive translation unit containing all the types required to compile a Win32 application.

- Keywords turn blue in the Visual Studio editor and belong strictly to the core C/C++ language. - Windows-specific types (`HINSTANCE`, `LPSTR`, etc.) and macros are defined entirely inside platform header files. - The preprocessor replaces the `#include` line with the complete text of the referenced file, recursing through every sub-header.

[01:11:01](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=4261s) Day 1 Conclusion and Upcoming Topics

With a complete, compiling Win32 project assembled, Day 1 concludes by setting up the architectural exploration planned for the next session. The upcoming stream will dig beneath the surface of the working code to examine the assembly instructions emitted by the compiler, trace the internal mechanics of the linker, examine the role of the C Runtime Library (CRT), and address why `WinMain` is not actually the true starting point of the application execution despite being designated as the program's main entry function.

> “And we're going to look at why I said WinMain was actually a little bit of a of a misdirection, why it's not really the entry point for your program even though I said it was going to be.”

The primary broadcast finishes here as the host cuts the main recording to transition into an unrecorded, interactive Q&A session with the live stream audience.

## Notable quotes > [01:04:05](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=3845s) C and C++ are languages in which you are never allowed to use something which has not been defined yet. — Casey Muratori

> [13:57](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=837s) The compilation step is basically in charge of doing the majority of the work to translate our text file from something humans read into something that a CPU can read. — Casey Muratori

> [32:18](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=1938s) The linking process, even though it seems like we're going to finish it here in a minute, is never actually really finished in an executable, unless what you're building is the whole operating system. — Casey Muratori

> [10:03](https://www.youtube.com/watch?v=F3ntGDm6hOs&t=603s) Basically just understand that nothing we're going to do is going to be anything other than entering text into a computer. — Casey Muratori

## Mentioned Casey Muratori, Handmade Hero, Molly Rocket, Microsoft, Microsoft Visual Studio, Microsoft Visual Studio Express, Visual Studio Community, Visual Studio 2008, Team Foundation Server, ASP.NET, The Witness, MFC, Intel Xeon, Intel Xeon W5580, Windows Task Manager, Microsoft Developer Network, Charles Simonyi, MIDL, COM, OLE, C Runtime Library

## Video description Day 1 of the introduction to C programming on Windows series from Handmade Hero. See http://handmadehero.org for details.

1. Getting up to speed with C programming on Windows 2. Getting a C compiler via Microsoft Visual Studio Express: 2.1. Caveat: In the next video, we suggest you to get Visual Studio Community instead of Visual Studio Express, you can get Visual Studio Community here: http://www.visualstudio.com/ 3. Creating a “Win32 Project” 4. Adding a C++ file: test.cpp 5. Compiling and Debugging project 6. WinMain entry point function 7. Creating and calling a function

[Source](https://www.youtube.com/watch?v=F3ntGDm6hOs)

中文简报

Windows平台C语言入门 - 第1天 主持人Casey Muratori通过确立在Windows上编译和运行原生代码的核心基础,为观众从零开始用C语言构建完整游戏做好准备。在操作Visual Studio配置包含空白C++源文件的空Win32项目后,他阐明了多阶段构建流程的细节,对比了解释编译器语法错误与未解析的链接器外部符号之间的区别。随后,他剖析了WinMain入口函数签名的结构,解释了Windows头文件、调用约定以及传统匈牙利命名法在底层的运作机制。本次直播最后定义并调用了一个自定义函数,利用OutputDebugString向Visual Studio调试窗格输出诊断文本。 Casey Muratori启动了Handmade Hero项目,旨在记录在Windows平台上完全使用C语言从零开发一款完整游戏的全过程。 (0:02) 在Windows上搭建原生C语言开发环境通常需要Microsoft Visual Studio Express或Community版本,以获取完整的MSVC编译器和链接器工具链。 (2:23) Windows在控制台应用程序与图形窗口软件之间保持着严格的架构划分,在项目配置期间需要进行明确的选择。 (5:00) 该编译流程依赖cl.exe生成中间目标文件,并依赖link.exe解析外部符号以生成最终的可执行文件。 (25:45) 图形化Windows应用程序使用WinMain作为默认用户入口点,接收windows.h中定义的操作系统句柄、命令行参数以及显示参数。 (35:36)

Source quotes

[64:05] Casey Muratori: C and C++ are languages in which you are never allowed to use something which has not been defined yet. [13:57] Casey Muratori: The compilation step is basically in charge of doing the majority of the work to translate our text file from something humans read into something that a CPU can read. [32:18] Casey Muratori: The linking process, even though it seems like we're going to finish it here in a minute, is never actually really finished in an executable, unless what you're building is the whole operating system. [10:03] Casey Muratori: Basically just understand that nothing we're going to do is going to be anything other than entering text into a computer.

Original transcript

[0:02] Okay [0:03] Assuming this is working [0:05] I would love to welcome everyone to this [0:09] Pestering basically what I wanted to do [0:12] Is I am planning on [0:14] I'm starting a project on Monday [0:16] Which is probably very ill-advised and I appreciate that but I'm [0:20] Planning to start a project [0:21] Where I am going to show how to code [0:24] A complete game in C [0:26] Which is a pretty big undertaking [0:29] And [0:30] I thought about it whether it was a good idea for a while and I wasn't sure but I finally decided that I really wanted to do it and I always want [0:36] I need the directions to have like a documentation [0:39] But you can basically [0:40] Or documentation say [0:42] Like a live recording of like cures everything that we did to make [0:46] An actual games you can play from scratch [0:50] And so I don't know how that'll go nobody make care about that at all until the game is pretty far along or something like that [0:57] That but I really really want to do it [0:59] And so I'm going to be starting that [1:01] On Monday but before then I wanted to practice the streaming to make sure that all of the stuff is going well because [1:07] Computers of course as you know are oh so reliable these days [1:12] And so I kind of have a feeling that there will be plenty of [1:15] So what I thought I do [1:17] Is spend a couple days [1:18] Doing test dreams where I will at least do something useful [1:22] Which is explain how to do C programming on a computer [1:26] Because [1:28] I mean [1:28] Let's face it lots of people don't know how to do that [1:31] And if anyone wants [1:32] What's to follow along as I program the game [1:35] NC and go through all the explanations [1:38] Of why I'm reading the game code that way [1:40] I won't be wanting to stop and explain little things like what is the question mark operator or [1:46] How does [1:47] Is the staff work or something like that unless that's exactly relevant topic [1:51] At the time so I was hoping to basically do [1:53] A couple streams that I could archived and just put up on the website that's like [1:57] If you don't know how to pronounce it all if you literally have no idea but would like to watch the series [2:02] Go watch these couple videos that'll get you up to speed [2:05] I'm just what's going on so you can start to follow and granted you'll still have to do a bunch of work to practice and learn how to program at Aldi [2:11] Because if you don't know any programming [2:13] You're not going to be able to just jump right in but at least I'll get you started and then you can presumably [2:18] At least start to follow the videos and understand [2:21] You know the majority [2:22] So [2:23] What this video is going to be [2:25] It was going to be literally showing [2:27] How I would start [2:29] To program Siana machine and how to do some of the basics [2:33] I forgot [2:34] So this is not a Windows machine cuz that's the most common [2:36] Programming machine that people are going [2:38] And have [2:38] And [2:39] The thing that you have to do right off the bat which is actually kind of annoying and you don't have to do this [2:44] If you're on Linux but the thing you have to do on a Windows machine issue has to find [2:48] A c compiler [2:49] I'm currently you don't have a lot of option [2:51] Even though llvm which is, one other platforms [2:54] Is [2:55] Sort of able to build seen out it's not able to actually do the entire process so what you have to do [3:02] Is you have to go [3:03] Get something called Microsoft Visual Studio X [3:07] And this is basically a free version [3:11] Of their you know thing that they're there [3:14] Professional [3:15] C programming environment and you'll see when you get to this page [3:18] They want to give you a lot of other stuff [3:21] But you really don't want [3:23] When you look on here you can see stuff like oh. [3:26] Team Foundation server [3:28] And [3:29] Since you're just someone is trying to program C at home you probably don't have a team or if you do they probably don't [3:35] Don't have a foundation or don't want their Foundation to be comprised primarily [3:39] Or something for Microsoft anyway I certainly would [3:41] And they're also going to try and give you things like this [3:45] Express for web which is something that you use [3:47] To program [3:48] Like you know if you want to do web deployment you know asp [3:52] P.net and other things like that [3:53] What you want to do [3:54] You're the one that you actually want to get [3:56] Is this one here which is Express 2013 for Windows [4:00] Which is the thing that actually lets us compile C++ which is what we want [4:04] So I'm going to start that downloading [4:06] Or at least I'm going to go through this this awesome [4:09] Crazy [4:10] Circus here that you have to do to download [4:13] Los Arcos [4:14] And now we're going to kind of have to skip a little bit of this process only because there is a challenge response that they do [4:20] Which people will have to do on their own I obviously [4:23] I can't tell you how to do [4:24] You will have to basically [4:27] Install the Skype [4:31] Loading identity provider [4:33] Okay so yeah you will have to go through and you'll have to fill this out [4:36] Unfortunately you'll have to get like a Microsoft [4:39] Login of some kind [4:40] In order to get it [4:42] But once you get it it will allow you to install visual studio and you will be able to do basically Sub sub [4:48] Definitely what I'm about to do [4:50] After you get that in [4:51] Install it'll probably make you reboot your machine which I also can't do on a live stream of course because if I would have read them [4:56] Machine [4:57] But after you do that [4:59] You will get [5:00] A newer version [5:01] Essentially [5:02] Of this particular product this is the older version that was installed on this machine [5:07] Visual Studio 2008 [5:09] And as you can see we've got stuff on here which is kind of not actually stuff I can open up [5:15] Obviously I'm not allowed to [5:17] To show you any of the secret Witness [5:19] Things that would that would be very bad for him [5:21] But what you can do [5:23] To actually start programming [5:25] In this particular Department you should go to new [5:28] And you go to Project [5:29] And what that'll do is that will allow you to create one of their dummy projects which I'll show you how to build [5:34] Only for a little while because we'll kind of immediately get off [5:38] What advice does the brings up [5:39] A giant window [5:41] Full of all of the things [5:44] That you [5:45] Could build with this [5:46] And most of them are things that we are not concerned with [5:49] Are you can see there's a bunch of template things for you can use for. Net you can see there's all sorts of things here MSC which is like an [5:55] Antiquated Library [5:56] And you don't care about any of these things the only thing you want to do is build a win32 [6:01] Application [6:01] Tinder two options [6:03] One is for win32 console application [6:06] One is for win32 [6:07] Project [6:08] And the difference between these two is actually extremely rudimentary [6:11] All it is is for some reason way back when they actually did [6:17] The original version of Windows they decided to segregate [6:21] How you built [6:23] Basically applications that can run from a command line [6:27] Which is something we'll look at me [6:28] Future and ones that are actually more like apps like it have a window [6:32] And because they did that [6:34] You have to build an app as one or the other [6:37] And this is actually something that's basically impossible to get around there are workarounds for it if you really care but basically there is no [6:44] No way on Windows [6:45] Unlike say on Linux or Mac Off [6:47] There is no way to actually build something [6:50] That both [6:51] Works from the command line [6:52] And work [6:53] From [6:54] In the standard application mode [6:57] But [6:58] We don't have to talk about that too much because we're going to be building a game and games don't really have [7:02] Have to do anything from the command line [7:04] Inside of a [7:05] That's right away [7:07] So [7:08] What we're going to do is Select win32 project which is what setup for actually building a [7:12] Sorry I got to enter a name [7:14] So we're going to call this [7:16] We're going to call this [7:19] Okay [7:20] And what I'll do is I'll bring up this silly little wizard [7:24] And The Wizard is basically asking a bunch of stuff none of what you want [7:27] So what you want to do is just check empty project so that it will get out of your way [7:31] And what kind of gives you another option here to do other things like the console application dlls which are separate issues. [7:37] Saclibrary switch we don't need [7:39] Worry about right now better things you might want to know [7:41] And we'll go to Windows application which will basically just give us [7:45] Our own [7:46] Furtive [7:51] This will basically give us our own sort of [7:53] Dumping Ground where we can put stuff in and build it [7:56] No the way that Microsoft Visual Studio works if it has this thing called a solution Explorer [8:01] And one thing that will often happen to you when you're developing is it will go away so you will get something [8:05] That's like this or perhaps you'll get something that's even completely blank [8:09] I'm so that has nothing in it like this [8:11] And you can get back to the solution Explorer Thing by going to view solution [8:15] Explorer now what is a solution [8:17] You may ask what was the problem [8:19] You may also ask him that's a very valid question [8:22] But the answer is there wasn't necessarily a problem [8:25] Unless you consider the problem being that Microsoft makes it very hard to build things [8:29] Solution was just something that they started calling a project at some point [8:34] Answer [8:35] Really a solution is just their word for a thing that you are going to build it's like a basically [8:40] A list of things that need to get built and how they're going to build them and so instead of having an intuitive name like [8:46] Files Explorer project Explorer it's called solution Explorer [8:51] And you have to go to it when you go to the solution Explorer [8:55] You will basically get something here [8:57] That works a lot like [8:58] You know the file explorer in Windows [9:01] It's hierarchical and you can collapse it [9:04] And they made some folders in here but we don't really have to care about these folders very much [9:08] And we can have our own folders or rename folder [9:11] So if we wanted to rename one of these you know we could go in here and call this [9:16] Whatever we wanted and that's fine [9:18] But we need to do to in order to start building something is Axe [9:21] She have some files in your [9:22] How to build [9:22] So that it will know [9:24] What we are [9:25] So in order to do that I'm just going to right click on this and going to add [9:29] And I'm going to take a new item [9:31] So that would have make a new file basically [9:34] That we can actually build [9:36] That will pop up a mess of Windows stuff [9:38] Because there's all sorts of things that you might want to do you might want to make an SQL script file [9:43] Class diagram [9:46] Those might be good things to me [9:47] But we're not going to make those right now [9:49] Instead we're going to make just a straight-up [9:51] CPP file [9:53] Okay [9:54] So basically I was ripped into the name done I so basically we just have to [9:58] Give RC Fallon name and add it now we will have a blank file that we can start typing into [10:03] And that is what we will use [10:06] To start programming in [10:07] Now [10:08] Programming UC has not Advanced much over the years unfortunately [10:12] Obviously C & C++ [10:14] They're both pretty old but [10:16] You know I think C++ was sometime early 80s [10:20] I see was you know a good decade before that I want to say [10:23] And yet [10:24] Just the same even though they're so old [10:27] The way in which you actually enter [10:30] C code into a computer and the way it is actually built is still [10:33] Almost the same [10:35] As it was back then you basically just have [10:37] Text files [10:38] Their basic clean old text files less complicated than something that you would type into Microsoft Word like they [10:45] They literally don't even have annotation right there just [10:47] Robotics [10:49] And that raw text [10:50] Is then [10:51] Interpreted [10:53] I'm by the tools [10:54] To do the things that we need to do [10:56] And that's done with the [10:57] Compiler and stuff that will be talking about [10:59] Basically just understand that nothing we're going to do is going to be anything other than entering text [11:05] Enterkomputer [11:06] Okay [11:07] So [11:08] The first thing to do is to say well okay we haven't actually done anything here [11:14] This is some text [11:15] In a file [11:18] And [11:19] What you wanted what you will notice is that this basically every time I type in here there's a little yellow bar that sort of appears [11:26] And that just tells you that these are new lines that you have type since you have saved [11:30] And you can see that I've got a little [11:32] Star there [11:33] That now adds to it just like in most applications that says this file has been modified since it has been [11:38] Can save now if I want to say that I can just go to files saved [11:42] Peppa Pig or I wanted some shorthand I can hit control s [11:46] Right and there it saves it and you'll notice that the yellow bars now changed to a green bar [11:51] And what does a green bar mean when a green bar is basically something that lets you know [11:55] That is saved there was still a change recently there [11:59] And I believe although I am not a frequent user Visual Studio that [12:02] It will basically remove the green bar [12:05] Once we actually [12:06] I'll be [12:07] Inter working program [12:08] So that you know what changes you've made since the last time you bought [12:12] Your program [12:14] So let's say [12:15] I want to actually run the process [12:17] Of making something out of this text file [12:20] Well the thing that you do there is you say build solution [12:23] And Bill solution will go through everything that we have in here [12:27] It will actually [12:28] Do the work necessary to make this in [12:31] To a program [12:32] And we'll talk about all those steps [12:33] In a little while [12:34] So when I hit build solution [12:36] You'll notice that if I did not have an output window open it magically made one for me [12:41] It just pops up there's really nothing you can do [12:43] About it [12:44] And [12:45] What it does is it [12:46] Prince out [12:47] What happened [12:49] When it tried to build the program [12:51] So it starts out by giving me a line which says what was trying to build [12:55] So it says build started [12:57] Project test [12:59] No that's what we wanted you can see in here we've essentially when it created are automatic [13:03] Project for us [13:04] He created the solution called test [13:06] And it put inside one default project which is called test in the reason I call a default project you can see it's bold [13:12] It's because [13:13] You can actually go in here [13:15] And there's a thing called set as start-up project in [13:17] Some of the things like this [13:18] There's basically a notion of what the project is you're going to build [13:23] When you build a solution because we could actually stacked other products in here that build other programs [13:28] Which we don't all want to build and other sorts of nonsense like this [13:32] Most of that is not really necessary when you're doing development unless you start developing a very large and complex project [13:38] But if you're just building a game by yourself it's on like you'll need to ever do anything [13:42] Like that [13:43] And I often don't build anything anything from here so [13:45] What are things were at carburetors how to build things without using [13:49] That's it [13:50] Cast of the project that we will build when we do build solution and so what this was telling us here [13:55] Is it was going to build that project [13:57] And there's a configuration line [13:59] Which is debug win32 [14:01] And what the configuration mean [14:04] Is basically what sort of build it was trying to do [14:07] Because as we'll see later on there's actually multiple ways you can build the same set of C code [14:14] Some of them are designed to Target different platforms for example you may want to Target a 32-bit copy of [14:20] Windows [14:21] Or 64-bit copy of windows [14:23] And that would be part of the configuration [14:25] You might want to be trying to do things that are based on [14:29] Deep like a debug developer build so something that has a lot of test code compiled into it [14:35] Special menus for you the editor for the game or something [14:38] Might be built [14:39] In this mode but then there might be another build called release [14:43] Or retail depending on how you do your naming [14:46] Team which will build these things out and so basic configuration [14:50] Is something that affects the way [14:52] In which these text files [14:54] Are actually interpreted by the various things that [14:57] That we do in order to get to an application that that [15:01] Is somehow different from the other configuration [15:04] That we might be [15:05] So now the next time you can see here is compiling [15:08] And what that is is compilation [15:10] Is the general term [15:12] It's not a particular specific term although we actually use it to mean something specific [15:17] That's a very general term that technically means [15:19] Moving something from one format into another [15:22] Basically [15:23] It's sort of like [15:25] A translation in some sense a compiler is something that parses [15:29] A text file typically [15:31] It turns it into something Samantha it understands the meaning of that text file what we were trying to do that text [15:37] And then it turns it into [15:40] Some other thing that we wanted [15:42] Now in this case [15:43] What is going to do is we're actually trying to get it [15:46] To produce at the end of the day [15:48] I'm an actual program that we can run an executable something that you would click on in Windows to run like with the little eye [15:55] Icon. Exe that thing we want build that thing [15:58] In order to build that thing [16:00] Basically the the text code that we write [16:03] Has to be translated into something that the computer can run [16:06] And that is what the compilation step does and there's another step [16:10] After compilation that we'll talk about [16:12] But the compilation step is basically in charge of doing the majority of the work [16:16] To translate [16:17] Are text file from something humans read into something that a CPU can read and specifically [16:24] Often times [16:26] A specific process [16:27] The compilation will be [16:29] Compiling from a text file into say x86 to [16:32] X64 code [16:34] Something for the actual CPU [16:36] That you were trying to Target not abstract [16:39] Stop [16:40] Given that [16:42] After we we see the compilation lineman of the compiler [16:45] Started and we now go to a list of what files it's actually [16:49] Compiling we only have one file which is [16:51] Just test out CPP [16:52] And so not surprisingly it tries to compile that file now you will note [16:57] In front of all of these [16:58] There is a little [17:00] Number within with assertive [17:02] Greater than symbol [17:04] And [17:04] What is [17:06] Is totally Irrelevant for the most part 2 what you're going to be doing for development it's not really something to pay attention to [17:12] But just in case you're wondering [17:14] If you are on a machine [17:16] That happens to have a lot of processor [17:18] So if I go in here [17:20] If I basically just that use the hot tea [17:23] One of my favorite hot fries [17:25] Control shift escape to bring up the task manager [17:28] You will notice that this machine [17:30] Have a lot of processors [17:32] In this thing called CPU usage history [17:35] There is one of these for every logical processor [17:39] In the machine [17:41] I'm a logical processor is or shouldn't say lunch process [17:45] Crap that's the wrong word [17:48] Deluxe compressor is not individual processor [17:51] If it's only a logical unit that can run code [17:54] And there's two different kinds of these [17:56] And we might as well talk about them now if I'm going to talk about them [17:59] Certainly more [18:00] Out later on in the actual series [18:02] It's not in the center doctors [18:04] Basically the word processor is divided internally or as we are computers about internally honestly there are actual physical processors [18:11] So most people have one physical processor in the machine obviously [18:14] But other machines have two or three or four maybe [18:18] Even dozens [18:19] A processor [18:20] I'm certainly not consumer boxes but you know [18:23] Certain server types my [18:24] I have 32 processors [18:25] The machine [18:27] Who's physical processors obviously are chips they were made by Intel they're stuck in the machine they have a nice big old heatsink, [18:35] Grandpa from overheating [18:37] And when you power on your machine they are what executes everything [18:41] Graphics code or things like [18:43] The networking which is sometimes on [18:44] Car adjustable chips [18:46] The CPUs what does all the work but [18:49] In addition to being [18:50] A physical unit [18:52] The CPU itself is actually divided internally [18:55] Into processing unit [18:56] Which actually can run code sort of separately [19:00] Those are typically called course [19:02] So inside a single CPU [19:05] You might have four chords [19:07] For a course or something [19:09] And you will see these often times advertising Intel advertising and of course more course is better but what is a quart [19:15] Accor [19:16] Is basically something that is capable [19:18] I'm doing the work [19:20] Stand-alone CPU for the most part it is something that would have been a CPU in the old days when CPUs could only [19:26] Execute one thing [19:27] Time [19:29] Now you have processors capable of executing multiple things at a time [19:32] Each one of those units is [19:35] Call Decor in [19:36] And the chorus typically have a bunch of things in them [19:39] They have units capable of doing [19:41] Maddox they have units capable of doing every other saying all these hurtful things [19:45] And then they will talk to the memory in your system will talk to the [19:50] The bus go talk to all sorts of things to do their job but [19:53] Biologic or [19:55] Is the things action of the computation [19:57] Even that [19:58] It's still not really [20:00] What you might call a logical processing unit [20:03] Nowadays and the reason for that is they subdivided that even further [20:08] Down two things called hyperthread [20:11] And of course [20:12] Hyperthreads are basically [20:15] A thing where [20:16] A processor [20:18] Score [20:19] Is actually able to maintain this [20:22] State [20:24] Of multiple cores [20:26] As if it were multiple cores [20:28] Even though is only capable of executing anyone given Court a time so for example [20:33] You think of a CPU core as being able to remember say what it was running where it is in the [20:39] Program what the state of the things it was operating on these sorts of things [20:43] We'll get into all those aren't detail later [20:45] But [20:47] Cory's basically doing this work of running an application [20:51] That core can actually store multiple of those States [20:54] Almost like a multitasking operating system you can think of is, there's the taskbar and it's got different tasks [21:00] That it has [21:01] Wella Cork and actually sort of do that testing [21:04] Insertive sent itself [21:06] And [21:07] Even though it's only running one thing at a given time it could keep safe for additional [21:13] State [21:13] But it can really quickly switch to [21:16] And so what happens is [21:17] Those actually show up often times in the operating system as a logical processing unit [21:23] Because to the operating system they sort of look [21:26] Like a processor [21:27] They are effectively running something [21:29] Even though only one of them are particular court is actually inflated a given [21:34] Another word to talk about their [21:36] But [21:36] I am from two tangents I thought I'd mention some of that way booted up here [21:39] So how's it going to see there a lot of logical bussiness as they are not this many processors [21:44] In the actual machine [21:46] In fact [21:47] I don't actually know [21:50] If I can go on here [21:52] I think [21:54] If it's actually will tell us [21:55] What kind of processor it is [21:57] Yes [21:58] It is a Xeon [21:59] It easy [22:01] 2 processor box [22:03] Although it doesn't actually tell me how many threads for plumbing how many cores for processor it actually has [22:07] We can go look up what a w5580 is [22:09] And we could see how many it has [22:11] But I think it's probably only got maybe [22:14] 4 / I don't know I'm not really sure [22:16] But anyway each one of these would would correspond basically [22:20] To one individual one of those hyperthreads and it would show me basically [22:24] How much usage that particular thread is is getting [22:28] Right now [22:29] So hopefully that that gives you a little bit [22:33] Perspective on this [22:33] I wonder too [22:35] You know what [22:36] Nowadays that kind of attitude [22:37] I wonder if there's any way I can get more information [22:40] About things like hybrid [22:43] Like I say even show hyperthreads I feel like in the old days you could [22:46] Chicago Bears [22:47] Didn't say whether you were showing [22:49] Clusters of large compressors out of [22:51] I do now [22:55] Doesn't [22:56] Doesn't look like there's much here [22:59] For that [23:01] Alright well [23:02] Anyway that is not really relevant what we're doing so I'm going to skip it but maybe later on we will [23:06] We will go try to find out how to how to get a little more info [23:09] Thanks anyway [23:11] So there a lot of Pastors in this system in when you build something [23:16] Obviously compilers can get a little slow and if you have a lot of things compiled they could take [23:21] Sometime it's a one of the things that compilers do is they are more [23:24] Threading sometimes [23:25] Depending on which one [23:26] Talking about [23:27] And they will try to compile using more than one [23:31] Lots of passing it so they'll try to use [23:33] More of a CPU resources faster and what this little thing here [23:39] Represents if I remember correctly [23:41] It's been a long time since I've ever really use my things that just to let you know a sequence number of basically which [23:47] Sort of [23:48] Sort of [23:49] Spawn of the compiler [23:51] Was reporting this message because you may have multiple compilation [23:54] I going [23:55] Multiple different [23:57] City is doing compilation and I believe that basically just tells you [24:00] Which Wonder [24:01] Which one you're looking at that time [24:02] Time so if we were to do more complicated [24:04] Population with multiple files you might see two stories for is going on there as it's cooled off jobs [24:08] Any more complex fashion but for the moment we're only seen ones because it only had one failed to compile [24:13] And did not bother to lunch at [24:15] Search for Threads to do that [24:16] Anyway [24:18] So [24:18] This is the father was compiling and we will see here the first time we got an error [24:23] And what an era is is an error means basically it was trying to read the text file that we gave it [24:29] And it did not like what it found now that is unsurprising cuz I basically just typed a bunch of gibberish in here [24:34] But we can do is when we double click on this it will tell us where the problem is [24:38] It will then stop basically what it's doing [24:41] So when you have errors it will list the errors that it found [24:45] It will list them up usually to a certain number of errors and use that as well but after it gets hurt [24:51] Compilation [24:52] And it will basically just reports [24:54] That it failed the compilation and you can see it says 1 errors [24:57] This year and it says 0 succeeded 1 failed [25:00] And Alexis know if they're ones that it skipped because it didn't thicken [25:04] Need to do any work that's what it [25:06] It also save a build log for [25:07] Which are pretty useless most the time but [25:10] If you want to look at the build log basically it saves an HTML file [25:14] That has sort of [25:15] A a lot of what happened in the building for I guess for posterity or if you want to do some kind of thing for you [25:20] You saved the logs are doing [25:22] Maybe you are running these [25:24] In some way that you're viewing remotely there's there's reasons for build logs but we're certainly not going to [25:30] Okay [25:31] So that rather exciting process there where we just hit build and we get an error [25:35] Is what we're going to be doing [25:37] In order to produce an executable and in order to get to the next step of actually producing [25:42] Beautiful [25:43] What we are going to have to do [25:45] Is we are going to have to give it [25:47] Some code that actually [25:49] Understand [25:50] And [25:51] Basically I'm going to type [25:53] In some rope code now [25:55] And I'm going to explain to you [25:56] Certified it does it start of the simplest thing that we can possibly type in [26:00] To get to the next stage [26:02] In [26:03] Here it is [26:05] Set [26:06] If I now try to build this [26:08] You will notice [26:10] And don't worry we'll get to this [26:13] You will notice that what it does is it gets [26:15] That's if we were before we got to test out CPP [26:19] And it actually was [26:21] Able to sort of moved past that [26:22] And move on to doing other things now [26:25] He tried to lock the Microsoft resource compiler [26:28] And that was because we have a resource files [26:30] Singing here and it created [26:32] This project for awesome [26:34] A resource compiler is nothing fancy [26:36] It sounds a lot better than it is you're like a resource Camp I like it to pile my games resource with that [26:41] Not very likely [26:42] And you probably don't want to do that [26:44] Myriad reasons but [26:46] What the refractive actually does is the resource compiler does things like packing up an icon [26:52] For your application [26:54] And sticking it in somewhere [26:56] Where the [26:57] But where Windows could find it in the executable so that I can display it next year schedule things like that so that is something that you do need to know how to do [27:04] Eventually [27:05] The right now we don't care at all obviously didn't actually do anything so to finish that up but then it got to the stuff that I actually want to talk about [27:11] Which is linking [27:13] No blinking is [27:15] Is linking [27:17] Is sort of a [27:18] A backpack [27:19] Tennis compilation [27:20] Process [27:21] Now what we could do [27:23] You know compiler certainly could [27:25] Take a text file and it could directly make an X [27:27] Skittle out of it if that textile contain everything that needed to Define their stupid butt [27:32] What usually happens more often [27:34] And [27:36] Harley for legacy reasons at this point but [27:38] You know [27:39] What can you do [27:40] What happens more often if you have a lot of text file so you know the code for game could be hundreds of thousands of lines of code [27:47] Kodak [27:48] It's a lot of PCP files that we're going to [27:50] Learn how to write here [27:52] And [27:53] In order to [27:55] Quote on quote save compilation time [27:57] And various other reasons [27:59] What a dolphin wants to do is be able to compile each file into an intermediate file [28:04] Doing one part of a compilation process one part of the bruising [28:09] Deleted file will basically be [28:11] The process that takes the text and turns it into mostly [28:15] Code to see if you can actually put their a bunch of things that aren't quite done yet [28:20] Windows intermediate files [28:22] Don't always have to be updated they only have me updated when the particular Source found that they came from changed [28:27] So for example this test ICP If I don't change test at CPP won't have to recompile testout CBP if I had tons of them [28:34] Other files productivity bar. CDP all these other files [28:37] Guy sings just one of them you would only have to do the recopilation [28:40] I just one of them [28:41] But [28:42] Does all of them have to be pulled in made into an executable at the end [28:46] They basically have a second stage [28:48] The compilation process which is called blinking [28:50] And that's what this line does here [28:52] And what Lincoln is about is licking is about Gathering all of that process [28:56] Sing together [28:57] All of us intermediate files [28:59] And [29:00] Basically resolving the places [29:03] Where is Bay Point to each other [29:05] So I made you a bunch of things in test out TPP [29:09] That are going to [29:10] Call out and and or reference [29:13] 2 or or use data from [29:16] Older [29:17] CPP file so I can pile [29:18] And [29:20] Since the compiler is only looking at each individual CPP file as it goes in [29:24] Found them [29:25] It can't resolve those references [29:27] It can't tell [29:28] Where the things are that things are pointing to because it's only seeing one individual files so what the Linker does [29:34] In this link stage [29:36] There's a thing called a liquor that gets executed [29:38] Separate from the compiler [29:40] And what it is [29:41] Is it is something that gathers all this together [29:43] Resolve the references [29:45] Packages into one EXE [29:48] Which you can then ship [29:50] Now when I say which you can then ship [29:53] That was the good old days [29:55] There's a lot of reasons why you can't actually just you [29:58] Thanks to Microsoft in their Tyler's Pursuit [30:00] Lawmaking building applications complicated [30:02] But [30:04] I'm going to hold off on that for now [30:05] So that we can focus on just the basics of the process in [30:08] It's a lot to absorb [30:09] I don't want over complicated [30:11] More than it already is [30:14] So in the linking stage [30:16] You will see that we've gotten to our next Air [30:18] And that air is this line right here you'll notice that it doesn't give me a line number and that is cuz Microsoft Linker [30:25] Is not particularly good [30:27] I don't know if they fix this and one of the more modern versions but [30:30] Even as of 2008 [30:32] Their liquor never bothered to tell you where your errors are so all you get [30:37] Is which function [30:38] It was referenced in [30:40] That makes sense [30:41] So basically you will know you will know very little you'll know like what file maybe May [30:47] Made the error possibly and you'll know what function [30:50] What's causing the problem or things like that and we'll kind of get to what all those mean and how to stop them out later but basically you get very [30:56] Cryptic message for a blinker fortunately [30:58] Most of the time winter errors are simpler airzooka Power air so it's not too hard [31:03] To figure out what they mean [31:06] So [31:07] Look at this error [31:08] What it says is unresolved external symbol underscore winmain at 16 [31:13] Referencing function [31:14] Tri main CRT startup [31:16] And then goes on to tell us that that was a fatal error [31:19] So there was one unresolved external [31:22] And now what that means just what I was just saying and unresolved external [31:26] What external means in this case is external to the population unit in which it was being used [31:32] So when I compile test at BP or something [31:35] It's got a corresponding file [31:37] That the compiler produced at the Linker isn't pulling in [31:40] Things that are external to that file are called externals [31:43] And when you see one unresolved external it means that it came across one of these [31:48] Couldn't resolve the couldn't find any [31:51] Actual definition of that anywhere else in the other file so what can I do it can't finish linking [31:56] Because it can't figure out [31:57] What it was supposed to do there [32:00] So again we get an error [32:01] This time it says 2 hours but really it was only wanting her [32:04] But that's just the way I guess it [32:06] Decided to print it out and not sure what the secondary is but hey [32:09] What you going to do [32:11] Anyway [32:13] Nobody gets now that we see what I look for areas we can start to the bucket [32:17] So [32:18] What actually happens [32:19] If you think about it when you run an executable [32:22] There is [32:23] Something kind of complicated but has to occur [32:25] Which is that [32:26] Windows [32:27] Is actually the program that's running on your machine [32:30] So the processor your machine is executing windows [32:34] And now we have built something that we would like Windows to start executing [32:38] But windows and our program [32:41] We're not linked [32:43] Together right [32:44] This linking stuff that I just explained where hey we can write some stuff and it pulls out together and it references each other and everyone's happy [32:50] It makes sense if we typed in all the code [32:54] But if we only typed in some code [32:57] That has to be started by windows are started by some operating system will [33:01] How does it know where to start how does it actually get started [33:05] And the answer to that is basically that [33:08] The linking process [33:09] Even though it seems like we're going to finish it here in a minute [33:12] Is never actually really finished [33:15] In an executable [33:16] Unless what you're building [33:17] Is the whole operating system [33:19] If you are building a kernel [33:21] You know that runs the entire machine then and some sense you've built the entire program in Lincoln can resolve all external [33:27] And even that maybe isn't [33:29] Totally true because even in that case there is a bios in your computer and that by us has to know how to [33:35] Load something [33:37] And start executing it which is the colonel that's on the disc so you know it's complicated if you actually want to go all the way [33:43] Way down to the bottom [33:44] And open up the Russian nesting dolls all the way down to what's actually happening [33:48] In your machine when you actually turn it on [33:50] But [33:51] Assuming that you're already running a program [33:53] Like Windows that's enough free system setup [33:56] To run executable content [33:58] The question is [33:59] How does Windows actually know where to start how did they know what to even do with this file [34:04] Any answer is that executable file format [34:07] Executable jar files on your disk just like a bitmap or anything else [34:12] The executable file format is basically set up in a way that Windows understand so that I can open it and read it [34:18] And read out of it information [34:21] That tells it [34:22] Where to actually start executing [34:25] So when Windows wants to run some of your [34:27] Code if it's we can load that file into memory [34:31] Do some work on it but it needs to do [34:33] Which will talk about again [34:34] In a little bit [34:35] And then it will use information that was put in the Goodwill by the slinker in fact [34:41] Which Talbot [34:42] Where in the Bible we wanted to actually start executing sewing memory where should it actually [34:48] Jump to [34:49] To actually start executing and tell the CPU here's where the code is go running [34:54] Any answer to that [34:56] Is [34:59] The way in which we tell the Linker [35:02] Where we wanted to tell Windows where to start [35:06] Is it we use a predefined name [35:09] And we name something that name [35:12] So that I can find it in our code [35:14] Now [35:15] That's not entirely true [35:17] Because we actually could go into the Linker itself [35:20] And there are settings which we could modify that would tell it to use some other name [35:24] For example through here [35:26] But most of the time nobody actually does code that way most of the time people just use the default name [35:32] And that default name name [35:34] Is actually [35:36] Well [35:38] I'm going to stay at Twin name [35:40] I will see you in a second it's not actually women but I don't want to spoil the surprise I'm going to say this with me [35:46] And what you can actually do if you [35:49] You're not going to probably remember a lot of [35:51] The stuff that I'm saying and I and I totally respect that I don't remember all the stuff all the time [35:55] Either [35:56] I always am looking things up [35:58] Ion msdn which [36:01] If you type women into your Google search box [36:05] You will get the first hit [36:06] As this site called msdn. Microsoft.com [36:09] Which we are going to be using a lot [36:11] As we learn to program C in Windows because it is basic Repository [36:16] For all of the stuff that is Windows specific [36:19] About program [36:20] And since we're going to be putting you in this for awhile that matters to us [36:23] Because we are possibly going to have to look things up at least in the first couple weeks [36:27] Look up things that tell us how to interface with the offering [36:32] Now in here you can see [36:33] The definition [36:34] We met in the documentation for it tells us a bunch of stuff [36:38] If you are beginning c programmer you will understand none of this and that is okay [36:43] One of the things I am definitely going to do in the series is go over things many times we're going to go over things in depth [36:49] You don't have to worry about the fact that a lot of the stuff that we're going to do may not be completely understand if you understand [36:55] Able to you at the moment I will always try to explain as much as you need to know then [36:59] And then we will go into more detail later as necessary because I don't want it to bog down [37:03] I do want to get bogged down fairly often but it don't like it to bog down [37:07] And [37:08] You can also email me anytime you have a question and we will try to work those questions into future [37:13] Editions of [37:13] Web series [37:15] So [37:16] This right here [37:17] Is what it's called a function prototype [37:19] And we're going to be dealing with these a lot [37:21] But basically what it does is it [37:23] Tells you [37:25] The way in which [37:26] A particular piece of code needs [37:29] The star Texaco [37:30] And we'll get into a lot of [37:32] Stop with these later so I won't belabor the point the basically this is the predefined entry point [37:37] That we will be getting called at [37:39] When we start executing [37:41] And so if we want to Define it in RC program [37:44] We have to basically do something like this [37:47] We have to go in and Define this [37:50] Just the way that they didn't hear [37:52] And [37:53] When we Define this [37:54] The Linker will now see the symbol this win main symbol [37:57] And it will know that that is the place [37:59] That we wanted our [38:02] Are execution for Windows [38:05] Now if I go to build again and you'll see there's a there's a shortcut to a here which [38:08] Ff7 so it's good to learn this was you build programs a lot [38:11] If I build it with S7 you'll notice one of the things that happened here [38:17] Before we get into two eras [38:19] What is going to happen series [38:20] Save the file automatically I don't know if you noticed the green line to the yellow line turning green [38:26] One of the things that happens [38:28] By default in the setup for [38:30] for [38:30] For Microsoft Microsoft Visual Studio [38:33] Is it when you build something it will save files that are unsaved [38:36] That's actually something you can change here in the tools option [38:39] If you want to [38:40] I change that stuff there's there's things in here that [38:42] That affect things like that [38:44] I don't have it remember exactly where that one is I think it might be in documents [38:49] But I don't know [38:52] Build projects I have no idea where it is [38:55] You will have to hunt for it my friends because I have no idea where that actually is [39:00] But [39:02] Etsy [39:04] There it is before building [39:06] Save all changes [39:08] And you can set that other things like don't say whatever so [39:11] That's just a custom my picture liking but you will notice that is why you have to save the file [39:16] Before I go [39:17] So if I hit that 7 it feels the file and you will see [39:20] That we have gotten some errors here [39:22] And the errors are because we have started to use Windows specific thing [39:26] And windows specific things aren't defined by default [39:30] In our secret [39:31] So what we have to do is we have to bring in something sad to find [39:35] Again don't worry too much about this because we're about to discuss it in detail [39:38] I just want to finish this one process first [39:40] Before we go back here [39:42] So I have done that [39:43] And now you will see [39:47] And I suppose I will have to remove these [39:50] To also [39:53] How to put those back [39:54] Things I wanted to talk about this [39:56] I was hoping they would be allowed [39:59] So [40:00] That did a successful field but I want to break it into two parts because I can't leave these in declaration [40:04] Gyms in there [40:05] Until [40:07] If I want Taxi [40:09] So [40:10] Miss particular definition [40:12] Basically uses a bunch of words [40:14] Windows has to find them [40:16] We're going to talk a lot about how we Define those things are things later but [40:19] I wanted to display nuts [40:21] Quickly [40:22] These things are all stuff that Windows defined that are specific to Windows [40:27] They're all things that you won't probably ever actually see if you're programming in a higher-level language [40:33] I've never really programmed in C sharp [40:36] Specifically [40:36] So maybe some of the stuff still creepy [40:38] Through that's entirely possible [40:40] But a lot of higher level languages [40:42] Obscure the underlying things that are happening in the windows code [40:45] And so you never will actually see them [40:48] But when we are apart of me and see it specifically when we program in low-level see that we want to directly interfere [40:55] Face with Windows as much [40:56] Possible to avoid any sort of [40:57] Intermediaries [40:59] We will have to deal with a lot of bees [41:01] No I'll get in touch with you specifically mean in a in a bit but you will see where it's like this LPS Easter [41:07] Now what is LP sturmey what what does that mean [41:10] Even an experience [41:11] Free programmer who's never programmed in Windows before [41:14] Would not know what LPC [41:16] Mr met so it is not the fact that I haven't explained [41:19] What this definition is or how any of this stuff in this file works that is why you don't understand it if you're beginning [41:24] You got a friend [41:25] This is actually complete gobbledygook [41:28] 28 experienc programmer [41:30] Who hasn't actually ever prevent windows before [41:32] Because these are things that Windows made up [41:34] They made them up [41:36] To use to reference specific things in their operating system [41:40] Which we will have to enter [41:42] Interesting [41:43] For example [41:44] Is a running program [41:45] It's something that refers to running program and LP stir [41:49] If something that is a pointer [41:50] To a string like a string of characters like some text [41:54] For example [41:55] And you will notice something that occurs in these that is kind of frustrating [42:00] These weird little H's because hey [42:02] Instance [42:03] Well that makes some sense that English right I mean [42:06] That makes no sense to use an instance of a program [42:09] Str that kind of makes me like a string Str stream MX [42:14] But like LP and age [42:17] Repeated over here [42:19] Okay pre Vincent previous since that makes sense instance that makes sense [42:22] CMD line command line I can read this evening if I don't understand anything about programming language [42:27] But these weird little things here H&M LP there's are confusing [42:31] Where do they come from [42:33] The answers they come from something a long long time ago in Windows history [42:37] Called Hungarian notation [42:39] If you want to know if that's racist well it probably is it's just nobody ever [42:43] Complain about it being racist [42:44] Because most people [42:45] Aren't racist against hungarians I don't think they are not a typically [42:49] Oppressed class during Washington State [42:52] So probably no one got upset about it but to be honest with you it's pretty racist to call Hungarian notation [42:57] Call Victoria notation is because the guy who introduced it [43:00] What is Hungarian [43:03] I think it was Charleston money I don't actually know I don't remember who it was but [43:07] Hungarian notation [43:09] Is [43:10] The sort of [43:11] Antiquated at this point I hope [43:13] Notion that you should prefix everything [43:16] That you ever typed [43:17] Into a programming language [43:19] With some characters that tell you what the thing actually is [43:23] So some kind of notion of what the thing is [43:27] Key in this case was pointer [43:29] I think L was long [43:31] Meaning it was it was a pointer that was into memory in the old 16-bit days that was outside the PayPal [43:37] Cuz I mean program [43:40] Mark 16 bit Windows I don't at this point my memory of what LP stand for [43:44] Completely. [43:45] They just handle it means something that you would use to talk [43:49] Two windows [43:50] It'll take me about something and you will see these littered everywhere they are super annoying [43:55] Because they really just do not helping me make things harder to read [43:59] Cannot emphasize enough please don't do this is a terrible idea [44:03] What can I say no you will see in modern code [44:07] Some people still do a variance of this [44:10] They will do things like [44:11] IP Foo if something is a pointer to food which will talk about a Wild Bill's um Foo or something cuz I'm [44:18] Number which is if you're doing object-oriented programming which we are really cover so [44:22] Don't ever find out what that is but [44:24] You can go watch someone else's track on Ustream Belinda [44:27] Anyway [44:28] That's what these annoying things are and you can pretty much ignore the most of the time although if you know how to read it it does help you if you just had [44:34] Happened to [44:35] Try to decipher something in Windows that's [44:37] Somewhat obtuse maybe you can use that [44:39] To help yourself [44:40] So there is [44:41] Anyway [44:43] If I said I want to talk about before we get into explaining exactly what all this code does [44:47] And how see [44:49] Work sort of [44:50] At a basic level [44:52] Is these things right here [44:54] So [44:55] What you will find [44:56] If you actually look at Windows code as you will see that there's a lot of annotation in it [45:01] There's not actually designed to be processed and see necessarily but that is designed to be processed by something [45:08] Say a documentation system that also reads the same files [45:11] Or was called the middle compiler which is a thing that is used to produce [45:15] Secondary files for [45:16] Object linking and embedding and all this other windows crap [45:19] We don't care about any of that stuff but [45:23] You will see things like this [45:25] Annotate some of the functions that you call and they see what this means [45:28] In [45:29] Is it telling you what direction [45:32] The data is flowing [45:34] No it's not actually something we want to have in here when we actually Define it is [45:37] It's strictly for their header file [45:39] But when you see it when you look at them sdn you will see it there and that is what that mean [45:44] Means that this is something [45:46] That is going to Windows using pass [45:48] Into windows [45:49] As opposed to an out parameter which is something that would be passed [45:53] Out to you back from window [45:55] And we will look at those [45:57] We will see those working Mini [45:59] Things we go through [46:00] Getting a windows program [46:05] So I'm going to go in here and delete those because you don't want to leave those in [46:08] I guess I've never actually tried before to leave them in I was kind of hoping you could [46:12] Just so that you could just [46:15] So where we build we now have a successfully [46:17] Building [46:18] Program [46:19] And [46:20] What this does is this means we actually have produced [46:23] And I will file and if we want to [46:26] We can actually run the executable [46:28] So in here you can see there is build solution [46:31] But in debug in the debug [46:34] Menu [46:35] You will also see that there is a way [46:37] Play to actually run the program [46:39] Which is start debugging [46:41] And that will actually run our program [46:44] Africa [46:44] That was our program [46:46] Did you love it [46:48] I know it's right side [46:49] So nothing strange but that actually did run our program our program doesn't do anything so it just started it [46:54] And then I deleted it [46:56] But you can also see hear some debug information that was printed out [47:00] Buy the actual startup code [47:02] Which is telling us something I'm sorry but that's exactly by the butter [47:05] Wichita keep telling us some things for example [47:07] It's telling us that it loaded [47:09] Pepcid AC unit [47:11] Let's get information for it [47:13] Hey buddy some other things [47:14] Depends on [47:15] So yeah she did Runner program [47:16] Isn't that a [47:18] Well let's complete that before I slam whatever [47:20] Does [47:21] With one [47:23] Simple thing that we can actually [47:24] Morrissey [47:33] Very exciting [47:35] We are going to run this [47:36] And oh [47:42] Oh man I get there [47:43] Everything [47:45] So as you can see now the program but as I modify everyone lying to it and now it's actually prints out [47:51] As part of Its Behavior [47:53] To the debug output [47:55] It prints out of string [47:56] That we wrote [47:58] Craigslist [47:59] I know that you are all very excited I am very excited as well about this [48:02] And I think [48:03] It is safe to say [48:05] That once I explain how this works [48:07] You are so on your way to create a game with Windows [48:10] If you can print something out of the debug window [48:13] How much more work [48:14] Couldn't even be to make a game [48:17] Certainly not much [48:19] Well [48:20] Maybe it's a little [48:22] I'm sure we'll be able to [48:24] In Future rapper [48:25] So [48:26] Now that we have a working windows program [48:28] Even though it really [48:29] Very much [48:30] Let's go through and see what everything did [48:33] I'd like to start first [48:35] With the things that I typed in [48:37] But couldn't actually be called by Windows cuz it was just a sub box didn't do it I could do anything and wasn't in the format that it wanted and terms [48:44] Blinking us [48:46] What this is [48:47] Empty [48:48] Is a function death [48:50] Now hopefully most people have [48:52] Are coming from other programming languages to have a passing familiarity with [48:55] What function is [48:56] So I won't belabor the point too much [48:59] Paisley what a function is [49:01] Is it something [49:02] It's sort of a reusable piece [49:04] Summer program [49:05] It's something where I can put some code in I can I can put some stuff in that it can do [49:10] And then I can use it [49:12] Anywhere I want to [49:13] So anytime I want to basically go do the things that the function does [49:17] I can do what's called a function [49:19] Call [49:20] And I can call into it [49:21] Now without actually [49:23] Explaining [49:24] The signature quite yet [49:25] We can actually see this in action [49:29] By moving the line that printed stuff out [49:32] Into [49:33] My function that I defy [49:35] Find before now when I run [49:37] You will notice I no longer get [49:39] The printout [49:40] You know [49:41] It's not there [49:42] Too bad [49:44] How do I actually do it well [49:46] I just function called that function [49:48] And now the thing is that it does [49:50] Get done where the [49:51] Function call [49:52] You can see now [49:53] Carpenter [49:55] Seriously what function is it something that holds some code for us [50:00] In a way that we can reuse [50:02] Encoding is about [50:03] We use a lot there's a lot of stuff encoding that has to do with sort of [50:08] Building little pieces then work together to make a program [50:11] It's very very difficult [50:12] If you were to sit down and write the entire program in one function [50:15] That would be really really difficult to do [50:18] And it's a lot of reasons why you would not want to do that [50:20] Which hopefully with my parents we go on but [50:23] That is what function is and now you'll notice our function [50:26] How to draw the parts to it [50:28] The first thing it has its word void [50:30] What the word void means there's this section before the name of the function [50:34] Images fear [50:35] This section here [50:37] Tells us if the function [50:39] Returns anything [50:41] And what that means is [50:42] When this function is called by somebody when someone asks it to do the work [50:47] Does it provide anything back [50:50] Two dots [50:51] To that call or to the person who invokes it [50:53] And it's actually more ways [50:55] But you can actually have that happen than just this [50:58] This is the most basic way [51:01] What void means in C [51:04] Is basically nothing [51:05] It's like saying [51:06] I don't [51:08] Provide anything [51:09] I am not going to give you something [51:11] When you call me [51:13] So the void in front of food just says this function produces no value for its color it does not act [51:20] Chile return [51:21] Anything to the person who called me [51:24] The next part of our function decoration [51:26] You can see here [51:27] In parentheses [51:28] Is another voice [51:29] And what that is is sort of the opposite of The Return part [51:33] It's what does this function expect to get [51:36] From the person who called it [51:38] So what [51:39] Things are going to be sent [51:41] Down to this function in order to get it to do the work that it needs to do [51:45] And as you can see it also void which means nothing [51:48] This is a function that returns nothing and takes nothing [51:51] And of course [51:52] That makes perfect sense given the fact that [51:55] Outputdebugstring [51:56] Just print out of string [51:58] It doesn't need anything to do it [52:00] So [52:02] That is our function [52:03] Apps that you can see these little plus and minus is he related to collapse functions if you're trying to [52:11] So [52:12] After that [52:13] Which is basically the thing that tells us it's called the function prototype [52:17] Piper the function signature [52:18] This right here [52:19] This is called [52:24] Prototype [52:25] And what it does is based [52:29] It defines the circumstances [52:31] If you will for how the function [52:32] Just called what does it take what does it return [52:34] We then have the function body [52:37] This part right here is a function body oh and I will note [52:40] This right here [52:42] DS2 of flashes [52:44] What is something that says [52:45] I'm about to type some stuff that's just a note to myself it's a comment [52:48] It has nothing to do with the code [52:51] But if that's something [52:52] You know what to do with my thought process [52:54] SOC allows me to do that anywhere I want to [52:57] C & C plus plus have to start with comments there's this kind [53:02] Which are bracketed by these little guys which is a lot like HTML a favor program HTML you know [53:08] You've got these two things [53:10] Right if you can use to enclose things and quotes [53:12] Enclosed things as a comment but doesn't actually process [53:16] So that's something that doesn't there and that basically says from here everything ignore until you see one of these [53:21] Right so can be multiple lines and all that stuff [53:24] This kind is a kind of was introduced with C++ [53:28] And what that does is it says ignore them to the end of the line [53:31] Get to the end of the line [53:32] Star-Crossed [53:33] And that's just a sweetie cut down on some typing it means you didn't have to type one of these at the end [53:37] It's a little convenient [53:39] It's not really that important but you'll find it's more convenient [53:42] I just typed [53:44] So anyway that's the Prototype of my function in this is the body [53:47] The body of the function [53:49] Is what it actually exit [53:52] So when this function is invoked [53:54] This is the code that will occur [53:57] And everything in between these two curly braces [54:00] Are things that will occur [54:02] So all the codes we put in here [54:04] Will occur [54:05] On invitation [54:06] The function [54:09] Principal right [54:10] Not much to it [54:11] And you can see [54:12] You really don't need much else understand what our function actually does the code Inside the Box [54:17] Office Depot [54:18] Because all it does [54:19] Is it called another function [54:21] A function we didn't Define [54:22] Call output debug string a [54:25] And I'm going to check out the as [54:28] Anyway as you can see [54:29] When I want to call the function [54:31] Syntax actually looks something like [54:33] The Prototype [54:36] These parentheses here [54:37] Most likely to find what I was going to take [54:40] These parentheses [54:42] Contain the things [54:44] That I'm going to pass [54:45] To the function [54:47] So in this case [54:48] I didn't take anything [54:49] Equity Bank Spring [54:51] Takes a string [54:52] NC [54:53] The way that you define [54:54] A basic string [54:55] Just a simple spring [54:56] Easy book quotes [54:58] Double quotes [54:59] Anything in between the double quotes [55:00] It's part of the strain [55:02] So [55:03] This is a string that I have made [55:04] And I'm passing it to Alba TX train so that you can print it out [55:08] Apple TV screen is a function [55:10] That works [55:11] With the operating system in order to actually send stuff to our debug output [55:15] Which [55:16] Betty Buttercup Frozen Prince over here [55:18] Now we'll talk a little bit more about that although debugging services on Windows is probably not something we're going to cover into much detail [55:23] But I will talk a little bit more about how that stuff works [55:26] More in-depth after we kind of go through in are more comfortable with just basic [55:29] Sexy code [55:30] Okay [55:31] So after that function is called [55:33] You'll notice there's a semicolon [55:35] A semicolon is a weigh-in see of telling the compiler that you're finished with a particular logical line of coke [55:42] Now it's not a particularly useless piece of syntax [55:45] Not particularly useful [55:47] Pizza syntax it is a relatively useless [55:49] Pizza Center [55:50] A lot of things just don't need semicolon [55:52] In a lot of languages only semicolons once in awhile or end-of-line 2 limited license [55:57] Understatement [55:59] The beastly all doesn't see in C plus plus is what the compiler know [56:03] That the things on that line [56:05] Other things that were part [56:06] Of a logical piece of code have now concluded [56:09] And so there might be more things on here that are part of this logical line of code and we'll start to see more of those later [56:15] The base of a semicolon says that the end [56:17] And that's called a statement [56:19] One line of code like that terminate by semicolon [56:22] Because it could actually go on for longer [56:25] The End of Line actual end of the text line [56:27] Doesn't really mean anything [56:29] MC plus plus [56:29] It's not like python or languages were white-faced mean something [56:34] In general like this [56:35] Whiteface here that I use to indent [56:37] To put this thing [56:38] So I could see that was part of the function more easily [56:41] That's really my decision [56:43] She doesn't care she just doesn't care about that [56:45] Cimorelli it doesn't care about this white space [56:47] Basically the only time Serie to care about white space [56:50] Would be if you were to insert it into something it was supposed to be a single name [56:55] Whiteface does breakup name [56:57] NC and so basically output debug [57:00] String a [57:01] Would not work if I were to compile this you would see that it would say that it doesn't know what output debug is [57:07] And the reason is because I Saw the space and thought that was a complete name that it's just hard to look [57:11] And see what it means and it can't do that [57:13] Something to get rid of that and go back to where we were [57:16] So anyway that is basically [57:19] How a line of code look [57:20] NCAA [57:21] Inside function [57:23] No [57:24] Let's go down to a more complicated function over here at the one that Windows call [57:28] So if you look here it's got a whole lot of decoration on it a lot more than we have here [57:33] Got something called in the beginning that we know [57:36] That is the place [57:37] Where the return value goes where the thing that comes back from the function [57:41] His place [57:42] Miss [57:43] In this case [57:44] 10th and C is a special keyword [57:46] It means editor so much like Boyd is a specialty word in seed [57:50] It tells it nothing [57:52] Isabella keyword that says an integer value [57:54] He's going to come back a number [57:56] Basically a whole number -5 [57:59] 12 [58:00] Something like this [58:01] Is going to be returned [58:03] From this function [58:04] To whoever called it [58:05] Whenever they call it [58:07] Call back [58:09] Is a piece of syntactic icing [58:13] Which [58:14] Actually expands to something else entirely [58:17] It is what we call a macro in C [58:20] And we'll look at those little bit later on when I dive into this windows at age 5 [58:23] And basically what it does is it expands [58:26] To some special decorations that are used [58:29] Only in Windows [58:32] Only for this particular Windows called [58:34] And it's decoration [58:36] That tells the Linker [58:38] And the compiler [58:40] The dysfunction is special [58:42] It is a function that must adhere to a special convention [58:46] Because since Windows was not compiled as part of our program and our program is not [58:51] Compile this part of windows [58:53] They will have to agree on how functions are called that makes [58:58] They will have to agree on a [59:00] And we'll talk about that little more when we start to talk about exactly how she actually generates [59:04] Access code [59:05] I think I'll probably be next [59:06] Next [59:07] Xvideo [59:09] So anyway [59:09] Put that in the back of your mind for now but suffice to say this is a special macro that we're going to look at in the future that [59:15] Tells [59:15] The compiler and the Linker [59:17] That this is a special function not like our run-of-the-mill function and then it has certain constraints that have to be met [59:23] Why does the pile [59:24] We then have the parameters to the function the things up a collar provide these are things that are being [59:29] Passenger the function that the function can use [59:31] We didn't use any recent void here [59:34] But women uses [59:35] A few [59:36] A few [59:38] It has access [59:40] The first one is HSN [59:43] Is actually just a handle to ourselves [59:46] What it is it's basically a handle that we can use [59:49] When were talking to windows again if we should do to talk to Windows [59:53] To refer to our running program [59:56] So for example let's say we need to do something that is very window specific everyone knows their service ever going to ask the windows car [60:02] Hey we need you to do something to a running executable [60:06] We need you to tell us about the memory this using we're going to we're going to access Addie bookkeeper [60:10] Reducing stuff [60:11] And where specifically referencing [60:13] This copy our copy in memory of our executable code [60:18] That is what this handled does [60:20] Is a handle that a lot that we can pass back to Windows to refer to ourselves [60:24] Turns out you don't really need to [60:26] Actually remember this or use it for [60:29] Because most the time you can get if I back down [60:31] I will cover that way [60:32] Free Vincent you can completely ignore is Legacy thing [60:36] You will never need it in game programming is basically something [60:40] That you needed to use in older versions of Windows sometimes [60:43] In order to do things [60:45] That had to do with previous runs of your programmer things like this [60:48] Previous versions of your program that we're running in memory [60:51] This right here [60:54] Much like this string [60:56] But we created this [60:57] This is the first time you've actually printed store [61:00] Miss LP store LP command line [61:03] Is basically [61:04] What [61:05] Got sent to us [61:06] When We Were Young [61:08] No [61:09] The interesting thing about that [61:10] Is although it's called LP command line [61:13] It is referring to it as if we're going to call something from a command line [61:17] Which we have not talked about yet and you may have no idea what it is [61:20] But [61:21] I will show you briefly [61:22] What it actually is if you go into [61:24] All programs [61:25] You can go to a thing [61:27] Call accessories and in accessories [61:29] There is a command prompt [61:32] If you go to that you will get this thing [61:34] This is a command line and we will be talking about how to use it later [61:38] But what allows you to do is it allows you to run things like I can run notepad for example from it [61:44] He loves you to run things and you can pass [61:46] Stuff to them on fear that they will receive [61:49] Nekros I tried to pass that if you like I don't know what you're talking about cuz notepad doesn't [61:54] Want to hear any of that [61:55] But when you look at this you'll think of LT command line [61:58] Well [61:59] I don't need that cuz my things not going to be called from the command line and we just talked about the brave genius episode [62:04] The fact that [62:05] We're not going to be building a console application or command line application [62:08] So I don't care about that well not exactly true [62:10] If you go in here [62:12] And you open up something let's say [62:15] Notepad itself [62:16] Can I go to property [62:17] You will notice [62:19] But there's a bunch of stuff in here [62:21] Well this target line [62:22] Simon Says Target [62:25] It actually allows you to put the command line after [62:29] So it's entirely possible to shift Windows programs [62:31] Are not run from the command line it will never be no one will ever run them there [62:36] It's still take a command line [62:38] And so it's important to know that that's there [62:41] I know there's other ways to get that [62:43] We'll talk about [62:46] And finally [62:47] Anchorman show [62:48] It's basically a parameter [62:50] But just back again [62:51] To this disorder properties [62:54] I don't even know if it [62:56] Still there [62:57] I'm just going to see if it is [63:01] Vans [63:02] No [63:03] Teeth [63:04] Hotels compare [63:05] Purity [63:07] I don't know what that is [63:12] Can you list it for legacy reasons no almost no one ever uses [63:15] Best butt [63:16] There's still a drop-down that says whether you want to run a particular application minimize or maximize or just in the normal window [63:23] So that it would open [63:24] If it wasn't told to do anything specific well [63:26] That gets passed to you right [63:28] Shear n Comanche [63:30] And that is basically a number [63:32] That corresponds [63:34] To which of those things was selected and we'll look at that in [63:37] In a little more detail later it's not exciting but you know [63:40] Might as well if they're [63:42] Play me those are things that we are passing me start up and then we have another function body just like we had up here [63:47] And we call function just like this. A function in that function is our road [63:51] And it does apathy books [63:53] That is [63:54] A complete C program [63:56] With a function calling it even [63:57] But that you don't quite know everything about because there's things in here [64:01] Dinner [64:02] Define dusk [64:03] And so the question becomes [64:05] Well [64:06] You know if I was to do this [64:09] Far Western just run that [64:12] You will notice that I couldn't do it [64:14] Because it says [64:15] Who identify was not [64:17] Found [64:18] Cuz I deleted [64:19] That from my program [64:21] And [64:22] When we get to the [64:24] Welcome [64:25] I should mention weather thing [64:27] You may wonder if this point [64:29] Since there was no Foo why wasn't that a linker-error instead of a compilation error [64:34] This is the compilation there remember I said in the past the Linker is the thing [64:37] That gathers things up into one [64:40] Peace so that they can essentially be [64:44] Taken [64:45] And and made into and have their references sorted [64:49] We combined all point to each other in the proper way [64:52] You would think of that era would come then right [64:55] Why does it come drink compilation [64:56] Because it should have come at the step when people try to resolve reference as well the reason for that [65:01] Iams this is actually a good thing to bring up [65:03] I'm happy that [65:05] Better that I remember that [65:07] What are the reasons [65:09] But that happens is because C [65:11] And C plus plus are languages in which you are never allowed to use something which has not been defined yet [65:18] NC [65:19] There were looser restrictions on this [65:21] And so it some things and see would work even if you didn't [65:24] Define Minuet in C plus plus date [65:26] Titans that down they tighten the ratchet on that [65:28] So you always have to find things before they are called [65:31] Since this isn't defined it can't be called [65:33] Now that many leaves you wondering if you can't [65:38] If you can't actually [65:40] Call something unless it's [65:42] Define well how are there ever unresolved external symbols [65:47] The answer to that [65:48] Issy allows you to do what's called a forward declaration [65:52] Functions are split into two parts essentially [65:54] They are split [65:55] Into a declaration [65:57] And the definition [65:59] Now definition is the full thing [66:02] It's the full function [66:03] It has the Prototype and it's got the body so it actually is the thing that you need [66:07] If you want to run it [66:09] But you could instead make just what's called a declaration and a declaration [66:13] Looks like this [66:15] It is the first [66:29] Don't you just love the pretty green, [66:31] They're so lovely [66:32] Anyway [66:34] Inside here [66:35] We basically have the same exact stuff that we had here [66:38] But instead of it actually [66:41] Providing the body it just [66:43] Put the semicolon and ends if they still use that I'm done [66:46] Semicolon marker to say I'm not actually tell you the body [66:49] I'm just going to tell you the signature [66:51] And [66:52] Once you have that signature [66:54] You will see that I can actually build [66:56] And you will notice that now or compile error has become a link error [67:00] And the reason I care is because now it's legal to call the function during compilation [67:05] And it the compiler will just assume [67:08] That since it has all the information used to call the function which is the signature knows what it needs to pass it knows what it will get back [67:14] It just goes ahead and does [67:16] The compilation that started to [67:17] Producer call and leaves [67:19] Essentially marker that it says hey [67:21] Linker [67:22] When you find this function [67:24] Please pass it in here because I would like to call it [67:27] All right [67:30] This is quite via the laryngitis seducing [67:34] Stream I'm going to have to talk quieter [67:36] Anyway [67:39] So [67:41] We actually fully defined our funk [67:43] So we have a fully buildable program [67:45] But [67:46] Could find this function [67:48] And for that matter you to find me this stuff [67:51] You'll notice that these things in blue [67:53] They're automatically being syntax highlighted by [67:56] Visual Studio [67:58] Bee stings in blue [67:59] They are keywords they're built into the [68:01] Tyler you can actually type these in [68:03] Alongside the brackets [68:04] The semicolons the parentheses [68:06] These are part of the language [68:08] They will work anywhere they will work on any c compiler that you ever want to use [68:13] But all this stuff [68:14] Where did that come from that's not mistaken power units is not turning blue is not a keyword [68:18] I can tell you that [68:21] And neither is this guy [68:22] And we need to find that function somewhere to come from [68:25] The answer is [68:27] Vista find that phone [68:28] So we're going to get to the last line here [68:30] And then we're going to wrap it up [68:32] For tonight because I want to try to keep these two roughly an hour [68:34] And we are about an hour [68:37] So [68:39] Okay [68:40] This is a line which says [68:42] I want you to go find this [68:44] File [68:45] Is actually a file name [68:47] It could have a complete path if you want [68:50] Whatever [68:51] It could be out the full on [68:53] In anything any filename you want to put in there [68:55] Although in general [68:56] Most the time you use for its lashes even though you're on Windows because forward slashes work for includes no matter where you are [69:03] Where is backslash enjoying working windows with us [69:06] Hey play think it's a filename any phylum a drive you can include and really all it means [69:12] For all intensive purposes [69:14] Is go get this file [69:17] Inspect the entire contents of it [69:19] Right here [69:20] I'm so this essentially makes [69:22] Are very simple program [69:24] That's only a dozen or so lines long [69:26] It actually makes this a very long program [69:29] Cuz it goes and [69:30] What's this file [69:33] I should tell you how to do that [69:34] If you right click on one [69:35] And knows where to find it you can go open document and it will jump right to that file [69:40] I just got a nice [69:42] So this is Windows. 8 [69:44] Which is the file that we included [69:45] Let me not look like much [69:47] It may look like a bunch of gobbledygook but relatively minor gobbledygook if not [69:51] It's absolutely massive [69:52] And the reason for that [69:54] If it's all just a bunch of more includes [69:56] That's going to include this [69:58] Right it's going to go down here [70:00] And it's going to include [70:01] This [70:02] And it's going to include [70:04] All of these things [70:06] Right [70:06] Who knows [70:07] You got to go interpret all the crazy stuff I don't even know what it's including [70:10] And all those things include more things happening things [70:14] Have included them as well this one includes this one [70:17] So there is a huge nightmare [70:19] Amazon closes with this Alexis I don't actually needs to be open but [70:23] Anyway [70:25] Pound including this town and close Windows 8 foot pounds includes all kinds of stuff [70:29] From the operating system [70:31] Include files [70:33] And those include files are designed [70:35] To Define [70:37] A bunch of functions like these [70:38] That you used interface with Windows and a bunch of special macros [70:42] And types of other things that will get into next week [70:45] That are designed for you to be able to read [70:47] Steve information [70:49] From Windows as well [70:50] And so [70:51] That [70:51] Define this [70:53] That is hard to find [70:54] All of these things [70:55] And that is why this is a complete program [70:57] Cuz without it it would not be [70:59] Orange [71:01] No I think that's a good place to stop [71:03] Because the next step here is we're going to start to look [71:06] At exactly how this program works [71:08] I'm going to step into the Assembly Language it was actually generated [71:11] We're going to look at how linking actually works [71:13] Where talk about the C runtime Library [71:15] And [71:16] We're going to look at why I said Win Maine [71:19] With actually a little bit [71:21] Of a of a [71:23] Misdirection [71:24] Why it's not really the entry point for your program [71:27] Even though I said it was going to be [71:29] Went to the program and it sure seems to have been the end [71:33] All that [71:35] We will get to tomorrow I believe [71:37] As we [71:38] Further continue [71:40] Our introduction [71:41] 2 C programming on Windows [71:43] I hope you have enjoyed this [71:44] Stream [71:45] And I am going to stop the recording now [71:48] But [71:49] I will continue to take questions [71:51] On the [71:53] On the live stream [71:54] And I will split those [71:56] Into a [71:57] A separate record