What is the relationship between the Windows API and the C run time library?
views:
496answers:
6If you mean the standard C library (msvcrt.dll I assume). Then not much at all. The majority of the windows API is implemented in separate dlls (very much of it is in user32.dll or kernel32.dll). In fact, some of these functions in the Windows API are just thin wrappers around system calls where the actual work is done in the kernel itself.
Also, as ocdecio said, it is entirely reasonable to assume that certain parts of the C standard library are implemented using windows APIs. And for certain cases like string manipulations, vice versa.
EDIT: since which dlls are implemented in terms of others has come into question, i've checked with dependancy walker and here is my findings:
kernel32.dll depends on:
ntdll.dll
user32.dll depends on:
gdi32.dll
kernel32
ntdll.dll
advapi.dll
msimg32.dll
powerprof.dll (this dll references msvcrt.dll for some string functions)
winsta.dll
msvcrt.dll depends on:
kernel32.dll (yes it does have imports for CreateFileA)
ntdll.dll
based off of this, I believe that msvcrt is build on top of the win32 API.
In a nutshell: The Windows API contains all the functions defined specifically for Windows. The C run-time library contains all the functions that are required by standard C.
The physical libraries that implement these functions may be a single file (library), split across two separate libraries or split into many libraries, depending on the operating system and the actual API/service you are using.
For example, when creating files, the C standard includes the function:
fopen
to open and create files, etc., while the Win32 API (for example) defines functions like:
CreateFile
to create and manipulate files. The first one will be available wherever a standard C run-time library is available while the second one will only be available on a Windows machine that supports the Win32 API.
Win32 is a completely different beast to the CRT.
CRT is something that needs to be linked into your project when you use C or C++ functions/features (such as printf or cout).
Win32 is a set of libraries that need to be linked into your project when you use Windows features (like GetWindowText).
What they are:
- The Windows API is the API exported by the Microsoft Windows[TM] Operating System
- The C run time library is the "standard library" which is shipped with the C compiler by the compiler vendor, and which is available on whichever/any operating system (for example, Unix) is targetted by the compiler
What their relationship is:
- They are distinct, but both equally available to C++ applications running on Windows
- On Windows, the C standard library is implemented by invoking the underlying Windows API (to allocate memory, open files, etc.).