类型重定义错误(使用标头保护)

时间:2017-10-08 18:58:05

标签: c++ redefinition

免责声明: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(仅限标题部分):

#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

正如您所看到的,我在任何地方都使用了标头防护装置,但是我得到了这些错误。似乎包含&#34; Windows.h&#34;?

存在问题

提前致谢!

修改 我猜这个问题与libjpegturbo处理&#34; Windows.h&#34;的包含方式有关。目前我没有办法解决这个问题。也许即时尝试在一个单独的DLL中导出我需要的功能...希望这将解决它。

1 个答案:

答案 0 :(得分:0)

经典问题。

只需从NetClient.h

中删除此行即可
#include <Windows.h>

包含<Winsock2.h&gt;将为您提供<windows.h>并更正所有重新定义的问题。

相关问题