Platform: Windows: Avoid windows.h

This way Windows.h doesn't pollute everything with random defines
This commit is contained in:
Paul Hollinsky
2022-02-28 19:12:35 -05:00
parent caf5cca42f
commit 453d3366af
8 changed files with 90 additions and 70 deletions
+1 -13
View File
@@ -1,19 +1,7 @@
#ifndef __DYNAMICLIB_WINDOWS_H_
#define __DYNAMICLIB_WINDOWS_H_
#define NOMINMAX
#ifndef WIN32_LEAN_AND_MEAN
#define LAM_DEFINED
#define WIN32_LEAN_AND_MEAN
#endif
#include <Windows.h>
#ifdef LAM_DEFINED
#undef LAM_DEFINED
#undef WIN32_LEAN_AND_MEAN
#endif
#undef NOMINMAX
#undef near
#undef far
#include "icsneo/platform/windows/windows.h"
#ifdef ICSNEOC_MAKEDLL
#define DLLExport __declspec(dllexport)
@@ -3,8 +3,7 @@
#ifdef __cplusplus
#include <Windows.h>
#include <winsock2.h>
#include "icsneo/platform/windows/windows.h"
#include <pcap.h>
#include <memory>
@@ -3,7 +3,6 @@
#ifdef __cplusplus
#include <Windows.h>
#include <string>
#include <vector>
@@ -20,17 +19,6 @@ public:
// Get DWORD value
static bool Get(std::wstring path, std::wstring key, uint32_t& value);
static bool Get(std::string path, std::string key, uint32_t& value);
private:
class Key {
public:
Key(std::wstring path, bool readwrite = false);
~Key();
HKEY GetKey() { return key; }
bool IsOpen() { return key != nullptr; }
private:
HKEY key;
};
};
}
+6 -11
View File
@@ -8,7 +8,6 @@
#include <thread>
#include <atomic>
#include <chrono>
#include <Windows.h>
#include "icsneo/device/neodevice.h"
#include "icsneo/communication/driver.h"
#include "icsneo/api/eventmanager.h"
@@ -22,25 +21,21 @@ public:
static bool IsHandleValid(neodevice_handle_t handle);
typedef void(*fn_boolCallback)(bool success);
VCP(const device_eventhandler_t& err, neodevice_t& forDevice) : Driver(err), device(forDevice) {
overlappedRead.hEvent = INVALID_HANDLE_VALUE;
overlappedWrite.hEvent = INVALID_HANDLE_VALUE;
overlappedWait.hEvent = INVALID_HANDLE_VALUE;
}
VCP(const device_eventhandler_t& err, neodevice_t& forDevice);
~VCP() { close(); }
bool open() { return open(false); }
void openAsync(fn_boolCallback callback);
bool close();
bool isOpen() { return handle != INVALID_HANDLE_VALUE; }
bool isOpen();
private:
bool open(bool fromAsync);
bool opening = false;
neodevice_t& device;
HANDLE handle = INVALID_HANDLE_VALUE;
OVERLAPPED overlappedRead = {};
OVERLAPPED overlappedWrite = {};
OVERLAPPED overlappedWait = {};
struct Detail;
std::shared_ptr<Detail> detail;
std::vector<std::shared_ptr<std::thread>> threads;
void readTask();
void writeTask();
+13
View File
@@ -0,0 +1,13 @@
// Include Windows.h with as few annoying defines as possible
#define NOMINMAX
#ifndef WIN32_LEAN_AND_MEAN
#define LAM_DEFINED
#define WIN32_LEAN_AND_MEAN
#endif
#include <Windows.h>
#ifdef LAM_DEFINED
#undef LAM_DEFINED
#undef WIN32_LEAN_AND_MEAN
#endif
#undef NOMINMAX