short question.
When I do:
#include <windows.h>
CreateProcess(..)
How does the header file knows to connect me to the correct dll?
Is there a dictionary inside those header files that maps each win32api function to the relevant dll?
The headers only contain declarations for the API functions, not their definitions. The definitions are found by linking the appropriate libraries.
For example, copy the following into a .c
file:
#include <Windows.h>
int main()
{
MessageBoxW(NULL, L"Hello World", L"", MB_OK);
return 0;
}
Try to compile it on the Visual Studio Command Prompt with the command cl example.c
. You will see the error message:
example.obj : error LNK2019: unresolved external symbol __imp__MessageBoxW@16 referenced in function _main
Note that compilation itself actually succeeds; it's the linker that complains about the missing function definition.
If you instead compile it with cl example.c /link user32.lib
, the linker will find the definition for MessageBox
. You could also just link example.obj user32.lib
.
So, to answer your question: the headers don't need to know which DLLs the functions are in because the project is required to provide the appropriate library references. Fortunately, the MSDN documentation for Windows API functions will tell you which DLL the function is in and which library to link.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With