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 157659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:32:36+00:00 2026-05-11T10:32:36+00:00

#include stdafx.h #include <windows.h> #include <winsock.h> #include <stdio.h> int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR IpCmdLine,int

  • 0
#include 'stdafx.h' #include <windows.h> #include <winsock.h> #include <stdio.h>  int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR IpCmdLine,int nCmdShow) {     WSADATA ws;     char buf[100];      WSAStartup(0x0101,&ws);      sprintf(buf,'%d.%d',HIBYTE(ws.wVersion),LOBYTE(ws.wVersion));     MessageBox(0,buf,'info',0);     WSACleanup();     return 0; } 

This program is for getting information of available wsock version in the computer. I cannot understand why ‘stdafx.h’ is included in program. What’s the significance of APIENTRY? Can’t we use _stdcall instead? I also can’t compile it in VC++. What’s the problem with the code?

Below are the errors when executing program there are no errors during compiling.

--------------------Configuration: sa - Win32 Debug-------------------- Linking... sa.obj : error LNK2001: unresolved external symbol _WSACleanup@0 sa.obj : error LNK2001: unresolved external symbol _WSAStartup@8 LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main Debug/sa.exe : fatal error LNK1120: 3 unresolved externals Error executing link.exe.  sa.exe - 4 error(s), 0 warning(s) 
  • 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. 2026-05-11T10:32:36+00:00Added an answer on May 11, 2026 at 10:32 am
    1. stdafx is used to implement precompiled headers in VC++. You can put your library headers like windows.h and winsock.h, etc.. in there and they will only be compiled once each time you modify stdafx.h.

    2. APIENTRY is usually just a define for __stdcall, but sometimes it is defined blank (if __stdcall is not supported for example). It’s to make your code more portable.

    3. Without the actual errors you are getting, I’m not going to be able to help much. But my first guess is that you have unicode on in your build and it’s complaining that MessageBoxW doesn’t take a char[100] as an argument. In this case, either use wide chars everywhere, or turn off unicode, or use MessageBoxA to explicitly use the ASCII version.

    Edit:

    Now with the errors, it’s easy. Under Project properties -> Linker -> Input -> Additional Dependencies, add ws2_32.lib. So you can get the Winsock functions linked in.

    The missing _main indicates that you are building the app as a console app, and not a windows app. Go back to project Properties -> Linker -> System and set SubSystem to Windows (/Subsystem:Windows) instead of Console. Or else, just rename WinMain to int main() (Make sure you drop the APIENTRY).

    Also, if you’re using MSVC++ you might as well use the safer sprintf_s:

    sprintf_s(buf,100,'%d.%d',HIBYTE(ws.wVersion),LOBYTE(ws.wVersion)); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you running on OS 3.0? I saw the same… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer It looks like you need to register Apache::Session::Memcached with Apache::Session::Wrapper,… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Use DATENAME or DATEPART: SELECT DATENAME(dw,GETDATE()) -- Friday SELECT DATEPART(dw,GETDATE())… May 12, 2026 at 1:19 am

Related Questions

Some time ago I wrote a little piece of code to ask about on
I need to work with array from several threads, so I use CRITICAL SECTION
Today is officially my first day with C++ :P I've downloaded Visual C++ 2005
I am writing an application that needs to send data over a network. I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.