This repository has been archived by the owner on Jul 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwin32includes.h
61 lines (48 loc) · 1.64 KB
/
win32includes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#pragma once
#pragma comment(lib, "Ws2_32.lib") // this indicates the WinSock2 DLL is needed
#pragma comment(lib, "gdiplus.lib") // this indicates the GDI+ DLL is needed
#pragma comment(lib, "IPHLPAPI.lib") // this indicates the IP Helper API DLL is needed
#define NOMINMAX // disable Min/Max macros in minwindef.h (included transitively below)
// WinSock2 must be first, to prevent the inclusion of
// WinSock1. Both cannot coexist.
#include <WinSock2.h>
#include <iphlpapi.h> // this must be after WinSock2.h
#include <WS2tcpip.h>
#include <mstcpip.h>
#include <Windows.h>
#include <gdiplus.h>
#include <KnownFolders.h>
#include <ShlObj.h>
#pragma region Library Helpers
static inline int Winsock2Startup() {
WORD winsockVersion = MAKEWORD(2, 2); // version 2.2
WSADATA winsockData;
int socketStartupCode = WSAStartup(winsockVersion, &winsockData);
if (socketStartupCode != 0) {
return -1; // start failed
}
if (winsockData.wVersion != winsockVersion) {
return 1; // bad version
}
return 0;
}
static inline void Winsock2Shutdown() {
WSACleanup();
}
static inline int GdiPlusStartup(ULONG_PTR* tokenOut) {
if (tokenOut == nullptr) {
throw "Null tokenOut pointer received in GdiPlusStartup";
}
Gdiplus::GdiplusStartupInput startupInfo;
Gdiplus::Status startStatus = Gdiplus::GdiplusStartup(tokenOut, &startupInfo, nullptr);
if (startStatus != Gdiplus::Status::Ok) {
return 1;
}
// this is important for image capture to obtain the entire screen
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
return 0;
}
static inline void GdiPlusShutdown(ULONG_PTR token) {
Gdiplus::GdiplusShutdown(token);
}
#pragma endregion