C++ (non MFC projects): Change the settings to multithreaded (go to project->settings, choose c++, and on the category tab select "code generation", change the runtime library to "debug multithreaded" (or just multithreaded if it's the release version)
Link: add ws2_32.lib to the input list (link settings)
Make sure you have the following includes (preferred in the precompiled headers):
#include <winsock2.h>
#include <windows.h>