zhuang@linux:~/reading/programming-windows/01-getting-started/$ less

Programming Windows / chapter 01

Getting Started

$ grep tags 01-getting-started.md

This post extracts some knowledge from Programming Windows Chapter 1 – Getting Started.

Dynamic Linking

The complete process from code to execution when creating a Windows program that dynamic link library file:

plaintext
[ .c/.cpp ]
[ Compile ]
[ .obj ]
[ Link ]
   │ │
   │ └── using import library (.lib)
   │                ↓
   │      providing DLL name + function symbol
[ .exe ]
[ running time Load ]
[ loading DLL (.dll) ]
[ provoke real function ]

Dynamic link vs Static link:

Typecopy code to exe
.lib(import)❌ not copy
.lib(static)✅ copy
.dllloading when running time

Windows Dynamic Linking:

  1. Compilation Stage

    • The compiler checks function declarations from header files.
  2. Linking Stage

    • The linker resolves external symbols using import libraries (.lib).
    • DLL dependencies are recorded in the executable.
  3. Runtime Stage

    • The Windows loader loads the required DLLs.
    • Imported functions are bound to their actual addresses.
    • Function calls are dispatched to implementations inside the DLLs.

Hello, World

c
#include <windows.h>

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
     MessageBox (NULL, TEXT ("Hello, Windows 98!"), TEXT ("HelloMsg"), 0) ;
     return 0 ;
}

WinMain declaration as follows:

c
int WINAPI WinMain(
    HINSTANCE hInstance,      // current instance
    HINSTANCE hPrevInstance,  // previous instance
    LPSTR lpCmdLine,          // point to command line 
    INT nCmdShow              // the status of show window
);

zhuang@linux:~/reading/programming-windows/01-getting-started/$ comments