Mental note: If you're using Win32's, link to libpqdll.lib, not
libpq.lib.
When I changed the lib I was linking to, everything worked fine.
Apparently libpq.lib doesn't initialize WinSock, so the gethostbyname()
call wasn't working.
Thanks to everyone for your help.