Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4123228
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:35:04+00:00 2026-05-20T23:35:04+00:00

I am porting linux app under win32 (msvc 9.0) and after finally finishing it,

  • 0

I am porting linux app under win32 (msvc 9.0) and after finally finishing it, I’m experiencing non-default behavior on simple things as socket().

#include <winsock2.h>
#include <ws2tcpip.h>

int main(int argc, char **argv)
{
    int subsock;
    if ((subsock = socket(PF_INET, SOCK_STREAM, 0)) < 0 ) { 
        printf("Failed to open socket (ret value = %d)\n", subsock);
    }
}

This prints Failed to open socket (ret value = -1) every time. What is wrong and how to open socket on win32?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T23:35:05+00:00Added an answer on May 20, 2026 at 11:35 pm

    You need to call WSAStartup to initialize winsock before subsequent socket calls will succeed.

    WORD wVersionRequested;
    WSADATA wsaData;
    int err;
    
    /* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */
    wVersionRequested = MAKEWORD(2, 2);
    err = WSAStartup(wVersionRequested, &wsaData)
    if (err != 0)
    {
        YourError!
    }
    else
    {
        // success
    }
    

    For more details:

    http://msdn.microsoft.com/en-us/library/ms742213%28VS.85%29.aspx

    Just request version 2.2 and be done with it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently porting a program developed on Linux to Win32. Amongst other problems,
The article Porting Qt for Embedded Linux to Another Operating System lists five things
In porting a big app from a Windows to Linux, I need to be
I'm porting an app i've been working on from Linux to Mac and i'm
I'm trying to learn Ada on Linux by porting simple C++ tools to Ada.
I am porting a app/PCI driver from vxWorks to Linux and I would like
I'm porting a multi-thread application from Win32 to Linux. In Win32 we use SetThreadIdealProcessor
I am porting my application to windows from Linux. I am fairly new to
I'm porting a small C++ console application from windows to linux, GCC 4.3.2. When
I'm working on porting a windows-only application to Linux, and eventually to Mac OSX.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.