c++ - Windows API : Undefined reference to DisconnectEx

标签 c++ c winapi mingw winsock

我正在开发一个使用 Windows 套接字的应用程序。我的套接字类有一个名为 Disconnect 的方法,它使用 DisconnectEx,但我在链接时收到以下错误:

undefined reference to `DisconnectEx@16'

我正在使用 MinGW 并将我的应用程序与以下库链接:

-lws2_32 -lwsock32 -lmswsock

在msdn上说这个功能需要的最低版本是Windows XP或Windows Server 2003,所以我用0x0502定义了WINVER,但我仍然得到同样的错误。

我在这里缺少什么?

提前致谢!

最佳答案

您显然错过了 DisconnectEx() function 的 MSDN 文档中的这条注释:

Note: The function pointer for the DisconnectEx function must be obtained at run time by making a call to the WSAIoctl function with the SIO_GET_EXTENSION_FUNCTION_POINTER opcode specified. The input buffer passed to the WSAIoctl function must contain WSAID_DISCONNECTEX, a globally unique identifier (GUID) whose value identifies the DisconnectEx extension function. On success, the output returned by the WSAIoctl function contains a pointer to the DisconnectEx function. The WSAID_DISCONNECTEX GUID is defined in the Mswsock.h header file.

请注意,DisconnectEx() 的 MSDN 文档未在“要求”部分指定库。这意味着您必须在运行时通过 WSAIoctl()function 动态加载此函数。获取函数指针。

关于c++ - Windows API : Undefined reference to DisconnectEx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7155698/

相关文章:

c++ - 即使在混合后也想要透明图像

C++ 显示一个字符串

c - 使用指针从另一个编译单元访问和更改静态变量

c - 在命令行上创建然后链接到 Win32 DLL 的确切步骤是什么?

c++ - 使用 makefile 在 OS X 上编译 SDL

c++ - 使用 CMake 静态链接到项目外部的库

c++ - 链接错误、未解析的符号 QString、QComboBox、QSlider、QAbstractButton、QRadioButton、

Cuda内核没有并发运行

c++ - 我如何在 delphi 中定义 IOCTL_ATA_PASS_THROUGH?

Windows 事件日志 : How fast are operations with it?