免責聲明:C++ Redefinition Header Files (winsock2.h)犯規解決我的問題類型重定義錯誤(用頭衛兵)
在這個項目中,我嘗試採取截圖,然後用libjpeg的渦輪增壓壓縮它。問題是,我得到這樣的錯誤
"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(只有頭部分):
#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
正如你看到的,我使用的標題 - 警衛無處不在,但儘管如此我得到這些錯誤。似乎包含「Windows.h」有問題?
在此先感謝!
編輯 我想這個問題與libjpegturbo處理包括「Windows.h」的方式有關。目前我沒有解決這個問題的真正方法。也許即時嘗試導出我需要在一個單獨的DLL中的功能......希望這將解決它。
可能重複的[C++重定義頭文件(winsock2.h)](https://stackoverflow.com/questions/1372480/c-redefinition-header-files-winsock2-h) – user2672165
已經看到了這個線程,但沒有爲那裏的問題找到了解決方案。 – StillWaters77