add WSAStartup() for Windows
Stefan Schuermans

Stefan Schuermans commited on 2017-10-28 20:23:07
Showing 5 changed files, with 130 additions and 0 deletions.

... ...
@@ -17,6 +17,7 @@
17 17
 #include "OpPrinter.h"
18 18
 #include "OpSplitter.h"
19 19
 #include "Output.h"
20
+#include "PlatformInit.h"
20 21
 #include "Player.h"
21 22
 #include "Printer.h"
22 23
 #include "Priority.h"
... ...
@@ -86,6 +87,8 @@ int main(int argc, const char *argv[])
86 87
   }
87 88
   dirConfig = argv[1];
88 89
 
90
+  PlatformInit pfInit();
91
+
89 92
   run(dirConfig);
90 93
 
91 94
   return 0;
... ...
@@ -0,0 +1,25 @@
1
+/* Blinker
2
+   Copyright 2011-2014 Stefan Schuermans <stefan@blinkenarea.org>
3
+   Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
4
+   a blinkenarea.org project */
5
+
6
+#include "PlatformInit.h"
7
+
8
+namespace Blinker {
9
+
10
+/**
11
+ * @brief constructor
12
+ */
13
+PlatformInit::PlatformInit()
14
+{
15
+}
16
+
17
+/**
18
+ * @brief destructor
19
+ */
20
+PlatformInit::~PlatformInit()
21
+{
22
+}
23
+
24
+} // namespace Blinker
25
+
... ...
@@ -0,0 +1,29 @@
1
+/* Blinker
2
+   Copyright 2011-2014 Stefan Schuermans <stefan@blinkenarea.org>
3
+   Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
4
+   a blinkenarea.org project */
5
+
6
+#ifndef BLINKER_PLATFORMINIT_H
7
+#define BLINKER_PLATFORMINIT_H
8
+
9
+namespace Blinker {
10
+
11
+/// initialization and cleanup on a platform
12
+class PlatformInit
13
+{
14
+public:
15
+  /**
16
+   * @brief constructor
17
+   */
18
+  PlatformInit();
19
+
20
+  /**
21
+   * @brief destructor
22
+   */
23
+  ~PlatformInit();
24
+}; // class PlatformInit
25
+
26
+} // namespace Blinker
27
+
28
+#endif // #ifndef BLINKER_PLATFORMINIT_H
29
+
... ...
@@ -0,0 +1,44 @@
1
+/* Blinker
2
+   Copyright 2011-2014 Stefan Schuermans <stefan@blinkenarea.org>
3
+   Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
4
+   a blinkenarea.org project */
5
+
6
+#include <winsock2.h>
7
+
8
+#include <iostream>
9
+#include <stdlib.h>
10
+
11
+#include "PlatformInit.h"
12
+
13
+namespace Blinker {
14
+
15
+/**
16
+ * @brief constructor
17
+ */
18
+PlatformInit::PlatformInit()
19
+{
20
+  WORD wVersionRequested = MAKEWORD(2, 2);
21
+  WSADATA wsaData;
22
+  int err = WSAStartup(wVersionRequested, &wsaData);
23
+  if (err != 0) {
24
+    std::cerr << "WSAStartup((2, 2), ...) failed" << std::endl;
25
+    exit(1);
26
+  }
27
+  if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
28
+    std::cerr << "WSAStartup((2, 2), ...) returned ("
29
+              << LOBYTE(wsaData.wVersion) << ", "
30
+              << HIBYTE(wsaData.wVersion) << ")" << std::endl;
31
+    exit(1);
32
+  }
33
+}
34
+
35
+/**
36
+ * @brief destructor
37
+ */
38
+PlatformInit::~PlatformInit()
39
+{
40
+  WSACleanup();
41
+}
42
+
43
+} // namespace Blinker
44
+
... ...
@@ -0,0 +1,29 @@
1
+/* Blinker
2
+   Copyright 2011-2014 Stefan Schuermans <stefan@blinkenarea.org>
3
+   Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
4
+   a blinkenarea.org project */
5
+
6
+#ifndef BLINKER_PLATFORMINIT_H
7
+#define BLINKER_PLATFORMINIT_H
8
+
9
+namespace Blinker {
10
+
11
+/// initialization and cleanup on a platform
12
+class PlatformInit
13
+{
14
+public:
15
+  /**
16
+   * @brief constructor
17
+   */
18
+  PlatformInit();
19
+
20
+  /**
21
+   * @brief destructor
22
+   */
23
+  ~PlatformInit();
24
+}; // class PlatformInit
25
+
26
+} // namespace Blinker
27
+
28
+#endif // #ifndef BLINKER_PLATFORMINIT_H
29
+
0 30