本文介绍了其中ConnectEx界定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Windows7的使用ConnectEx功能,具有MSVC2010。

I want to use ConnectEx function on Windows7, with MSVC2010.

我收到错误C3861:'ConnectEx':标识符找不到

I am getting error C3861: 'ConnectEx': identifier not found

MSDN暗示的作用应该mswsock.h声明,然而,检​​查的话,它是没有定义。

MSDN suggests the function should be declared in mswsock.h, however, when checking it, it's not defined there.

任何提示?

推荐答案

如果你还读入的你提到的,它说:

If you read further into the MSDN article for ConnectEx() you mentioned, it says:

注意作为 ConnectEx 必须获得函数的函数指针
  在通过向功能
   SIO_GET_EXTENSION_FUNCTION_POINTER 运code指定。输入缓冲器
  传递给函数的WSAIoctl必须包含 WSAID_CONNECTEX ,一
  全局唯一标识符(GUID)值标识的 ConnectEx
  扩展功能。如果成功,由的WSAIoctl 返回的输出
  函数包含一个指向 ConnectEx 功能。该
   WSAID_CONNECTEX GUID中定义的 Mswsock.h 的头文件。

不像其他的Windows API函数, ConnectEx()必须在运行时加载,因为头文件实际上并不包含函数声明ConnectEx()(它确实有一个的typedef 用于调用的函数 LPFN_CONNECTEX )和文档没有明确提及您必须链接到为了这个工作(这通常是其他Windows API函数的情况下)特定库。

Unlike other Windows API functions, ConnectEx() must be loaded at runtime, as the header file doesn't actually contain a function declaration for ConnectEx() (it does have a typedef for the function called LPFN_CONNECTEX) and the documentation doesn't specifically mention a specific library that you must link to in order for this to work (which is usually the case for other Windows API functions).

下面是一个如何得到这个工作(错误检查省略博览会)的例子:

Here's an example of how one could get this to work (error-checking omitted for exposition):

#include <Winsock2.h> // Must be included before Mswsock.h
#include <Mswsock.h>

// Required if you haven't specified this library for the linker yet
#pragma comment(lib, "Ws2_32.lib")

/* ... */

SOCKET s = /* ... */;
DWORD numBytes = 0;
GUID guid = WSAID_CONNECTEX;
LPFN_CONNECTEX ConnectExPtr = NULL;
int success = ::WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER,
    (void*)&guid, sizeof(guid), (void*)&ConnectExPtr, sizeof(ConnectExPtr),
    &numBytes, NULL, NULL);
// Check WSAGetLastError()!

/* ... */

// Assuming the pointer isn't NULL, you can call it with the correct parameters.
ConnectExPtr(s, name, namelen, lpSendBuffer,
    dwSendDataLength, lpdwBytesSent, lpOverlapped);

这篇关于其中ConnectEx界定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 00:51