zhuang@linux:~/reading/programming-windows/01-getting-started/$ less
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:
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:
| Type | copy code to exe |
|---|---|
.lib(import) | ❌ not copy |
.lib(static) | ✅ copy |
.dll | loading when running time |
Windows Dynamic Linking:
Compilation Stage
- The compiler checks function declarations from header files.
Linking Stage
- The linker resolves external symbols using import libraries (.lib).
- DLL dependencies are recorded in the executable.
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