user2263786
user2263786

Reputation: 131

Which header file loads the DLLs in Win32 api?

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

Answers (1)

David Heffernan
David Heffernan

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

Related Questions