winsock error returned from socket(AF_INET...

I am trying to write a simple DLL that opens a socket
to a Unix machine.  The routine keeps returning
10047 (notsupported) from the connect call.  Actually
I think it's coming from the socket call. TCP is up
on the LAN and all my other apps work great.  Can
anyone see my problem?

__declspec (dllexport) void _stdcall
woe_init (long *out1, long *out2)
      SOCKET H = socket(PF_INET,SOCK_STREAM,0);
      struct sockaddr_in sock;
      sock.sin_addr.s_addr = inet_addr("");

      int u=0,y=0;
      *out1 = WSAGetLastError();
      *out2 = WSAGetLastError();
Who is Participating?
tflaiConnect With a Mentor Commented:
I believe you forgot this line:
sock.sin_family = PF_INET;

timothynelsonAuthor Commented:
Obvious... if I only checked my Unix code!

Do I also need to worry about WSAStartUp???

Thanks for the quick reply, I'll be giving you the points.

Yes, you should call WSAStartUp. It initializes the winsock dll.
if you do not call it, the socket-functions is likely to behave
unpredictably. Furthermore WSAGetLastError() should defenitly not work.
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 0 );//which version do you need
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
    /* Tell the user that we couldn't find a usable */
    /* WinSock DLL.                                  */    return;

if ( LOBYTE( wsaData.wVersion ) != 2 ||HIBYTE(wsaData.wVersion ) != 0 ) //which version is available

WSACleanup( );
struct WSAData {
WORD wVersion;    
WORD wHighVersion;
char szDescription[WSADESCRIPTION_LEN+1];
char szSystemStatus[WSASYSSTATUS_LEN+1];
unsigned short iMaxSockets;
unsigned short iMaxUdpDg;
char FAR *lpVendorInfo;};
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.