Getting Started

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:

[ .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:

Type copy code to exe
.lib(import) ❌ not copy
.lib(static) ✅ copy
.dll loading when running time

Windows Dynamic Linking:

  1. Compilation Stage
  2. The compiler checks function declarations from header files.

  3. Linking Stage

  4. The linker resolves external symbols using import libraries (.lib).
  5. DLL dependencies are recorded in the executable.

  6. Runtime Stage

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

Hello, World

#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:

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

原文链接:https://zhuang.dev/reading/programming-windows/01-getting-started/

posted @ 2026-07-12 22:50  neozhuang  阅读(4)  评论(0)    收藏  举报