Reputation: 131
For example, to call MessageBox all I need is to include windows.h, so I assume some header file does the actual LoadLibrary.
How does this work?
Upvotes: 2
Views: 1710
Reputation: 613013
The Windows header file that declares MessageBox
declares it but does not define it. In other words, the header file merely declares that there is a function with a particular prototype that is defined somewhere else.
The definition is provided by an import library. For MessageBox
, that import library is user32.lib
. That import library is passed to the linker and provides the definition.
The actually loading of the Windows DLL that implements MessageBox
, user32.dll is done by the loader. The linker emits an executable file that contains metadata declaring the dependent DLLs, and the functions that must be imported. That's the PE import table. At process load time, the loader reads the import table, loads dependent DLLs, and resolves the references.
Upvotes: 8