我正在开发一个使用 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 theWSAIoctl
function with theSIO_GET_EXTENSION_FUNCTION_POINTER
opcode specified. The input buffer passed to theWSAIoctl
function must containWSAID_DISCONNECTEX
, a globally unique identifier (GUID) whose value identifies theDisconnectEx
extension function. On success, the output returned by theWSAIoctl
function contains a pointer to theDisconnectEx
function. TheWSAID_DISCONNECTEX
GUID is defined in theMswsock.h
header file.
请注意,DisconnectEx()
的 MSDN 文档未在“要求”部分指定库。这意味着您必须在运行时通过 WSAIoctl()
function 动态加载此函数。获取函数指针。
关于c++ - Windows API : Undefined reference to DisconnectEx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7155698/