I have a simple small question which someone who knows will be able to answer easily, I searched google but couldn't find the answer.
There are many programs running at once on a computer, and my question is: when a program loads a DLL, does it actually load the DLL file or does it find the memory in which the DLL is already loaded? For example, is ws2_32.dll (winsock 2) loaded for every program that uses winsock, or is it loaded once and all programs that use it use the same memory addresses to call the functions?
It's loaded once and all programs share the same in-memory copy of code. It's kind of complicated, but for the read-only sections of the DLL (that is, code) the operating system loader uses a technique called "memory mapping" to map the DLL into the process's address space. The pages are only loaded into physical memory once for all processes, even though they may have the page mapped to different address in their virtual address space.
However, each process has a separate data section (so that global variables are not shared - unless you explicitly ask them to be) and they obviously also have a separate heap so that dynamically-allocated memory is not shared.
It depends on what you mean by "loaded".
The DLL is prepared for shared use of code and data: most Windows environments honor the shareability (by mapping the same memory copy of the code into each process's memory space) to conserve memory.
However, part of the "load" operation (from a process's point of view) is running the DLL's initialization: that is done separately in each process with distinct copies of the data areas which are private to each process.