Visual C ++程序抱怨net框架

时间:2013-03-22 11:37:42

标签: c++ visual-c++ winsock

我在Visual C ++ 2010中编写了一个简单的客户端程序,它使用winsock连接到客户端。当我尝试在另一台计算机上运行该程序时,它抱怨缺少Net Framework。 我想知道为什么会这样呢?我的代码中需要net framework的是什么?

错误消息:

  

应用程序,必须先安装以下版本之一   .NET Framework v4.0等等

这是我的代码

#pragma once
#pragma comment(lib, "Ws2_32.lib")

#include "stdafx.h"
#include <sdkddkver.h>
#include <WinSock2.h>
#include <Windows.h>
#include <iostream>
#include <string>
#include <time.h>
#include <cstring>
#include <sstream>

#define SCK_VERSION2 0x020

using namespace std;

void main() {
long Successful;
WSAData WinSockData;
WORD DLLVersion;
DLLVersion = MAKEWORD(2,1);
Successful = WSAStartup(DLLVersion, &WinSockData);
int sd,rcv,i,myint = 1;

hostent *host = gethostbyname("localhost");
char * myhostadd = inet_ntoa (*((struct in_addr *) host->h_addr_list[0]));

string memzi2,memzi,Converter;
char Message[200],tell[200] = "haa";

SOCKADDR_IN Address;

SOCKET sock;
sock = socket(AF_INET,SOCK_STREAM,NULL);

Address.sin_addr.s_addr = inet_addr(myhostadd);
Address.sin_family = AF_INET;
Address.sin_port = htons(7177);

cout << "Connecting to server...";
Successful = connect(sock, (SOCKADDR*)&Address, sizeof(Address));
u_long iMode=1;
ioctlsocket(sock,FIONBIO,&iMode);

if (Successful == 0) {
    cout << "Connected. "<< endl;

    for (;;++i) {
            std::stringstream convert2;
            convert2 << myint;
            memzi2 = convert2.str();
            std::cout << "Client: " << memzi2 << std::endl;
            const char * c = memzi2.c_str();

        sd = send(sock, c, sizeof(tell), NULL);
        cout << "Server: ";
        rcv = recv(sock,Message,sizeof(Message),NULL);
        Converter = Message;
        cout << Converter << endl;

        std::stringstream convert1(Converter);
        convert1 >> myint;
        if (myint > 5000) {
        myint = 1;
        }
        ++myint;

    }

        closesocket(sock);

}
else cout << "Failed." << endl;         

cout << "\n\n\t";
system("pause");
exit(1);
}

提前致谢!

1 个答案:

答案 0 :(得分:1)

可能是一个简单的原因,它将使用C ++ CLI,即公共语言运行库。转到项目属性并进行修复,它将不再显示。