我正在编写一个使用cpp、套接字、json和winsock2在服务器和客户端之间创建连接的项目,我正在使用winsock2.h中的函数WSAStartup来启动连接。我从互联网上的代码中复制了它的使用方式,它工作了一段时间,直到突然MAKEWORD函数产生了一个错误。
这是我在其中使用的函数:(Communicator,RequestHandelerFactory和m_handlerFactory是我创建的类,忽略它)
Communicator::Communicator(RequestHandelerFactory* RHF) : m_handlerFactory(RHF)
{
WSADATA wsa_data = {};
if (WSAStartup(MAKEWORD(2, 2), &wsa_data) != 0)
{
throw std::exception("wsa startup failed");
}
std::cout << "Starting..." << std::endl;
_serverSocket = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (_serverSocket == INVALID_SOCKET)
{
throw std::exception(__FUNCTION__ " - socket");
}
}我使用的include和定义如下:
#pragma warning(disable : 4996)
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <WinSock2.h>
#include <WS2tcpip.h>
#include <stdio.h>
#include <sstream>
#include <bitset>
#include <exception>
#include <minwindef.h>
#include <windef.h>
#include <ctime>
//some more includes from code I wrote
#pragma comment (lib, "ws2_32.lib")错误出现在MAKEWORD函数中,无论我做什么,它仍然给出相同的错误。
E0109 expression preceding parentheses of apparent call must have (pointer-to-) function type我使用的是Visual Studio 2017,如果有什么变化的话。我试着用很多方法来解决这个问题,似乎都不起作用。
发布于 2019-06-30 02:16:20
问题是在我的代码之前使用define。谢谢您:)
https://stackoverflow.com/questions/56807352
复制相似问题