Johanne Irish
Johanne Irish

Reputation: 1063

SDK for VC++ 2010?

I'm still attempting to do something with networking, and instead of using Beej's tutorial, I turned to MSDN.com. It says I need to include "Ws32_32.lib" as a library. I cannot find this library, and I believe it is with the VS 2010 SDK. I DLed the SDK, and it only works with the professional or ultimate or something. Maybe I've just answered my own question here but, is there a way to actually use windows sockets with VS express? I understand professional or ultimate cost exorbitant sums of money (because they're made for businesses, I'm just a single novice/hobbyist). Is there any way to use windows sockets with VS express?

Maybe I should just turn to codeblocks or QT...

Upvotes: 1

Views: 1138

Answers (2)

Abhijit-K
Abhijit-K

Reputation: 3679

The winsock library is Ws2_32.LIB, is windows socket dll linking lib. You will find this in Microsoft SDK lib folder. In my case it is at C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib. The Visual studio already should know this path. IF you simple specify this lib in the linker options(linker -> Input -> Additional libs )then you are actually implicitly linking the the system winsock dll Ws2_32.dll. You can also use #pragma comment(lib, "ws2_32.lib")

The SDK is not directly related to the version of Visual studio like professional, ultimate. You should be able to work with SDK even from command line or express edition of VS2010. SDk can be installed independent of Visual studio. If your visual studio is not able to find the path of SDK lib then you need to check settings. With VS2010 in project settings in configuration there is a option for VC++ Directories. There on right hand side you will see "Library Directories" check if SDK lib is specified there. Check the macro for $(WindowsSdkDir)lib.

Upvotes: 0

Blastfurnace
Blastfurnace

Reputation: 18652

Have you looked at the MSDN Getting Started with Winsock guide? The provided sample code works for me with plain Visual C++ 2010 Express. This snippet compiles cleanly and the #pragma tells the linker which library is needed.

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

// link with Ws2_32.lib
#pragma comment(lib, "Ws2_32.lib")

int main()
{
    WSADATA wsaData;

    // Initialize Winsock
    int result = WSAStartup(MAKEWORD(2, 2), &wsaData);
    if (result != 0) {
        printf("WSAStartup failed: %d\n", result);
        return 1;
    }

    // Your code here

    WSACleanup();
    return 0;
}

Upvotes: 1

Related Questions