gpt4 book ai didi

c++ - 如何使用Winsock 2?

转载 作者:太空宇宙 更新时间:2023-11-04 14:43:01 24 4
gpt4 key购买 nike

我如何在 Visual Studio 2008 中使用 Windows Sockets 2。我使用的是预编译 header ,到目前为止我尝试过的是:

  1. 在我的StdAfx.h 文件中包含winsock2.h
  2. 并在项目设置中输入WS2_32.LIB 作为附加依赖

我得到这些错误

------ Build started: Project: TestIVR, Configuration: Debug Win32 ------
Compiling...
main.cpp
c:\documents and settings\hussain\my documents\visual studio 2008\projects\testivr\testivr\main.cpp(30) : error C2065: 'WSAEVENT' : undeclared identifier
c:\documents and settings\hussain\my documents\visual studio 2008\projects\testivr\testivr\main.cpp(30) : error C2146: syntax error : missing ';' before identifier 'socketEvent'
c:\documents and settings\hussain\my documents\visual studio 2008\projects\testivr\testivr\main.cpp(30) : error C2065: 'socketEvent' : undeclared identifier
c:\documents and settings\hussain\my documents\visual studio 2008\projects\testivr\testivr\main.cpp(35) : error C2039: 'S_addr' : is not a member of 'in_addr'
c:\program files\microsoft sdks\windows\v6.0a\include\inaddr.h(22) : see declaration of 'in_addr'
c:\documents and settings\hussain\my documents\visual studio 2008\projects\testivr\testivr\main.cpp(40) : error C2065: 'socketEvent' : undeclared identifier
c:\documents and settings\hussain\my documents\visual studio 2008\projects\testivr\testivr\main.cpp(40) : error C3861: 'WSAEventSelect': identifier not found
Build log was saved at "file://c:\Documents and Settings\Hussain\My Documents\Visual Studio 2008\Projects\TestIVR\TestIVR\Debug\BuildLog.htm"
TestIVR - 6 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

顺便说一句,如果我在我的 ma​​in.cpp(我的 main() 函数所在的位置)中包含 winsock2.h,那么我会得到不同的错误

------ Build started: Project: TestIVR, Configuration: Debug Win32 ------
Compiling...
main.cpp
c:\documents and settings\hussain\my documents\visual studio 2008\projects\testivr\testivr\main.cpp(36) : error C2039: 'S_addr' : is not a member of 'in_addr'
c:\program files\microsoft sdks\windows\v6.0a\include\inaddr.h(22) : see declaration of 'in_addr'
Build log was saved at "file://c:\Documents and Settings\Hussain\My Documents\Visual Studio 2008\Projects\TestIVR\TestIVR\Debug\BuildLog.htm"
TestIVR - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

以下是我的StdAfx.h头文件的内容

#pragma once

#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include <winsock2.h>

最佳答案

您的 in_addr 问题是由 in_addr 中没有 S_addr 字段这一事实引起的。有一个 in_addr.s_addr 重定向到 in_addr.S_un.S_addr。

关于c++ - 如何使用Winsock 2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1321731/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com