【发布时间】:2017-10-08 18:58:05
【问题描述】:
免责声明:C++ Redefinition Header Files (winsock2.h) 没有解决我的问题
在这个项目中,我尝试截取屏幕截图,然后使用 libjpeg-turbo 对其进行压缩。问题是我收到类似的错误
"sockaddr": "struct" Type redefinition
和
"nothl": Redefinition
ScreenWorker.h:
#pragma once
#ifndef SCREENWORKER_H
#define SCREENWORKER_H
#include <string>
#include <vector>
#include <thread>
#include <turbojpeg.h>
#include <Windows.h>
#include "..\API\NetClient.h"
class ScreenWorker {
private:
NetClient* client;
public:
int delay = 30;
ScreenWorker(NetClient* client);
HBITMAP GetScreenBmp(HDC hdc);
void Update();
};
#endif
ScreenWorker.cpp:
#include "ScreenWorker.h"
ScreenWorker::ScreenWorker(NetClient* client) {
this->client = client;
Update();
}
HBITMAP ScreenWorker::GetScreenBmp(HDC hdc) {...}
void ScreenWorker::Update() {...}
main.cpp(DLL-Entry):
#pragma once
#include "..\..\Base\API\API\GladOSClient.h"
#include "ScreenWorker.h"
using namespace std;
BOOL WINAPI DllMain(HINSTANCE Instance, DWORD Reason, LPVOID Reserved) {
return true;
}
NetClient.h(仅 Header 部分):
#pragma once
#ifndef NETCLIENT_H
#define NETCLIENT_H
#define _WINSOCKAPI_
#include <Windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <vector>
#include <list>
#include <mutex>
#include <map>
#include <string>
#pragma comment (lib, "Ws2_32.lib")
#pragma comment (lib, "Mswsock.lib")
#pragma comment (lib, "AdvApi32.lib")
#include "Utils.h"
#include "PacketHandler.h"
#include "Packet.h"
...
#endif
如您所见,我到处都在使用 header-guards,但是我还是遇到了这些错误。好像包含“Windows.h”有问题?
提前致谢!
编辑 我猜这个问题与 libjpegturbo 处理“Windows.h”的方式有关。目前我没有真正的方法来解决这个问题。也许我正在尝试将我需要的函数导出到一个单独的 DLL 中......希望这能解决它。
【问题讨论】:
-
已经看到这个帖子,但没有找到解决我的问题的方法。
标签: c++ redefinition