Browse code

Apply text-removal.sh script to Windows codebase

Change-Id: I8f53c49b885c7c9e36a78ca434ec021e6dc347e0
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20250318172350.20996-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg31159.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Frank Lichtenheld authored on 2025/03/19 02:23:42
Showing 16 changed files
... ...
@@ -32,7 +32,7 @@
32 32
 #pragma comment(lib, "msi.lib")
33 33
 #endif
34 34
 #include <stdio.h>
35
-#include <tchar.h>
35
+#include <wchar.h>
36 36
 
37 37
 
38 38
 DWORD openvpnmsica_thread_data_idx = TLS_OUT_OF_INDEXES;
... ...
@@ -160,13 +160,13 @@ x_msg_va(const unsigned int flags, const char *format, va_list arglist)
160 160
         MsiRecordSetInteger(hRecordProg, 3, dwResult);
161 161
 
162 162
         /* Field 4: The Windows error description. */
163
-        LPTSTR szErrMessage = NULL;
163
+        LPWSTR szErrMessage = NULL;
164 164
         if (FormatMessage(
165 165
                 FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS,
166 166
                 0,
167 167
                 dwResult,
168 168
                 0,
169
-                (LPTSTR)&szErrMessage,
169
+                (LPWSTR)&szErrMessage,
170 170
                 0,
171 171
                 NULL) && szErrMessage)
172 172
         {
... ...
@@ -175,7 +175,7 @@ x_msg_va(const unsigned int flags, const char *format, va_list arglist)
175 175
             {
176 176
                 if (szErrMessage[i])
177 177
                 {
178
-                    if (!_istspace(szErrMessage[i]))
178
+                    if (!iswspace(szErrMessage[i]))
179 179
                     {
180 180
                         i_last = i + 1;
181 181
                     }
... ...
@@ -54,9 +54,9 @@ msica_arg_seq_free(_Inout_ struct msica_arg_seq *seq)
54 54
 void
55 55
 msica_arg_seq_add_head(
56 56
     _Inout_ struct msica_arg_seq *seq,
57
-    _In_z_ LPCTSTR argument)
57
+    _In_z_ LPCWSTR argument)
58 58
 {
59
-    size_t argument_size = (_tcslen(argument) + 1) * sizeof(TCHAR);
59
+    size_t argument_size = (wcslen(argument) + 1) * sizeof(WCHAR);
60 60
     struct msica_arg *p = malloc(sizeof(struct msica_arg) + argument_size);
61 61
     if (p == NULL)
62 62
     {
... ...
@@ -75,9 +75,9 @@ msica_arg_seq_add_head(
75 75
 void
76 76
 msica_arg_seq_add_tail(
77 77
     _Inout_ struct msica_arg_seq *seq,
78
-    _Inout_ LPCTSTR argument)
78
+    _Inout_ LPCWSTR argument)
79 79
 {
80
-    size_t argument_size = (_tcslen(argument) + 1) * sizeof(TCHAR);
80
+    size_t argument_size = (wcslen(argument) + 1) * sizeof(WCHAR);
81 81
     struct msica_arg *p = malloc(sizeof(struct msica_arg) + argument_size);
82 82
     if (p == NULL)
83 83
     {
... ...
@@ -90,19 +90,19 @@ msica_arg_seq_add_tail(
90 90
 }
91 91
 
92 92
 
93
-LPTSTR
93
+LPWSTR
94 94
 msica_arg_seq_join(_In_ const struct msica_arg_seq *seq)
95 95
 {
96 96
     /* Count required space. */
97 97
     size_t size = 2 /*x + zero-terminator*/;
98 98
     for (struct msica_arg *p = seq->head; p != NULL; p = p->next)
99 99
     {
100
-        size += _tcslen(p->val) + 1 /*space delimiter|zero-terminator*/;
100
+        size += wcslen(p->val) + 1 /*space delimiter|zero-terminator*/;
101 101
     }
102
-    size *= sizeof(TCHAR);
102
+    size *= sizeof(WCHAR);
103 103
 
104 104
     /* Allocate. */
105
-    LPTSTR str = malloc(size);
105
+    LPWSTR str = malloc(size);
106 106
     if (str == NULL)
107 107
     {
108 108
         msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, size);
... ...
@@ -115,18 +115,18 @@ msica_arg_seq_join(_In_ const struct msica_arg_seq *seq)
115 115
 #endif
116 116
 
117 117
     /* Dummy argv[0] (i.e. executable name), for CommandLineToArgvW to work correctly when parsing this string. */
118
-    _tcscpy(str, TEXT("x"));
118
+    wcscpy(str, L"x");
119 119
 
120 120
     /* Join. */
121
-    LPTSTR s = str + 1 /*x*/;
121
+    LPWSTR s = str + 1 /*x*/;
122 122
     for (struct msica_arg *p = seq->head; p != NULL; p = p->next)
123 123
     {
124 124
         /* Convert zero-terminator into space delimiter. */
125
-        s[0] = TEXT(' ');
125
+        s[0] = L' ';
126 126
         s++;
127 127
         /* Append argument. */
128
-        _tcscpy(s, p->val);
129
-        s += _tcslen(p->val);
128
+        wcscpy(s, p->val);
129
+        s += wcslen(p->val);
130 130
     }
131 131
 
132 132
 #ifdef _MSC_VER
... ...
@@ -22,7 +22,7 @@
22 22
 #define MSICA_ARG_H
23 23
 
24 24
 #include <windows.h>
25
-#include <tchar.h>
25
+#include <wchar.h>
26 26
 #include "../tapctl/basic.h"
27 27
 
28 28
 
... ...
@@ -38,7 +38,7 @@
38 38
 struct msica_arg
39 39
 {
40 40
     struct msica_arg *next; /**< Pointer to the next argument in the sequence */
41
-    TCHAR val[];            /**< Zero terminated argument string */
41
+    WCHAR val[];            /**< Zero terminated argument string */
42 42
 };
43 43
 
44 44
 
... ...
@@ -80,7 +80,7 @@ msica_arg_seq_free(_Inout_ struct msica_arg_seq *seq);
80 80
 void
81 81
 msica_arg_seq_add_head(
82 82
     _Inout_ struct msica_arg_seq *seq,
83
-    _In_z_ LPCTSTR argument);
83
+    _In_z_ LPCWSTR argument);
84 84
 
85 85
 
86 86
 /**
... ...
@@ -93,7 +93,7 @@ msica_arg_seq_add_head(
93 93
 void
94 94
 msica_arg_seq_add_tail(
95 95
     _Inout_ struct msica_arg_seq *seq,
96
-    _Inout_ LPCTSTR argument);
96
+    _Inout_ LPCWSTR argument);
97 97
 
98 98
 /**
99 99
  * Join arguments of the argument sequence into a space delimited string
... ...
@@ -102,7 +102,7 @@ msica_arg_seq_add_tail(
102 102
  *
103 103
  * @return Joined argument string. Must be released with free() after use.
104 104
  */
105
-LPTSTR
105
+LPWSTR
106 106
 msica_arg_seq_join(_In_ const struct msica_arg_seq *seq);
107 107
 
108 108
 #ifdef _MSC_VER
... ...
@@ -37,8 +37,8 @@
37 37
 UINT
38 38
 msi_get_string(
39 39
     _In_ MSIHANDLE hInstall,
40
-    _In_z_ LPCTSTR szName,
41
-    _Out_ LPTSTR *pszValue)
40
+    _In_z_ LPCWSTR szName,
41
+    _Out_ LPWSTR *pszValue)
42 42
 {
43 43
     if (pszValue == NULL)
44 44
     {
... ...
@@ -46,29 +46,29 @@ msi_get_string(
46 46
     }
47 47
 
48 48
     /* Try with stack buffer first. */
49
-    TCHAR szBufStack[128];
49
+    WCHAR szBufStack[128];
50 50
     DWORD dwLength = _countof(szBufStack);
51 51
     UINT uiResult = MsiGetProperty(hInstall, szName, szBufStack, &dwLength);
52 52
     if (uiResult == ERROR_SUCCESS)
53 53
     {
54 54
         /* Copy from stack. */
55
-        *pszValue = (LPTSTR)malloc(++dwLength * sizeof(TCHAR));
55
+        *pszValue = (LPWSTR)malloc(++dwLength * sizeof(WCHAR));
56 56
         if (*pszValue == NULL)
57 57
         {
58
-            msg(M_FATAL, "%s: malloc(%u) failed", dwLength * sizeof(TCHAR));
58
+            msg(M_FATAL, "%s: malloc(%u) failed", dwLength * sizeof(WCHAR));
59 59
             return ERROR_OUTOFMEMORY;
60 60
         }
61 61
 
62
-        memcpy(*pszValue, szBufStack, dwLength * sizeof(TCHAR));
62
+        memcpy(*pszValue, szBufStack, dwLength * sizeof(WCHAR));
63 63
         return ERROR_SUCCESS;
64 64
     }
65 65
     else if (uiResult == ERROR_MORE_DATA)
66 66
     {
67 67
         /* Allocate on heap and retry. */
68
-        LPTSTR szBufHeap = (LPTSTR)malloc(++dwLength * sizeof(TCHAR));
68
+        LPWSTR szBufHeap = (LPWSTR)malloc(++dwLength * sizeof(WCHAR));
69 69
         if (szBufHeap == NULL)
70 70
         {
71
-            msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, dwLength * sizeof(TCHAR));
71
+            msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, dwLength * sizeof(WCHAR));
72 72
             return ERROR_OUTOFMEMORY;
73 73
         }
74 74
 
... ...
@@ -96,7 +96,7 @@ UINT
96 96
 msi_get_record_string(
97 97
     _In_ MSIHANDLE hRecord,
98 98
     _In_ unsigned int iField,
99
-    _Out_ LPTSTR *pszValue)
99
+    _Out_ LPWSTR *pszValue)
100 100
 {
101 101
     if (pszValue == NULL)
102 102
     {
... ...
@@ -104,29 +104,29 @@ msi_get_record_string(
104 104
     }
105 105
 
106 106
     /* Try with stack buffer first. */
107
-    TCHAR szBufStack[128];
107
+    WCHAR szBufStack[128];
108 108
     DWORD dwLength = _countof(szBufStack);
109 109
     UINT uiResult = MsiRecordGetString(hRecord, iField, szBufStack, &dwLength);
110 110
     if (uiResult == ERROR_SUCCESS)
111 111
     {
112 112
         /* Copy from stack. */
113
-        *pszValue = (LPTSTR)malloc(++dwLength * sizeof(TCHAR));
113
+        *pszValue = (LPWSTR)malloc(++dwLength * sizeof(WCHAR));
114 114
         if (*pszValue == NULL)
115 115
         {
116
-            msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, dwLength * sizeof(TCHAR));
116
+            msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, dwLength * sizeof(WCHAR));
117 117
             return ERROR_OUTOFMEMORY;
118 118
         }
119 119
 
120
-        memcpy(*pszValue, szBufStack, dwLength * sizeof(TCHAR));
120
+        memcpy(*pszValue, szBufStack, dwLength * sizeof(WCHAR));
121 121
         return ERROR_SUCCESS;
122 122
     }
123 123
     else if (uiResult == ERROR_MORE_DATA)
124 124
     {
125 125
         /* Allocate on heap and retry. */
126
-        LPTSTR szBufHeap = (LPTSTR)malloc(++dwLength * sizeof(TCHAR));
126
+        LPWSTR szBufHeap = (LPWSTR)malloc(++dwLength * sizeof(WCHAR));
127 127
         if (szBufHeap == NULL)
128 128
         {
129
-            msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, dwLength * sizeof(TCHAR));
129
+            msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, dwLength * sizeof(WCHAR));
130 130
             return ERROR_OUTOFMEMORY;
131 131
         }
132 132
 
... ...
@@ -154,7 +154,7 @@ UINT
154 154
 msi_format_record(
155 155
     _In_ MSIHANDLE hInstall,
156 156
     _In_ MSIHANDLE hRecord,
157
-    _Out_ LPTSTR *pszValue)
157
+    _Out_ LPWSTR *pszValue)
158 158
 {
159 159
     if (pszValue == NULL)
160 160
     {
... ...
@@ -162,29 +162,29 @@ msi_format_record(
162 162
     }
163 163
 
164 164
     /* Try with stack buffer first. */
165
-    TCHAR szBufStack[128];
165
+    WCHAR szBufStack[128];
166 166
     DWORD dwLength = _countof(szBufStack);
167 167
     UINT uiResult = MsiFormatRecord(hInstall, hRecord, szBufStack, &dwLength);
168 168
     if (uiResult == ERROR_SUCCESS)
169 169
     {
170 170
         /* Copy from stack. */
171
-        *pszValue = (LPTSTR)malloc(++dwLength * sizeof(TCHAR));
171
+        *pszValue = (LPWSTR)malloc(++dwLength * sizeof(WCHAR));
172 172
         if (*pszValue == NULL)
173 173
         {
174
-            msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, dwLength * sizeof(TCHAR));
174
+            msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, dwLength * sizeof(WCHAR));
175 175
             return ERROR_OUTOFMEMORY;
176 176
         }
177 177
 
178
-        memcpy(*pszValue, szBufStack, dwLength * sizeof(TCHAR));
178
+        memcpy(*pszValue, szBufStack, dwLength * sizeof(WCHAR));
179 179
         return ERROR_SUCCESS;
180 180
     }
181 181
     else if (uiResult == ERROR_MORE_DATA)
182 182
     {
183 183
         /* Allocate on heap and retry. */
184
-        LPTSTR szBufHeap = (LPTSTR)malloc(++dwLength * sizeof(TCHAR));
184
+        LPWSTR szBufHeap = (LPWSTR)malloc(++dwLength * sizeof(WCHAR));
185 185
         if (szBufHeap == NULL)
186 186
         {
187
-            msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, dwLength * sizeof(TCHAR));
187
+            msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, dwLength * sizeof(WCHAR));
188 188
             return ERROR_OUTOFMEMORY;
189 189
         }
190 190
 
... ...
@@ -213,7 +213,7 @@ msi_format_field(
213 213
     _In_ MSIHANDLE hInstall,
214 214
     _In_ MSIHANDLE hRecord,
215 215
     _In_ unsigned int iField,
216
-    _Out_ LPTSTR *pszValue)
216
+    _Out_ LPWSTR *pszValue)
217 217
 {
218 218
     if (pszValue == NULL)
219 219
     {
... ...
@@ -221,7 +221,7 @@ msi_format_field(
221 221
     }
222 222
 
223 223
     /* Read string to format. */
224
-    LPTSTR szValue = NULL;
224
+    LPWSTR szValue = NULL;
225 225
     UINT uiResult = msi_get_record_string(hRecord, iField, &szValue);
226 226
     if (uiResult != ERROR_SUCCESS)
227 227
     {
... ...
@@ -41,8 +41,8 @@
41 41
 UINT
42 42
 msi_get_string(
43 43
     _In_ MSIHANDLE hInstall,
44
-    _In_z_ LPCTSTR szName,
45
-    _Out_ LPTSTR *pszValue);
44
+    _In_z_ LPCWSTR szName,
45
+    _Out_ LPWSTR *pszValue);
46 46
 
47 47
 
48 48
 /**
... ...
@@ -61,7 +61,7 @@ UINT
61 61
 msi_get_record_string(
62 62
     _In_ MSIHANDLE hRecord,
63 63
     _In_ unsigned int iField,
64
-    _Out_ LPTSTR *pszValue);
64
+    _Out_ LPWSTR *pszValue);
65 65
 
66 66
 
67 67
 /**
... ...
@@ -83,7 +83,7 @@ UINT
83 83
 msi_format_record(
84 84
     _In_ MSIHANDLE hInstall,
85 85
     _In_ MSIHANDLE hRecord,
86
-    _Out_ LPTSTR *pszValue);
86
+    _Out_ LPWSTR *pszValue);
87 87
 
88 88
 
89 89
 /**
... ...
@@ -107,6 +107,6 @@ msi_format_field(
107 107
     _In_ MSIHANDLE hInstall,
108 108
     _In_ MSIHANDLE hRecord,
109 109
     _In_ unsigned int iField,
110
-    _Out_ LPTSTR *pszValue);
110
+    _Out_ LPWSTR *pszValue);
111 111
 
112 112
 #endif /* ifndef MSIHLP_H */
... ...
@@ -40,7 +40,7 @@
40 40
 #include <shlwapi.h>
41 41
 #include <stdbool.h>
42 42
 #include <stdlib.h>
43
-#include <tchar.h>
43
+#include <wchar.h>
44 44
 #include <setupapi.h>
45 45
 #include <newdev.h>
46 46
 #include <initguid.h>
... ...
@@ -80,11 +80,11 @@
80 80
 static UINT
81 81
 setup_sequence(
82 82
     _In_ MSIHANDLE hInstall,
83
-    _In_z_ LPCTSTR szProperty,
83
+    _In_z_ LPCWSTR szProperty,
84 84
     _In_ struct msica_arg_seq *seq)
85 85
 {
86 86
     UINT uiResult;
87
-    LPTSTR szSequence = msica_arg_seq_join(seq);
87
+    LPWSTR szSequence = msica_arg_seq_join(seq);
88 88
     uiResult = MsiSetProperty(hInstall, szProperty, szSequence);
89 89
     free(szSequence);
90 90
     if (uiResult != ERROR_SUCCESS)
... ...
@@ -92,7 +92,7 @@ setup_sequence(
92 92
         /* MSDN does not mention MsiSetProperty() to set GetLastError(). But we do have an error
93 93
          * code. Set last error manually. */
94 94
         SetLastError(uiResult);
95
-        msg(M_NONFATAL | M_ERRNO, "%s: MsiSetProperty(\"%" PRIsLPTSTR "\") failed", __FUNCTION__, szProperty);
95
+        msg(M_NONFATAL | M_ERRNO, "%s: MsiSetProperty(\"%ls\") failed", __FUNCTION__, szProperty);
96 96
         return uiResult;
97 97
     }
98 98
     return ERROR_SUCCESS;
... ...
@@ -111,27 +111,27 @@ setup_sequence(
111 111
 static void
112 112
 _debug_popup(_In_z_ LPCSTR szFunctionName)
113 113
 {
114
-    TCHAR szTitle[0x100], szMessage[0x100+MAX_PATH], szProcessPath[MAX_PATH];
114
+    WCHAR szTitle[0x100], szMessage[0x100+MAX_PATH], szProcessPath[MAX_PATH];
115 115
 
116 116
     /* Compose pop-up title. The dialog title will contain function name to ease the process
117 117
      * locating. Mind that Visual Studio displays window titles on the process list. */
118
-    _stprintf_s(szTitle, _countof(szTitle), TEXT("%hs v%") TEXT(PRIsLPTSTR),
119
-                szFunctionName, TEXT(PACKAGE_VERSION));
118
+    swprintf_s(szTitle, _countof(szTitle), L"%hs v%ls",
119
+               szFunctionName, _L(PACKAGE_VERSION));
120 120
 
121 121
     /* Get process name. */
122 122
     GetModuleFileName(NULL, szProcessPath, _countof(szProcessPath));
123
-    LPCTSTR szProcessName = _tcsrchr(szProcessPath, TEXT('\\'));
123
+    LPCWSTR szProcessName = wcsrchr(szProcessPath, L'\\');
124 124
     szProcessName = szProcessName ? szProcessName + 1 : szProcessPath;
125 125
 
126 126
     /* Compose the pop-up message. */
127
-    _stprintf_s(
127
+    swprintf_s(
128 128
         szMessage, _countof(szMessage),
129
-        TEXT("The %") TEXT(PRIsLPTSTR) TEXT(" process (PID: %u) has started to execute the %hs")
130
-        TEXT(" custom action.\r\n")
131
-        TEXT("\r\n")
132
-        TEXT("If you would like to debug the custom action, attach a debugger to this process and set breakpoints before dismissing this dialog.\r\n")
133
-        TEXT("\r\n")
134
-        TEXT("If you are not debugging this custom action, you can safely ignore this message."),
129
+        L"The %ls process (PID: %u) has started to execute the %hs"
130
+        L" custom action.\r\n"
131
+        L"\r\n"
132
+        L"If you would like to debug the custom action, attach a debugger to this process and set breakpoints before dismissing this dialog.\r\n"
133
+        L"\r\n"
134
+        L"If you are not debugging this custom action, you can safely ignore this message.",
135 135
         szProcessName,
136 136
         GetCurrentProcessId(),
137 137
         szFunctionName);
... ...
@@ -147,9 +147,9 @@ _debug_popup(_In_z_ LPCSTR szFunctionName)
147 147
 static void
148 148
 find_adapters(
149 149
     _In_ MSIHANDLE hInstall,
150
-    _In_z_ LPCTSTR szzHardwareIDs,
151
-    _In_z_ LPCTSTR szAdaptersPropertyName,
152
-    _In_z_ LPCTSTR szActiveAdaptersPropertyName)
150
+    _In_z_ LPCWSTR szzHardwareIDs,
151
+    _In_z_ LPCWSTR szAdaptersPropertyName,
152
+    _In_z_ LPCWSTR szActiveAdaptersPropertyName)
153 153
 {
154 154
     UINT uiResult;
155 155
 
... ...
@@ -207,28 +207,28 @@ find_adapters(
207 207
     }
208 208
 
209 209
     /* Prepare semicolon delimited list of TAP adapter ID(s) and active TAP adapter ID(s). */
210
-    LPTSTR
211
-        szAdapters     = (LPTSTR)malloc(adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR)),
210
+    LPWSTR
211
+        szAdapters     = (LPWSTR)malloc(adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(WCHAR)),
212 212
         szAdaptersTail = szAdapters;
213 213
     if (szAdapters == NULL)
214 214
     {
215
-        msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR));
215
+        msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(WCHAR));
216 216
         uiResult = ERROR_OUTOFMEMORY; goto cleanup_pAdapterAdresses;
217 217
     }
218 218
 
219
-    LPTSTR
220
-        szAdaptersActive     = (LPTSTR)malloc(adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR)),
219
+    LPWSTR
220
+        szAdaptersActive     = (LPWSTR)malloc(adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(WCHAR)),
221 221
         szAdaptersActiveTail = szAdaptersActive;
222 222
     if (szAdaptersActive == NULL)
223 223
     {
224
-        msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR));
224
+        msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(WCHAR));
225 225
         uiResult = ERROR_OUTOFMEMORY; goto cleanup_szAdapters;
226 226
     }
227 227
 
228 228
     for (struct tap_adapter_node *pAdapter = pAdapterList; pAdapter; pAdapter = pAdapter->pNext)
229 229
     {
230 230
         /* exclude adapters created by OpenVPN Connect, since they're removed on Connect uninstallation */
231
-        if (_tcsstr(pAdapter->szName, OPENVPN_CONNECT_ADAPTER_SUBSTR))
231
+        if (wcsstr(pAdapter->szName, OPENVPN_CONNECT_ADAPTER_SUBSTR))
232 232
         {
233 233
             msg(M_WARN, "%s: skip OpenVPN Connect adapter '%ls'", __FUNCTION__, pAdapter->szName);
234 234
             continue;
... ...
@@ -241,9 +241,9 @@ find_adapters(
241 241
         /* Append to the list of TAP adapter ID(s). */
242 242
         if (szAdapters < szAdaptersTail)
243 243
         {
244
-            *(szAdaptersTail++) = TEXT(';');
244
+            *(szAdaptersTail++) = L';';
245 245
         }
246
-        memcpy(szAdaptersTail, szAdapterId, 38 * sizeof(TCHAR));
246
+        memcpy(szAdaptersTail, szAdapterId, 38 * sizeof(WCHAR));
247 247
         szAdaptersTail += 38;
248 248
 
249 249
         /* If this adapter is active (connected), add it to the list of active TAP adapter ID(s). */
... ...
@@ -260,9 +260,9 @@ find_adapters(
260 260
                     /* This TAP adapter is active (connected). */
261 261
                     if (szAdaptersActive < szAdaptersActiveTail)
262 262
                     {
263
-                        *(szAdaptersActiveTail++) = TEXT(';');
263
+                        *(szAdaptersActiveTail++) = L';';
264 264
                     }
265
-                    memcpy(szAdaptersActiveTail, szAdapterId, 38 * sizeof(TCHAR));
265
+                    memcpy(szAdaptersActiveTail, szAdapterId, 38 * sizeof(WCHAR));
266 266
                     szAdaptersActiveTail += 38;
267 267
                 }
268 268
                 break;
... ...
@@ -315,19 +315,19 @@ FindSystemInfo(_In_ MSIHANDLE hInstall)
315 315
 
316 316
     find_adapters(
317 317
         hInstall,
318
-        TEXT("root\\") TEXT(TAP_WIN_COMPONENT_ID) TEXT("\0") TEXT(TAP_WIN_COMPONENT_ID) TEXT("\0"),
319
-        TEXT("TAPWINDOWS6ADAPTERS"),
320
-        TEXT("ACTIVETAPWINDOWS6ADAPTERS"));
318
+        L"root\\" _L(TAP_WIN_COMPONENT_ID) L"\0" _L(TAP_WIN_COMPONENT_ID) L"\0",
319
+        L"TAPWINDOWS6ADAPTERS",
320
+        L"ACTIVETAPWINDOWS6ADAPTERS");
321 321
     find_adapters(
322 322
         hInstall,
323
-        TEXT("Wintun") TEXT("\0"),
324
-        TEXT("WINTUNADAPTERS"),
325
-        TEXT("ACTIVEWINTUNADAPTERS"));
323
+        L"Wintun" L"\0",
324
+        L"WINTUNADAPTERS",
325
+        L"ACTIVEWINTUNADAPTERS");
326 326
     find_adapters(
327 327
         hInstall,
328
-        TEXT("ovpn-dco") TEXT("\0"),
329
-        TEXT("OVPNDCOADAPTERS"),
330
-        TEXT("ACTIVEOVPNDCOADAPTERS"));
328
+        L"ovpn-dco" L"\0",
329
+        L"OVPNDCOADAPTERS",
330
+        L"ACTIVEOVPNDCOADAPTERS");
331 331
 
332 332
     if (bIsCoInitialized)
333 333
     {
... ...
@@ -348,7 +348,7 @@ CloseOpenVPNGUI(_In_ MSIHANDLE hInstall)
348 348
     debug_popup(__FUNCTION__);
349 349
 
350 350
     /* Find OpenVPN GUI window. */
351
-    HWND hWnd = FindWindow(TEXT("OpenVPN-GUI"), NULL);
351
+    HWND hWnd = FindWindow(L"OpenVPN-GUI", NULL);
352 352
     if (hWnd)
353 353
     {
354 354
         /* Ask it to close and wait for 100ms. Unfortunately, this will succeed only for recent OpenVPN GUI that do not run elevated. */
... ...
@@ -382,7 +382,7 @@ StartOpenVPNGUI(_In_ MSIHANDLE hInstall)
382 382
         msg(M_NONFATAL, "%s: MsiCreateRecord failed", __FUNCTION__);
383 383
         goto cleanup_CoInitialize;
384 384
     }
385
-    uiResult = MsiRecordSetString(hRecord, 0, TEXT("\"[#bin.openvpn_gui.exe]\""));
385
+    uiResult = MsiRecordSetString(hRecord, 0, L"\"[#bin.openvpn_gui.exe]\"");
386 386
     if (uiResult != ERROR_SUCCESS)
387 387
     {
388 388
         SetLastError(uiResult); /* MSDN does not mention MsiRecordSetString() to set GetLastError(). But we do have an error code. Set last error manually. */
... ...
@@ -391,17 +391,17 @@ StartOpenVPNGUI(_In_ MSIHANDLE hInstall)
391 391
     }
392 392
 
393 393
     /* Format string. */
394
-    TCHAR szStackBuf[MAX_PATH];
394
+    WCHAR szStackBuf[MAX_PATH];
395 395
     DWORD dwPathSize = _countof(szStackBuf);
396
-    LPTSTR szPath = szStackBuf;
396
+    LPWSTR szPath = szStackBuf;
397 397
     uiResult = MsiFormatRecord(hInstall, hRecord, szPath, &dwPathSize);
398 398
     if (uiResult == ERROR_MORE_DATA)
399 399
     {
400 400
         /* Allocate buffer on heap (+1 for terminator), and retry. */
401
-        szPath = (LPTSTR)malloc((++dwPathSize) * sizeof(TCHAR));
401
+        szPath = (LPWSTR)malloc((++dwPathSize) * sizeof(WCHAR));
402 402
         if (szPath == NULL)
403 403
         {
404
-            msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, dwPathSize * sizeof(TCHAR));
404
+            msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, dwPathSize * sizeof(WCHAR));
405 405
             uiResult = ERROR_OUTOFMEMORY; goto cleanup_MsiCreateRecord;
406 406
         }
407 407
 
... ...
@@ -470,8 +470,8 @@ static DWORD
470 470
 schedule_adapter_create(
471 471
     _Inout_ struct msica_arg_seq *seq,
472 472
     _Inout_opt_ struct msica_arg_seq *seqRollback,
473
-    _In_z_ LPCTSTR szDisplayName,
474
-    _In_z_ LPCTSTR szHardwareId,
473
+    _In_z_ LPCWSTR szDisplayName,
474
+    _In_z_ LPCWSTR szHardwareId,
475 475
     _Inout_ int *iTicks)
476 476
 {
477 477
     /* Get existing network adapters. */
... ...
@@ -488,12 +488,12 @@ schedule_adapter_create(
488 488
         if (pAdapterOther == NULL)
489 489
         {
490 490
             /* No adapter with a same name found. */
491
-            TCHAR szArgument[10 /*create=""|deleteN=""*/ + MAX_PATH /*szDisplayName*/ + 1 /*|*/ + MAX_PATH /*szHardwareId*/ + 1 /*terminator*/];
491
+            WCHAR szArgument[10 /*create=""|deleteN=""*/ + MAX_PATH /*szDisplayName*/ + 1 /*|*/ + MAX_PATH /*szHardwareId*/ + 1 /*terminator*/];
492 492
 
493 493
             /* InstallTUNTAPAdapters will create the adapter. */
494
-            _stprintf_s(
494
+            swprintf_s(
495 495
                 szArgument, _countof(szArgument),
496
-                TEXT("create=\"%.*s|%.*s\""),
496
+                L"create=\"%.*s|%.*s\"",
497 497
                 MAX_PATH, szDisplayName,
498 498
                 MAX_PATH, szHardwareId);
499 499
             msica_arg_seq_add_tail(seq, szArgument);
... ...
@@ -501,9 +501,9 @@ schedule_adapter_create(
501 501
             if (seqRollback)
502 502
             {
503 503
                 /* InstallTUNTAPAdaptersRollback will delete the adapter. */
504
-                _stprintf_s(
504
+                swprintf_s(
505 505
                     szArgument, _countof(szArgument),
506
-                    TEXT("deleteN=\"%.*s\""),
506
+                    L"deleteN=\"%.*s\"",
507 507
                     MAX_PATH, szDisplayName);
508 508
                 msica_arg_seq_add_head(seqRollback, szArgument);
509 509
             }
... ...
@@ -511,19 +511,19 @@ schedule_adapter_create(
511 511
             *iTicks += MSICA_ADAPTER_TICK_SIZE;
512 512
             break;
513 513
         }
514
-        else if (_tcsicmp(szDisplayName, pAdapterOther->szName) == 0)
514
+        else if (wcsicmp(szDisplayName, pAdapterOther->szName) == 0)
515 515
         {
516 516
             /* Adapter with a same name found. */
517
-            for (LPCTSTR hwid = pAdapterOther->szzHardwareIDs;; hwid += _tcslen(hwid) + 1)
517
+            for (LPCWSTR hwid = pAdapterOther->szzHardwareIDs;; hwid += wcslen(hwid) + 1)
518 518
             {
519 519
                 if (hwid[0] == 0)
520 520
                 {
521 521
                     /* This adapter has a different hardware ID. */
522
-                    msg(M_NONFATAL, "%s: Adapter with name \"%" PRIsLPTSTR "\" already exists", __FUNCTION__, pAdapterOther->szName);
522
+                    msg(M_NONFATAL, "%s: Adapter with name \"%ls\" already exists", __FUNCTION__, pAdapterOther->szName);
523 523
                     dwResult = ERROR_ALREADY_EXISTS;
524 524
                     goto cleanup_pAdapterList;
525 525
                 }
526
-                else if (_tcsicmp(hwid, szHardwareId) == 0)
526
+                else if (wcsicmp(hwid, szHardwareId) == 0)
527 527
                 {
528 528
                     /* This is an adapter with the requested hardware ID. We already have what we want! */
529 529
                     break;
... ...
@@ -571,8 +571,8 @@ schedule_adapter_delete(
571 571
     _Inout_ struct msica_arg_seq *seq,
572 572
     _Inout_opt_ struct msica_arg_seq *seqCommit,
573 573
     _Inout_opt_ struct msica_arg_seq *seqRollback,
574
-    _In_z_ LPCTSTR szDisplayName,
575
-    _In_z_ LPCTSTR szzHardwareIDs,
574
+    _In_z_ LPCWSTR szDisplayName,
575
+    _In_z_ LPCWSTR szzHardwareIDs,
576 576
     _Inout_ int *iTicks)
577 577
 {
578 578
     /* Get adapters with given hardware ID. */
... ...
@@ -586,39 +586,39 @@ schedule_adapter_delete(
586 586
     /* Does adapter exist? */
587 587
     for (struct tap_adapter_node *pAdapter = pAdapterList; pAdapter != NULL; pAdapter = pAdapter->pNext)
588 588
     {
589
-        if (_tcsicmp(szDisplayName, pAdapter->szName) == 0)
589
+        if (wcsicmp(szDisplayName, pAdapter->szName) == 0)
590 590
         {
591 591
             /* Adapter found. */
592
-            TCHAR szArgument[8 /*disable=|enable=|delete=*/ + 38 /*{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}*/ + 1 /*terminator*/];
592
+            WCHAR szArgument[8 /*disable=|enable=|delete=*/ + 38 /*{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}*/ + 1 /*terminator*/];
593 593
             if (seqCommit && seqRollback)
594 594
             {
595 595
                 /* UninstallTUNTAPAdapters will disable the adapter. */
596
-                _stprintf_s(
596
+                swprintf_s(
597 597
                     szArgument, _countof(szArgument),
598
-                    TEXT("disable=") TEXT(PRIXGUID),
598
+                    L"disable=" _L(PRIXGUID),
599 599
                     PRIGUID_PARAM(pAdapter->guid));
600 600
                 msica_arg_seq_add_tail(seq, szArgument);
601 601
 
602 602
                 /* UninstallTUNTAPAdaptersRollback will re-enable the adapter. */
603
-                _stprintf_s(
603
+                swprintf_s(
604 604
                     szArgument, _countof(szArgument),
605
-                    TEXT("enable=") TEXT(PRIXGUID),
605
+                    L"enable=" _L(PRIXGUID),
606 606
                     PRIGUID_PARAM(pAdapter->guid));
607 607
                 msica_arg_seq_add_head(seqRollback, szArgument);
608 608
 
609 609
                 /* UninstallTUNTAPAdaptersCommit will delete the adapter. */
610
-                _stprintf_s(
610
+                swprintf_s(
611 611
                     szArgument, _countof(szArgument),
612
-                    TEXT("delete=") TEXT(PRIXGUID),
612
+                    L"delete=" _L(PRIXGUID),
613 613
                     PRIGUID_PARAM(pAdapter->guid));
614 614
                 msica_arg_seq_add_tail(seqCommit, szArgument);
615 615
             }
616 616
             else
617 617
             {
618 618
                 /* UninstallTUNTAPAdapters will delete the adapter. */
619
-                _stprintf_s(
619
+                swprintf_s(
620 620
                     szArgument, _countof(szArgument),
621
-                    TEXT("delete=") TEXT(PRIXGUID),
621
+                    L"delete=" _L(PRIXGUID),
622 622
                     PRIGUID_PARAM(pAdapter->guid));
623 623
                 msica_arg_seq_add_tail(seq, szArgument);
624 624
             }
... ...
@@ -662,7 +662,7 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
662 662
     msica_arg_seq_init(&seqUninstallRollback);
663 663
 
664 664
     /* Check rollback state. */
665
-    bool bRollbackEnabled = MsiEvaluateCondition(hInstall, TEXT("RollbackDisabled")) != MSICONDITION_TRUE;
665
+    bool bRollbackEnabled = MsiEvaluateCondition(hInstall, L"RollbackDisabled") != MSICONDITION_TRUE;
666 666
 
667 667
     /* Open MSI database. */
668 668
     MSIHANDLE hDatabase = MsiGetActiveDatabase(hInstall);
... ...
@@ -674,7 +674,7 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
674 674
     }
675 675
 
676 676
     /* Check if TUNTAPAdapter table exists. If it doesn't exist, there's nothing to do. */
677
-    switch (MsiDatabaseIsTablePersistent(hDatabase, TEXT("TUNTAPAdapter")))
677
+    switch (MsiDatabaseIsTablePersistent(hDatabase, L"TUNTAPAdapter"))
678 678
     {
679 679
         case MSICONDITION_FALSE:
680 680
         case MSICONDITION_TRUE: break;
... ...
@@ -686,12 +686,12 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
686 686
 
687 687
     /* Prepare a query to get a list/view of adapters. */
688 688
     MSIHANDLE hViewST = 0;
689
-    LPCTSTR szQuery = TEXT("SELECT `Adapter`,`DisplayName`,`Condition`,`Component_`,`HardwareId` FROM `TUNTAPAdapter`");
689
+    LPCWSTR szQuery = L"SELECT `Adapter`,`DisplayName`,`Condition`,`Component_`,`HardwareId` FROM `TUNTAPAdapter`";
690 690
     uiResult = MsiDatabaseOpenView(hDatabase, szQuery, &hViewST);
691 691
     if (uiResult != ERROR_SUCCESS)
692 692
     {
693 693
         SetLastError(uiResult); /* MSDN does not mention MsiDatabaseOpenView() to set GetLastError(). But we do have an error code. Set last error manually. */
694
-        msg(M_NONFATAL | M_ERRNO, "%s: MsiDatabaseOpenView(\"%" PRIsLPTSTR "\") failed", __FUNCTION__, szQuery);
694
+        msg(M_NONFATAL | M_ERRNO, "%s: MsiDatabaseOpenView(\"%ls\") failed", __FUNCTION__, szQuery);
695 695
         goto cleanup_hDatabase;
696 696
     }
697 697
 
... ...
@@ -700,7 +700,7 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
700 700
     if (uiResult != ERROR_SUCCESS)
701 701
     {
702 702
         SetLastError(uiResult); /* MSDN does not mention MsiViewExecute() to set GetLastError(). But we do have an error code. Set last error manually. */
703
-        msg(M_NONFATAL | M_ERRNO, "%s: MsiViewExecute(\"%" PRIsLPTSTR "\") failed", __FUNCTION__, szQuery);
703
+        msg(M_NONFATAL | M_ERRNO, "%s: MsiViewExecute(\"%ls\") failed", __FUNCTION__, szQuery);
704 704
         goto cleanup_hViewST;
705 705
     }
706 706
 
... ...
@@ -733,7 +733,7 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
733 733
         INSTALLSTATE iInstalled, iAction;
734 734
         {
735 735
             /* Read adapter component ID (`Component_` is field #4). */
736
-            LPTSTR szValue = NULL;
736
+            LPWSTR szValue = NULL;
737 737
             uiResult = msi_get_record_string(hRecord, 4, &szValue);
738 738
             if (uiResult != ERROR_SUCCESS)
739 739
             {
... ...
@@ -745,7 +745,7 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
745 745
             if (uiResult != ERROR_SUCCESS)
746 746
             {
747 747
                 SetLastError(uiResult); /* MSDN does not mention MsiGetComponentState() to set GetLastError(). But we do have an error code. Set last error manually. */
748
-                msg(M_NONFATAL | M_ERRNO, "%s: MsiGetComponentState(\"%" PRIsLPTSTR "\") failed", __FUNCTION__, szValue);
748
+                msg(M_NONFATAL | M_ERRNO, "%s: MsiGetComponentState(\"%ls\") failed", __FUNCTION__, szValue);
749 749
                 free(szValue);
750 750
                 goto cleanup_hRecord;
751 751
             }
... ...
@@ -753,26 +753,26 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
753 753
         }
754 754
 
755 755
         /* Get adapter display name (`DisplayName` is field #2). */
756
-        LPTSTR szDisplayName = NULL;
756
+        LPWSTR szDisplayName = NULL;
757 757
         uiResult = msi_format_field(hInstall, hRecord, 2, &szDisplayName);
758 758
         if (uiResult != ERROR_SUCCESS)
759 759
         {
760 760
             goto cleanup_hRecord;
761 761
         }
762 762
         /* `DisplayName` field type is [Filename](https://docs.microsoft.com/en-us/windows/win32/msi/filename), which is either "8.3|long name" or "8.3". */
763
-        LPTSTR szDisplayNameEx = _tcschr(szDisplayName, TEXT('|'));
763
+        LPWSTR szDisplayNameEx = wcschr(szDisplayName, L'|');
764 764
         szDisplayNameEx = szDisplayNameEx != NULL ? szDisplayNameEx + 1 : szDisplayName;
765 765
 
766 766
         /* Get adapter hardware ID (`HardwareId` is field #5). */
767
-        TCHAR szzHardwareIDs[0x100] = { 0 };
767
+        WCHAR szzHardwareIDs[0x100] = { 0 };
768 768
         {
769
-            LPTSTR szHwId = NULL;
769
+            LPWSTR szHwId = NULL;
770 770
             uiResult = msi_get_record_string(hRecord, 5, &szHwId);
771 771
             if (uiResult != ERROR_SUCCESS)
772 772
             {
773 773
                 goto cleanup_szDisplayName;
774 774
             }
775
-            memcpy_s(szzHardwareIDs, sizeof(szzHardwareIDs) - 2*sizeof(TCHAR) /*requires double zero termination*/, szHwId, _tcslen(szHwId)*sizeof(TCHAR));
775
+            memcpy_s(szzHardwareIDs, sizeof(szzHardwareIDs) - 2*sizeof(WCHAR) /*requires double zero termination*/, szHwId, wcslen(szHwId)*sizeof(WCHAR));
776 776
             free(szHwId);
777 777
         }
778 778
 
... ...
@@ -783,7 +783,7 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
783 783
             if (iAction >= INSTALLSTATE_LOCAL)
784 784
             {
785 785
                 /* Read and evaluate adapter condition (`Condition` is field #3). */
786
-                LPTSTR szValue = NULL;
786
+                LPWSTR szValue = NULL;
787 787
                 uiResult = msi_get_record_string(hRecord, 3, &szValue);
788 788
                 if (uiResult != ERROR_SUCCESS)
789 789
                 {
... ...
@@ -805,7 +805,7 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
805 805
 
806 806
                     case MSICONDITION_ERROR:
807 807
                         uiResult = ERROR_INVALID_FIELD;
808
-                        msg(M_NONFATAL | M_ERRNO, "%s: MsiEvaluateCondition(\"%" PRIsLPTSTR "\") failed", __FUNCTION__, szValue);
808
+                        msg(M_NONFATAL | M_ERRNO, "%s: MsiEvaluateCondition(\"%ls\") failed", __FUNCTION__, szValue);
809 809
                         free(szValue);
810 810
                         goto cleanup_szDisplayName;
811 811
                 }
... ...
@@ -864,11 +864,11 @@ cleanup_hRecord:
864 864
     }
865 865
 
866 866
     /* save path to user's temp dir to be used later by deferred actions */
867
-    TCHAR tmpDir[MAX_PATH];
867
+    WCHAR tmpDir[MAX_PATH];
868 868
     GetTempPath(MAX_PATH, tmpDir);
869 869
 
870
-    TCHAR str[MAX_PATH + 7];
871
-    _stprintf_s(str, _countof(str), TEXT("tmpdir=%") TEXT(PRIsLPTSTR), tmpDir);
870
+    WCHAR str[MAX_PATH + 7];
871
+    swprintf_s(str, _countof(str), L"tmpdir=%ls", tmpDir);
872 872
     msica_arg_seq_add_tail(&seqInstall, str);
873 873
     msica_arg_seq_add_tail(&seqInstallCommit, str);
874 874
     msica_arg_seq_add_tail(&seqInstallRollback, str);
... ...
@@ -877,12 +877,12 @@ cleanup_hRecord:
877 877
     msica_arg_seq_add_tail(&seqUninstallRollback, str);
878 878
 
879 879
     /* Store deferred custom action parameters. */
880
-    if ((uiResult = setup_sequence(hInstall, TEXT("InstallTUNTAPAdapters"          ), &seqInstall          )) != ERROR_SUCCESS
881
-        || (uiResult = setup_sequence(hInstall, TEXT("InstallTUNTAPAdaptersCommit"    ), &seqInstallCommit    )) != ERROR_SUCCESS
882
-        || (uiResult = setup_sequence(hInstall, TEXT("InstallTUNTAPAdaptersRollback"  ), &seqInstallRollback  )) != ERROR_SUCCESS
883
-        || (uiResult = setup_sequence(hInstall, TEXT("UninstallTUNTAPAdapters"        ), &seqUninstall        )) != ERROR_SUCCESS
884
-        || (uiResult = setup_sequence(hInstall, TEXT("UninstallTUNTAPAdaptersCommit"  ), &seqUninstallCommit  )) != ERROR_SUCCESS
885
-        || (uiResult = setup_sequence(hInstall, TEXT("UninstallTUNTAPAdaptersRollback"), &seqUninstallRollback)) != ERROR_SUCCESS)
880
+    if ((uiResult = setup_sequence(hInstall, L"InstallTUNTAPAdapters", &seqInstall          )) != ERROR_SUCCESS
881
+        || (uiResult = setup_sequence(hInstall, L"InstallTUNTAPAdaptersCommit", &seqInstallCommit    )) != ERROR_SUCCESS
882
+        || (uiResult = setup_sequence(hInstall, L"InstallTUNTAPAdaptersRollback", &seqInstallRollback  )) != ERROR_SUCCESS
883
+        || (uiResult = setup_sequence(hInstall, L"UninstallTUNTAPAdapters", &seqUninstall        )) != ERROR_SUCCESS
884
+        || (uiResult = setup_sequence(hInstall, L"UninstallTUNTAPAdaptersCommit", &seqUninstallCommit  )) != ERROR_SUCCESS
885
+        || (uiResult = setup_sequence(hInstall, L"UninstallTUNTAPAdaptersRollback", &seqUninstallRollback)) != ERROR_SUCCESS)
886 886
     {
887 887
         goto cleanup_hRecordProg;
888 888
     }
... ...
@@ -1027,7 +1027,7 @@ ProcessDeferredAction(_In_ MSIHANDLE hInstall)
1027 1027
             {
1028 1028
                 /* Report the name of the adapter to installer. */
1029 1029
                 MSIHANDLE hRecord = MsiCreateRecord(4);
1030
-                MsiRecordSetString(hRecord, 1, TEXT("Creating adapter"));
1030
+                MsiRecordSetString(hRecord, 1, L"Creating adapter");
1031 1031
                 MsiRecordSetString(hRecord, 2, szName);
1032 1032
                 MsiRecordSetString(hRecord, 3, szHardwareId);
1033 1033
                 int iResult = MsiProcessMessage(hInstall, INSTALLMESSAGE_ACTIONDATA, hRecord);
... ...
@@ -1056,7 +1056,7 @@ ProcessDeferredAction(_In_ MSIHANDLE hInstall)
1056 1056
             {
1057 1057
                 /* Report the name of the adapter to installer. */
1058 1058
                 MSIHANDLE hRecord = MsiCreateRecord(3);
1059
-                MsiRecordSetString(hRecord, 1, TEXT("Deleting adapter"));
1059
+                MsiRecordSetString(hRecord, 1, L"Deleting adapter");
1060 1060
                 MsiRecordSetString(hRecord, 2, szName);
1061 1061
                 int iResult = MsiProcessMessage(hInstall, INSTALLMESSAGE_ACTIONDATA, hRecord);
1062 1062
                 MsiCloseHandle(hRecord);
... ...
@@ -1075,7 +1075,7 @@ ProcessDeferredAction(_In_ MSIHANDLE hInstall)
1075 1075
                 /* Does the adapter exist? */
1076 1076
                 for (struct tap_adapter_node *pAdapter = pAdapterList; pAdapter != NULL; pAdapter = pAdapter->pNext)
1077 1077
                 {
1078
-                    if (_tcsicmp(szName, pAdapter->szName) == 0)
1078
+                    if (wcsicmp(szName, pAdapter->szName) == 0)
1079 1079
                     {
1080 1080
                         /* Adapter found. */
1081 1081
                         dwResult = tap_delete_adapter(NULL, &pAdapter->guid, &bRebootRequired);
... ...
@@ -24,11 +24,11 @@
24 24
 #include "service.h"
25 25
 #include "validate.h"
26 26
 
27
-LPCTSTR service_instance = TEXT("");
27
+LPCWSTR service_instance = L"";
28 28
 static wchar_t win_sys_path[MAX_PATH];
29 29
 
30 30
 static DWORD
31
-GetRegString(HKEY key, LPCTSTR value, LPTSTR data, DWORD size, LPCTSTR default_value)
31
+GetRegString(HKEY key, LPCWSTR value, LPWSTR data, DWORD size, LPCWSTR default_value)
32 32
 {
33 33
     LONG status = RegGetValue(key, NULL, value, RRF_RT_REG_SZ,
34 34
                               NULL, (LPBYTE) data, &size);
... ...
@@ -45,7 +45,7 @@ GetRegString(HKEY key, LPCTSTR value, LPTSTR data, DWORD size, LPCTSTR default_v
45 45
     if (status != ERROR_SUCCESS)
46 46
     {
47 47
         SetLastError(status);
48
-        return MsgToEventLog(M_SYSERR, TEXT("Error querying registry value: HKLM\\SOFTWARE\\") TEXT(PACKAGE_NAME) TEXT("%ls\\%ls"), service_instance, value);
48
+        return MsgToEventLog(M_SYSERR, L"Error querying registry value: HKLM\\SOFTWARE\\" _L(PACKAGE_NAME) L"%ls\\%ls", service_instance, value);
49 49
     }
50 50
 
51 51
     return ERROR_SUCCESS;
... ...
@@ -55,21 +55,21 @@ GetRegString(HKEY key, LPCTSTR value, LPTSTR data, DWORD size, LPCTSTR default_v
55 55
 DWORD
56 56
 GetOpenvpnSettings(settings_t *s)
57 57
 {
58
-    TCHAR reg_path[256];
59
-    TCHAR priority[64];
60
-    TCHAR append[2];
58
+    WCHAR reg_path[256];
59
+    WCHAR priority[64];
60
+    WCHAR append[2];
61 61
     DWORD error;
62 62
     HKEY key;
63
-    TCHAR install_path[MAX_PATH];
64
-    TCHAR default_value[MAX_PATH];
63
+    WCHAR install_path[MAX_PATH];
64
+    WCHAR default_value[MAX_PATH];
65 65
 
66
-    swprintf(reg_path, _countof(reg_path), TEXT("SOFTWARE\\") TEXT(PACKAGE_NAME) TEXT("%ls"), service_instance);
66
+    swprintf(reg_path, _countof(reg_path), L"SOFTWARE\\" _L(PACKAGE_NAME) L"%ls", service_instance);
67 67
 
68 68
     LONG status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, reg_path, 0, KEY_READ, &key);
69 69
     if (status != ERROR_SUCCESS)
70 70
     {
71 71
         SetLastError(status);
72
-        return MsgToEventLog(M_SYSERR, TEXT("Could not open Registry key HKLM\\%ls not found"), reg_path);
72
+        return MsgToEventLog(M_SYSERR, L"Could not open Registry key HKLM\\%ls not found", reg_path);
73 73
     }
74 74
 
75 75
     /* The default value of REG_KEY is the install path */
... ...
@@ -80,97 +80,97 @@ GetOpenvpnSettings(settings_t *s)
80 80
         goto out;
81 81
     }
82 82
 
83
-    swprintf(default_value, _countof(default_value), TEXT("%ls\\bin\\openvpn.exe"),
83
+    swprintf(default_value, _countof(default_value), L"%ls\\bin\\openvpn.exe",
84 84
              install_path);
85
-    error = GetRegString(key, TEXT("exe_path"), s->exe_path, sizeof(s->exe_path), default_value);
85
+    error = GetRegString(key, L"exe_path", s->exe_path, sizeof(s->exe_path), default_value);
86 86
     if (error != ERROR_SUCCESS)
87 87
     {
88 88
         goto out;
89 89
     }
90 90
 
91
-    swprintf(default_value, _countof(default_value), TEXT("%ls\\config"), install_path);
92
-    error = GetRegString(key, TEXT("config_dir"), s->config_dir, sizeof(s->config_dir),
91
+    swprintf(default_value, _countof(default_value), L"%ls\\config", install_path);
92
+    error = GetRegString(key, L"config_dir", s->config_dir, sizeof(s->config_dir),
93 93
                          default_value);
94 94
     if (error != ERROR_SUCCESS)
95 95
     {
96 96
         goto out;
97 97
     }
98 98
 
99
-    error = GetRegString(key, TEXT("config_ext"), s->ext_string, sizeof(s->ext_string),
100
-                         TEXT(".ovpn"));
99
+    error = GetRegString(key, L"config_ext", s->ext_string, sizeof(s->ext_string),
100
+                         L".ovpn");
101 101
     if (error != ERROR_SUCCESS)
102 102
     {
103 103
         goto out;
104 104
     }
105 105
 
106
-    swprintf(default_value, _countof(default_value), TEXT("%ls\\log"), install_path);
107
-    error = GetRegString(key, TEXT("log_dir"), s->log_dir, sizeof(s->log_dir), default_value);
106
+    swprintf(default_value, _countof(default_value), L"%ls\\log", install_path);
107
+    error = GetRegString(key, L"log_dir", s->log_dir, sizeof(s->log_dir), default_value);
108 108
     if (error != ERROR_SUCCESS)
109 109
     {
110 110
         goto out;
111 111
     }
112 112
 
113
-    error = GetRegString(key, TEXT("priority"), priority, sizeof(priority),
114
-                         TEXT("NORMAL_PRIORITY_CLASS"));
113
+    error = GetRegString(key, L"priority", priority, sizeof(priority),
114
+                         L"NORMAL_PRIORITY_CLASS");
115 115
     if (error != ERROR_SUCCESS)
116 116
     {
117 117
         goto out;
118 118
     }
119 119
 
120
-    error = GetRegString(key, TEXT("log_append"), append, sizeof(append), TEXT("0"));
120
+    error = GetRegString(key, L"log_append", append, sizeof(append), L"0");
121 121
     if (error != ERROR_SUCCESS)
122 122
     {
123 123
         goto out;
124 124
     }
125 125
 
126 126
     /* read if present, else use default */
127
-    error = GetRegString(key, TEXT("ovpn_admin_group"), s->ovpn_admin_group,
127
+    error = GetRegString(key, L"ovpn_admin_group", s->ovpn_admin_group,
128 128
                          sizeof(s->ovpn_admin_group), OVPN_ADMIN_GROUP);
129 129
     if (error != ERROR_SUCCESS)
130 130
     {
131 131
         goto out;
132 132
     }
133 133
     /* set process priority */
134
-    if (!_wcsicmp(priority, TEXT("IDLE_PRIORITY_CLASS")))
134
+    if (!_wcsicmp(priority, L"IDLE_PRIORITY_CLASS"))
135 135
     {
136 136
         s->priority = IDLE_PRIORITY_CLASS;
137 137
     }
138
-    else if (!_wcsicmp(priority, TEXT("BELOW_NORMAL_PRIORITY_CLASS")))
138
+    else if (!_wcsicmp(priority, L"BELOW_NORMAL_PRIORITY_CLASS"))
139 139
     {
140 140
         s->priority = BELOW_NORMAL_PRIORITY_CLASS;
141 141
     }
142
-    else if (!_wcsicmp(priority, TEXT("NORMAL_PRIORITY_CLASS")))
142
+    else if (!_wcsicmp(priority, L"NORMAL_PRIORITY_CLASS"))
143 143
     {
144 144
         s->priority = NORMAL_PRIORITY_CLASS;
145 145
     }
146
-    else if (!_wcsicmp(priority, TEXT("ABOVE_NORMAL_PRIORITY_CLASS")))
146
+    else if (!_wcsicmp(priority, L"ABOVE_NORMAL_PRIORITY_CLASS"))
147 147
     {
148 148
         s->priority = ABOVE_NORMAL_PRIORITY_CLASS;
149 149
     }
150
-    else if (!_wcsicmp(priority, TEXT("HIGH_PRIORITY_CLASS")))
150
+    else if (!_wcsicmp(priority, L"HIGH_PRIORITY_CLASS"))
151 151
     {
152 152
         s->priority = HIGH_PRIORITY_CLASS;
153 153
     }
154 154
     else
155 155
     {
156 156
         SetLastError(ERROR_INVALID_DATA);
157
-        error = MsgToEventLog(M_SYSERR, TEXT("Unknown priority name: %ls"), priority);
157
+        error = MsgToEventLog(M_SYSERR, L"Unknown priority name: %ls", priority);
158 158
         goto out;
159 159
     }
160 160
 
161 161
     /* set log file append/truncate flag */
162
-    if (append[0] == TEXT('0'))
162
+    if (append[0] == L'0')
163 163
     {
164 164
         s->append = FALSE;
165 165
     }
166
-    else if (append[0] == TEXT('1'))
166
+    else if (append[0] == L'1')
167 167
     {
168 168
         s->append = TRUE;
169 169
     }
170 170
     else
171 171
     {
172 172
         SetLastError(ERROR_INVALID_DATA);
173
-        error = MsgToEventLog(M_ERR, TEXT("Log file append flag (given as '%ls') must be '0' or '1'"), append);
173
+        error = MsgToEventLog(M_ERR, L"Log file append flag (given as '%ls') must be '0' or '1'", append);
174 174
         goto out;
175 175
     }
176 176
 
... ...
@@ -180,13 +180,13 @@ out:
180 180
 }
181 181
 
182 182
 
183
-LPCTSTR
183
+LPCWSTR
184 184
 GetLastErrorText(void)
185 185
 {
186 186
     DWORD error;
187
-    static TCHAR buf[256];
187
+    static WCHAR buf[256];
188 188
     DWORD len;
189
-    LPTSTR tmp = NULL;
189
+    LPWSTR tmp = NULL;
190 190
 
191 191
     error = GetLastError();
192 192
     len = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY,
... ...
@@ -194,12 +194,12 @@ GetLastErrorText(void)
194 194
 
195 195
     if (len == 0 || (long) _countof(buf) < (long) len + 14)
196 196
     {
197
-        buf[0] = TEXT('\0');
197
+        buf[0] = L'\0';
198 198
     }
199 199
     else
200 200
     {
201
-        tmp[wcslen(tmp) - 2] = TEXT('\0'); /* remove CR/LF characters */
202
-        swprintf(buf, _countof(buf), TEXT("%ls (0x%x)"), tmp, error);
201
+        tmp[wcslen(tmp) - 2] = L'\0'; /* remove CR/LF characters */
202
+        swprintf(buf, _countof(buf), L"%ls (0x%x)", tmp, error);
203 203
     }
204 204
 
205 205
     if (tmp)
... ...
@@ -212,12 +212,12 @@ GetLastErrorText(void)
212 212
 
213 213
 
214 214
 DWORD
215
-MsgToEventLog(DWORD flags, LPCTSTR format, ...)
215
+MsgToEventLog(DWORD flags, LPCWSTR format, ...)
216 216
 {
217 217
     HANDLE hEventSource;
218
-    TCHAR msg[2][256];
218
+    WCHAR msg[2][256];
219 219
     DWORD error = 0;
220
-    LPCTSTR err_msg = TEXT("");
220
+    LPCWSTR err_msg = L"";
221 221
     va_list arglist;
222 222
 
223 223
     if (flags & MSG_FLAGS_SYS_CODE)
... ...
@@ -230,14 +230,14 @@ MsgToEventLog(DWORD flags, LPCTSTR format, ...)
230 230
     if (hEventSource != NULL)
231 231
     {
232 232
         swprintf(msg[0], _countof(msg[0]),
233
-                 TEXT("%ls%ls%ls: %ls"), APPNAME, service_instance,
234
-                 (flags & MSG_FLAGS_ERROR) ? TEXT(" error") : TEXT(""), err_msg);
233
+                 L"%ls%ls%ls: %ls", APPNAME, service_instance,
234
+                 (flags & MSG_FLAGS_ERROR) ? L" error" : L"", err_msg);
235 235
 
236 236
         va_start(arglist, format);
237 237
         vswprintf(msg[1], _countof(msg[1]), format, arglist);
238 238
         va_end(arglist);
239 239
 
240
-        const TCHAR *mesg[] = { msg[0], msg[1] };
240
+        const WCHAR *mesg[] = { msg[0], msg[1] };
241 241
         ReportEvent(hEventSource, flags & MSG_FLAGS_ERROR ?
242 242
                     EVENTLOG_ERROR_TYPE : EVENTLOG_INFORMATION_TYPE,
243 243
                     0, 0, NULL, 2, 0, mesg, NULL);
... ...
@@ -60,8 +60,8 @@ static HANDLE rdns_semaphore = NULL;
60 60
 
61 61
 openvpn_service_t interactive_service = {
62 62
     interactive,
63
-    TEXT(PACKAGE_NAME) TEXT("ServiceInteractive"),
64
-    TEXT(PACKAGE_NAME) TEXT(" Interactive Service"),
63
+    _L(PACKAGE_NAME) L"ServiceInteractive",
64
+    _L(PACKAGE_NAME) L" Interactive Service",
65 65
     SERVICE_DEPENDENCIES,
66 66
     SERVICE_AUTO_START
67 67
 };
... ...
@@ -462,7 +462,7 @@ GetStartupData(HANDLE pipe, STARTUP_DATA *sud)
462 462
     bytes = PeekNamedPipeAsync(pipe, 1, &exit_event);
463 463
     if (bytes == 0)
464 464
     {
465
-        MsgToEventLog(M_SYSERR, TEXT("PeekNamedPipeAsync failed"));
465
+        MsgToEventLog(M_SYSERR, L"PeekNamedPipeAsync failed");
466 466
         ReturnLastError(pipe, L"PeekNamedPipeAsync");
467 467
         goto err;
468 468
     }
... ...
@@ -470,7 +470,7 @@ GetStartupData(HANDLE pipe, STARTUP_DATA *sud)
470 470
     size = bytes / sizeof(*data);
471 471
     if (size == 0)
472 472
     {
473
-        MsgToEventLog(M_SYSERR, TEXT("malformed startup data: 1 byte received"));
473
+        MsgToEventLog(M_SYSERR, L"malformed startup data: 1 byte received");
474 474
         ReturnError(pipe, ERROR_STARTUP_DATA, L"GetStartupData", 1, &exit_event);
475 475
         goto err;
476 476
     }
... ...
@@ -478,7 +478,7 @@ GetStartupData(HANDLE pipe, STARTUP_DATA *sud)
478 478
     data = malloc(bytes);
479 479
     if (data == NULL)
480 480
     {
481
-        MsgToEventLog(M_SYSERR, TEXT("malloc failed"));
481
+        MsgToEventLog(M_SYSERR, L"malloc failed");
482 482
         ReturnLastError(pipe, L"malloc");
483 483
         goto err;
484 484
     }
... ...
@@ -486,14 +486,14 @@ GetStartupData(HANDLE pipe, STARTUP_DATA *sud)
486 486
     read = ReadPipeAsync(pipe, data, bytes, 1, &exit_event);
487 487
     if (bytes != read)
488 488
     {
489
-        MsgToEventLog(M_SYSERR, TEXT("ReadPipeAsync failed"));
489
+        MsgToEventLog(M_SYSERR, L"ReadPipeAsync failed");
490 490
         ReturnLastError(pipe, L"ReadPipeAsync");
491 491
         goto err;
492 492
     }
493 493
 
494 494
     if (data[size - 1] != 0)
495 495
     {
496
-        MsgToEventLog(M_ERR, TEXT("Startup data is not NULL terminated"));
496
+        MsgToEventLog(M_ERR, L"Startup data is not NULL terminated");
497 497
         ReturnError(pipe, ERROR_STARTUP_DATA, L"GetStartupData", 1, &exit_event);
498 498
         goto err;
499 499
     }
... ...
@@ -503,7 +503,7 @@ GetStartupData(HANDLE pipe, STARTUP_DATA *sud)
503 503
     size -= len;
504 504
     if (size <= 0)
505 505
     {
506
-        MsgToEventLog(M_ERR, TEXT("Startup data ends at working directory"));
506
+        MsgToEventLog(M_ERR, L"Startup data ends at working directory");
507 507
         ReturnError(pipe, ERROR_STARTUP_DATA, L"GetStartupData", 1, &exit_event);
508 508
         goto err;
509 509
     }
... ...
@@ -513,7 +513,7 @@ GetStartupData(HANDLE pipe, STARTUP_DATA *sud)
513 513
     size -= len;
514 514
     if (size <= 0)
515 515
     {
516
-        MsgToEventLog(M_ERR, TEXT("Startup data ends at command line options"));
516
+        MsgToEventLog(M_ERR, L"Startup data ends at command line options");
517 517
         ReturnError(pipe, ERROR_STARTUP_DATA, L"GetStartupData", 1, &exit_event);
518 518
         goto err;
519 519
     }
... ...
@@ -746,15 +746,15 @@ HandleFlushNeighborsMessage(flush_neighbors_message_t *msg)
746 746
 static void
747 747
 BlockDNSErrHandler(DWORD err, const char *msg)
748 748
 {
749
-    TCHAR buf[256];
750
-    LPCTSTR err_str;
749
+    WCHAR buf[256];
750
+    LPCWSTR err_str;
751 751
 
752 752
     if (!err)
753 753
     {
754 754
         return;
755 755
     }
756 756
 
757
-    err_str = TEXT("Unknown Win32 Error");
757
+    err_str = L"Unknown Win32 Error";
758 758
 
759 759
     if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM
760 760
                       | FORMAT_MESSAGE_ARGUMENT_ARRAY,
... ...
@@ -796,7 +796,7 @@ DeleteWfpBlock(const wfp_block_message_t *msg, undo_lists_t *lists)
796 796
     }
797 797
     else
798 798
     {
799
-        MsgToEventLog(M_ERR, TEXT("No previous block filters to delete"));
799
+        MsgToEventLog(M_ERR, L"No previous block filters to delete");
800 800
     }
801 801
 
802 802
     return err;
... ...
@@ -913,7 +913,7 @@ ExecCommand(const WCHAR *argv0, const WCHAR *cmdline, DWORD timeout)
913 913
         WaitForSingleObject(pi.hProcess, timeout ? timeout : INFINITE);
914 914
         if (!GetExitCodeProcess(pi.hProcess, &exit_code))
915 915
         {
916
-            MsgToEventLog(M_SYSERR, TEXT("ExecCommand: Error getting exit_code:"));
916
+            MsgToEventLog(M_SYSERR, L"ExecCommand: Error getting exit_code:");
917 917
             exit_code = GetLastError();
918 918
         }
919 919
         else if (exit_code == STILL_ACTIVE)
... ...
@@ -922,17 +922,17 @@ ExecCommand(const WCHAR *argv0, const WCHAR *cmdline, DWORD timeout)
922 922
 
923 923
             /* kill without impunity */
924 924
             TerminateProcess(pi.hProcess, exit_code);
925
-            MsgToEventLog(M_ERR, TEXT("ExecCommand: \"%ls %ls\" killed after timeout"),
925
+            MsgToEventLog(M_ERR, L"ExecCommand: \"%ls %ls\" killed after timeout",
926 926
                           argv0, cmdline);
927 927
         }
928 928
         else if (exit_code)
929 929
         {
930
-            MsgToEventLog(M_ERR, TEXT("ExecCommand: \"%ls %ls\" exited with status = %lu"),
930
+            MsgToEventLog(M_ERR, L"ExecCommand: \"%ls %ls\" exited with status = %lu",
931 931
                           argv0, cmdline, exit_code);
932 932
         }
933 933
         else
934 934
         {
935
-            MsgToEventLog(M_INFO, TEXT("ExecCommand: \"%ls %ls\" completed"), argv0, cmdline);
935
+            MsgToEventLog(M_INFO, L"ExecCommand: \"%ls %ls\" completed", argv0, cmdline);
936 936
         }
937 937
 
938 938
         CloseHandle(pi.hProcess);
... ...
@@ -941,7 +941,7 @@ ExecCommand(const WCHAR *argv0, const WCHAR *cmdline, DWORD timeout)
941 941
     else
942 942
     {
943 943
         exit_code = GetLastError();
944
-        MsgToEventLog(M_SYSERR, TEXT("ExecCommand: could not run \"%ls %ls\" :"),
944
+        MsgToEventLog(M_SYSERR, L"ExecCommand: could not run \"%ls %ls\" :",
945 945
                       argv0, cmdline);
946 946
     }
947 947
 
... ...
@@ -986,12 +986,12 @@ RegisterDNS(LPVOID unused)
986 986
         err = 0;
987 987
         if (!ReleaseSemaphore(rdns_semaphore, 1, NULL) )
988 988
         {
989
-            err = MsgToEventLog(M_SYSERR, TEXT("RegisterDNS: Failed to release regsiter-dns semaphore:"));
989
+            err = MsgToEventLog(M_SYSERR, L"RegisterDNS: Failed to release regsiter-dns semaphore:");
990 990
         }
991 991
     }
992 992
     else
993 993
     {
994
-        MsgToEventLog(M_ERR, TEXT("RegisterDNS: Failed to lock register-dns semaphore"));
994
+        MsgToEventLog(M_ERR, L"RegisterDNS: Failed to lock register-dns semaphore");
995 995
         err = ERROR_SEM_TIMEOUT; /* Windows error code 0x79 */
996 996
     }
997 997
     return err;
... ...
@@ -1194,7 +1194,7 @@ ApplyDnsSettings(BOOL apply_gpol)
1194 1194
 
1195 1195
     if (apply_gpol && ApplyGpolSettings() == FALSE)
1196 1196
     {
1197
-        MsgToEventLog(M_ERR, TEXT("ApplyDnsSettings: sending GPOL notification failed"));
1197
+        MsgToEventLog(M_ERR, L"ApplyDnsSettings: sending GPOL notification failed");
1198 1198
     }
1199 1199
 
1200 1200
     scm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
... ...
@@ -1442,7 +1442,7 @@ StoreInitialDnsSearchList(HKEY key, PCWSTR list)
1442 1442
 {
1443 1443
     if (!list || wcslen(list) == 0)
1444 1444
     {
1445
-        MsgToEventLog(M_ERR, TEXT("StoreInitialDnsSearchList: empty search list"));
1445
+        MsgToEventLog(M_ERR, L"StoreInitialDnsSearchList: empty search list");
1446 1446
         return FALSE;
1447 1447
     }
1448 1448
 
... ...
@@ -2079,7 +2079,7 @@ OvpnDuplicateHandle(HANDLE ovpn_proc, HANDLE orig_handle, HANDLE *new_handle)
2079 2079
     if (!DuplicateHandle(ovpn_proc, orig_handle, GetCurrentProcess(), new_handle, 0, FALSE, DUPLICATE_SAME_ACCESS))
2080 2080
     {
2081 2081
         err = GetLastError();
2082
-        MsgToEventLog(M_SYSERR, TEXT("Could not duplicate handle"));
2082
+        MsgToEventLog(M_SYSERR, L"Could not duplicate handle");
2083 2083
         return err;
2084 2084
     }
2085 2085
 
... ...
@@ -2103,7 +2103,7 @@ DuplicateAndMapRing(HANDLE ovpn_proc, HANDLE orig_handle, struct tun_ring **ring
2103 2103
     if (*ring == NULL)
2104 2104
     {
2105 2105
         err = GetLastError();
2106
-        MsgToEventLog(M_SYSERR, TEXT("Could not map shared memory"));
2106
+        MsgToEventLog(M_SYSERR, L"Could not map shared memory");
2107 2107
         return err;
2108 2108
     }
2109 2109
 
... ...
@@ -2166,7 +2166,7 @@ HandleRegisterRingBuffers(const register_ring_buffers_message_t *rrb, HANDLE ovp
2166 2166
                                send_tail_moved, receive_tail_moved))
2167 2167
     {
2168 2168
         err = GetLastError();
2169
-        MsgToEventLog(M_SYSERR, TEXT("Could not register ring buffers"));
2169
+        MsgToEventLog(M_SYSERR, L"Could not register ring buffers");
2170 2170
         goto out;
2171 2171
     }
2172 2172
 
... ...
@@ -2299,7 +2299,7 @@ HandleMessage(HANDLE pipe, HANDLE ovpn_proc,
2299 2299
 
2300 2300
         default:
2301 2301
             ack.error_number = ERROR_MESSAGE_TYPE;
2302
-            MsgToEventLog(MSG_FLAGS_ERROR, TEXT("Unknown message type %d"), msg.header.type);
2302
+            MsgToEventLog(MSG_FLAGS_ERROR, L"Unknown message type %d", msg.header.type);
2303 2303
             break;
2304 2304
     }
2305 2305
 
... ...
@@ -2391,7 +2391,7 @@ RunOpenvpn(LPVOID p)
2391 2391
     STARTUPINFOW startup_info;
2392 2392
     PROCESS_INFORMATION proc_info;
2393 2393
     LPVOID user_env = NULL;
2394
-    TCHAR ovpn_pipe_name[256]; /* The entire pipe name string can be up to 256 characters long according to MSDN. */
2394
+    WCHAR ovpn_pipe_name[256]; /* The entire pipe name string can be up to 256 characters long according to MSDN. */
2395 2395
     LPCWSTR exe_path;
2396 2396
     WCHAR *cmdline = NULL;
2397 2397
     size_t cmdline_size;
... ...
@@ -2509,14 +2509,14 @@ RunOpenvpn(LPVOID p)
2509 2509
     ea[0].grfInheritance = NO_INHERITANCE;
2510 2510
     ea[0].Trustee.TrusteeForm = TRUSTEE_IS_SID;
2511 2511
     ea[0].Trustee.TrusteeType = TRUSTEE_IS_UNKNOWN;
2512
-    ea[0].Trustee.ptstrName = (LPTSTR) svc_user->User.Sid;
2512
+    ea[0].Trustee.ptstrName = (LPWSTR) svc_user->User.Sid;
2513 2513
     ea[1].grfAccessPermissions = READ_CONTROL | SYNCHRONIZE | PROCESS_VM_READ
2514 2514
                                  |SYNCHRONIZE | PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION;
2515 2515
     ea[1].grfAccessMode = SET_ACCESS;
2516 2516
     ea[1].grfInheritance = NO_INHERITANCE;
2517 2517
     ea[1].Trustee.TrusteeForm = TRUSTEE_IS_SID;
2518 2518
     ea[1].Trustee.TrusteeType = TRUSTEE_IS_UNKNOWN;
2519
-    ea[1].Trustee.ptstrName = (LPTSTR) ovpn_user->User.Sid;
2519
+    ea[1].Trustee.ptstrName = (LPWSTR) ovpn_user->User.Sid;
2520 2520
 
2521 2521
     /* Set owner and DACL of OpenVPN security descriptor */
2522 2522
     if (!SetSecurityDescriptorOwner(&ovpn_sd, svc_user->User.Sid, FALSE))
... ...
@@ -2543,7 +2543,7 @@ RunOpenvpn(LPVOID p)
2543 2543
     }
2544 2544
 
2545 2545
     /* use /dev/null for stdout of openvpn (client should use --log for output) */
2546
-    stdout_write = CreateFile(_T("NUL"), GENERIC_WRITE, FILE_SHARE_WRITE,
2546
+    stdout_write = CreateFile(_L("NUL"), GENERIC_WRITE, FILE_SHARE_WRITE,
2547 2547
                               &inheritable, OPEN_EXISTING, 0, NULL);
2548 2548
     if (stdout_write == INVALID_HANDLE_VALUE)
2549 2549
     {
... ...
@@ -2559,7 +2559,7 @@ RunOpenvpn(LPVOID p)
2559 2559
     }
2560 2560
 
2561 2561
     swprintf(ovpn_pipe_name, _countof(ovpn_pipe_name),
2562
-             TEXT("\\\\.\\pipe\\") TEXT(PACKAGE) TEXT("%ls\\service_%lu"), service_instance, GetCurrentThreadId());
2562
+             L"\\\\.\\pipe\\" _L(PACKAGE) L"%ls\\service_%lu", service_instance, GetCurrentThreadId());
2563 2563
     ovpn_pipe = CreateNamedPipe(ovpn_pipe_name,
2564 2564
                                 PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE | FILE_FLAG_OVERLAPPED,
2565 2565
                                 PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 1, 128, 128, 0, NULL);
... ...
@@ -2654,7 +2654,7 @@ RunOpenvpn(LPVOID p)
2654 2654
         if (bytes > sizeof(pipe_message_t))
2655 2655
         {
2656 2656
             /* process at the other side of the pipe is misbehaving, shut it down */
2657
-            MsgToEventLog(MSG_FLAGS_ERROR, TEXT("OpenVPN process sent too large payload length to the pipe (%lu bytes), it will be terminated"), bytes);
2657
+            MsgToEventLog(MSG_FLAGS_ERROR, L"OpenVPN process sent too large payload length to the pipe (%lu bytes), it will be terminated", bytes);
2658 2658
             break;
2659 2659
         }
2660 2660
 
... ...
@@ -2734,12 +2734,12 @@ CreateClientPipeInstance(VOID)
2734 2734
      * allow read/write for authenticated users
2735 2735
      * deny all access to anonymous
2736 2736
      */
2737
-    const TCHAR *sddlString = TEXT("D:(A;OICI;GA;;;S-1-5-18)(D;OICI;0x4;;;S-1-1-0)(A;OICI;GRGW;;;S-1-5-11)(D;;GA;;;S-1-5-7)");
2737
+    const WCHAR *sddlString = L"D:(A;OICI;GA;;;S-1-5-18)(D;OICI;0x4;;;S-1-1-0)(A;OICI;GRGW;;;S-1-5-11)(D;;GA;;;S-1-5-7)";
2738 2738
 
2739 2739
     PSECURITY_DESCRIPTOR sd = NULL;
2740 2740
     if (!ConvertStringSecurityDescriptorToSecurityDescriptor(sddlString, SDDL_REVISION_1, &sd, NULL))
2741 2741
     {
2742
-        MsgToEventLog(M_SYSERR, TEXT("ConvertStringSecurityDescriptorToSecurityDescriptor failed."));
2742
+        MsgToEventLog(M_SYSERR, L"ConvertStringSecurityDescriptorToSecurityDescriptor failed.");
2743 2743
         return INVALID_HANDLE_VALUE;
2744 2744
     }
2745 2745
 
... ...
@@ -2758,8 +2758,8 @@ CreateClientPipeInstance(VOID)
2758 2758
         first = FALSE;
2759 2759
     }
2760 2760
 
2761
-    TCHAR pipe_name[256]; /* The entire pipe name string can be up to 256 characters long according to MSDN. */
2762
-    swprintf(pipe_name, _countof(pipe_name), TEXT("\\\\.\\pipe\\") TEXT(PACKAGE) TEXT("%ls\\service"), service_instance);
2761
+    WCHAR pipe_name[256]; /* The entire pipe name string can be up to 256 characters long according to MSDN. */
2762
+    swprintf(pipe_name, _countof(pipe_name), L"\\\\.\\pipe\\" _L(PACKAGE) L"%ls\\service", service_instance);
2763 2763
     HANDLE pipe = CreateNamedPipe(pipe_name, flags,
2764 2764
                                   PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_REJECT_REMOTE_CLIENTS,
2765 2765
                                   PIPE_UNLIMITED_INSTANCES, 1024, 1024, 0, &sa);
... ...
@@ -2768,7 +2768,7 @@ CreateClientPipeInstance(VOID)
2768 2768
 
2769 2769
     if (pipe == INVALID_HANDLE_VALUE)
2770 2770
     {
2771
-        MsgToEventLog(M_SYSERR, TEXT("Could not create named pipe"));
2771
+        MsgToEventLog(M_SYSERR, L"Could not create named pipe");
2772 2772
         return INVALID_HANDLE_VALUE;
2773 2773
     }
2774 2774
 
... ...
@@ -2840,7 +2840,7 @@ CmpHandle(LPVOID item, LPVOID hnd)
2840 2840
 
2841 2841
 
2842 2842
 VOID WINAPI
2843
-ServiceStartInteractiveOwn(DWORD dwArgc, LPTSTR *lpszArgv)
2843
+ServiceStartInteractiveOwn(DWORD dwArgc, LPWSTR *lpszArgv)
2844 2844
 {
2845 2845
     status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
2846 2846
     ServiceStartInteractive(dwArgc, lpszArgv);
... ...
@@ -2876,7 +2876,7 @@ CleanupRegistry(void)
2876 2876
 }
2877 2877
 
2878 2878
 VOID WINAPI
2879
-ServiceStartInteractive(DWORD dwArgc, LPTSTR *lpszArgv)
2879
+ServiceStartInteractive(DWORD dwArgc, LPWSTR *lpszArgv)
2880 2880
 {
2881 2881
     HANDLE pipe, io_event = NULL;
2882 2882
     OVERLAPPED overlapped;
... ...
@@ -2911,14 +2911,14 @@ ServiceStartInteractive(DWORD dwArgc, LPTSTR *lpszArgv)
2911 2911
     exit_event = CreateEvent(NULL, TRUE, FALSE, NULL);
2912 2912
     if (!exit_event || !io_event)
2913 2913
     {
2914
-        error = MsgToEventLog(M_SYSERR, TEXT("Could not create event"));
2914
+        error = MsgToEventLog(M_SYSERR, L"Could not create event");
2915 2915
         goto out;
2916 2916
     }
2917 2917
 
2918 2918
     rdns_semaphore = CreateSemaphoreW(NULL, 1, 1, NULL);
2919 2919
     if (!rdns_semaphore)
2920 2920
     {
2921
-        error = MsgToEventLog(M_SYSERR, TEXT("Could not create semaphore for register-dns"));
2921
+        error = MsgToEventLog(M_SYSERR, L"Could not create semaphore for register-dns");
2922 2922
         goto out;
2923 2923
     }
2924 2924
 
... ...
@@ -2944,7 +2944,7 @@ ServiceStartInteractive(DWORD dwArgc, LPTSTR *lpszArgv)
2944 2944
             && GetLastError() != ERROR_PIPE_CONNECTED
2945 2945
             && GetLastError() != ERROR_IO_PENDING)
2946 2946
         {
2947
-            MsgToEventLog(M_SYSERR, TEXT("Could not connect pipe"));
2947
+            MsgToEventLog(M_SYSERR, L"Could not connect pipe");
2948 2948
             break;
2949 2949
         }
2950 2950
 
... ...
@@ -2989,7 +2989,7 @@ ServiceStartInteractive(DWORD dwArgc, LPTSTR *lpszArgv)
2989 2989
             CancelIo(pipe);
2990 2990
             if (error == WAIT_FAILED)
2991 2991
             {
2992
-                MsgToEventLog(M_SYSERR, TEXT("WaitForMultipleObjects failed"));
2992
+                MsgToEventLog(M_SYSERR, L"WaitForMultipleObjects failed");
2993 2993
                 SetEvent(exit_event);
2994 2994
                 /* Give some time for worker threads to exit and then terminate */
2995 2995
                 Sleep(1000);
... ...
@@ -47,7 +47,7 @@ ReportStatusToSCMgr(SERVICE_STATUS_HANDLE service, SERVICE_STATUS *status)
47 47
     res = SetServiceStatus(service, status);
48 48
     if (!res)
49 49
     {
50
-        MsgToEventLog(MSG_FLAGS_ERROR, TEXT("SetServiceStatus"));
50
+        MsgToEventLog(MSG_FLAGS_ERROR, L"SetServiceStatus");
51 51
     }
52 52
 
53 53
     return res;
... ...
@@ -58,22 +58,22 @@ CmdInstallServices(void)
58 58
 {
59 59
     SC_HANDLE service;
60 60
     SC_HANDLE svc_ctl_mgr;
61
-    TCHAR path[512];
61
+    WCHAR path[512];
62 62
     int i, ret = _service_max;
63 63
 
64 64
     if (GetModuleFileName(NULL, path + 1, _countof(path) - 2) == 0)
65 65
     {
66
-        wprintf(TEXT("Unable to install service - %ls\n"), GetLastErrorText());
66
+        wprintf(L"Unable to install service - %ls\n", GetLastErrorText());
67 67
         return 1;
68 68
     }
69 69
 
70
-    path[0] = TEXT('\"');
71
-    wcscat_s(path, _countof(path), TEXT("\""));
70
+    path[0] = L'\"';
71
+    wcscat_s(path, _countof(path), L"\"");
72 72
 
73 73
     svc_ctl_mgr = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT | SC_MANAGER_CREATE_SERVICE);
74 74
     if (svc_ctl_mgr == NULL)
75 75
     {
76
-        wprintf(TEXT("OpenSCManager failed - %ls\n"), GetLastErrorText());
76
+        wprintf(L"OpenSCManager failed - %ls\n", GetLastErrorText());
77 77
         return 1;
78 78
     }
79 79
 
... ...
@@ -91,13 +91,13 @@ CmdInstallServices(void)
91 91
                                 NULL, NULL);
92 92
         if (service)
93 93
         {
94
-            wprintf(TEXT("%ls installed.\n"), openvpn_service[i].display_name);
94
+            wprintf(L"%ls installed.\n", openvpn_service[i].display_name);
95 95
             CloseServiceHandle(service);
96 96
             --ret;
97 97
         }
98 98
         else
99 99
         {
100
-            wprintf(TEXT("CreateService failed - %ls\n"), GetLastErrorText());
100
+            wprintf(L"CreateService failed - %ls\n", GetLastErrorText());
101 101
         }
102 102
     }
103 103
 
... ...
@@ -116,7 +116,7 @@ CmdStartService(openvpn_service_type type)
116 116
     svc_ctl_mgr = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
117 117
     if (svc_ctl_mgr == NULL)
118 118
     {
119
-        wprintf(TEXT("OpenSCManager failed - %ls\n"), GetLastErrorText());
119
+        wprintf(L"OpenSCManager failed - %ls\n", GetLastErrorText());
120 120
         return 1;
121 121
     }
122 122
 
... ...
@@ -125,19 +125,19 @@ CmdStartService(openvpn_service_type type)
125 125
     {
126 126
         if (StartService(service, 0, NULL))
127 127
         {
128
-            wprintf(TEXT("Service Started\n"));
128
+            wprintf(L"Service Started\n");
129 129
             ret = 0;
130 130
         }
131 131
         else
132 132
         {
133
-            wprintf(TEXT("StartService failed - %ls\n"), GetLastErrorText());
133
+            wprintf(L"StartService failed - %ls\n", GetLastErrorText());
134 134
         }
135 135
 
136 136
         CloseServiceHandle(service);
137 137
     }
138 138
     else
139 139
     {
140
-        wprintf(TEXT("OpenService failed - %ls\n"), GetLastErrorText());
140
+        wprintf(L"OpenService failed - %ls\n", GetLastErrorText());
141 141
     }
142 142
 
143 143
     CloseServiceHandle(svc_ctl_mgr);
... ...
@@ -156,7 +156,7 @@ CmdRemoveServices(void)
156 156
     svc_ctl_mgr = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
157 157
     if (svc_ctl_mgr == NULL)
158 158
     {
159
-        wprintf(TEXT("OpenSCManager failed - %ls\n"), GetLastErrorText());
159
+        wprintf(L"OpenSCManager failed - %ls\n", GetLastErrorText());
160 160
         return 1;
161 161
     }
162 162
 
... ...
@@ -167,21 +167,21 @@ CmdRemoveServices(void)
167 167
                               DELETE | SERVICE_STOP | SERVICE_QUERY_STATUS);
168 168
         if (service == NULL)
169 169
         {
170
-            wprintf(TEXT("OpenService failed - %ls\n"), GetLastErrorText());
170
+            wprintf(L"OpenService failed - %ls\n", GetLastErrorText());
171 171
             goto out;
172 172
         }
173 173
 
174 174
         /* try to stop the service */
175 175
         if (ControlService(service, SERVICE_CONTROL_STOP, &status))
176 176
         {
177
-            wprintf(TEXT("Stopping %ls."), ovpn_svc->display_name);
177
+            wprintf(L"Stopping %ls.", ovpn_svc->display_name);
178 178
             Sleep(1000);
179 179
 
180 180
             while (QueryServiceStatus(service, &status))
181 181
             {
182 182
                 if (status.dwCurrentState == SERVICE_STOP_PENDING)
183 183
                 {
184
-                    wprintf(TEXT("."));
184
+                    wprintf(L".");
185 185
                     Sleep(1000);
186 186
                 }
187 187
                 else
... ...
@@ -192,23 +192,23 @@ CmdRemoveServices(void)
192 192
 
193 193
             if (status.dwCurrentState == SERVICE_STOPPED)
194 194
             {
195
-                wprintf(TEXT("\n%ls stopped.\n"), ovpn_svc->display_name);
195
+                wprintf(L"\n%ls stopped.\n", ovpn_svc->display_name);
196 196
             }
197 197
             else
198 198
             {
199
-                wprintf(TEXT("\n%ls failed to stop.\n"), ovpn_svc->display_name);
199
+                wprintf(L"\n%ls failed to stop.\n", ovpn_svc->display_name);
200 200
             }
201 201
         }
202 202
 
203 203
         /* now remove the service */
204 204
         if (DeleteService(service))
205 205
         {
206
-            wprintf(TEXT("%ls removed.\n"), ovpn_svc->display_name);
206
+            wprintf(L"%ls removed.\n", ovpn_svc->display_name);
207 207
             --ret;
208 208
         }
209 209
         else
210 210
         {
211
-            wprintf(TEXT("DeleteService failed - %ls\n"), GetLastErrorText());
211
+            wprintf(L"DeleteService failed - %ls\n", GetLastErrorText());
212 212
         }
213 213
 
214 214
         CloseServiceHandle(service);
... ...
@@ -221,7 +221,7 @@ out:
221 221
 
222 222
 
223 223
 int
224
-_tmain(int argc, TCHAR *argv[])
224
+wmain(int argc, WCHAR *argv[])
225 225
 {
226 226
     /*
227 227
      * Interactive service (as a SERVICE_WIN32_SHARE_PROCESS)
... ...
@@ -234,7 +234,7 @@ _tmain(int argc, TCHAR *argv[])
234 234
 
235 235
     /* Interactive service only (as a SERVICE_WIN32_OWN_PROCESS) */
236 236
     const SERVICE_TABLE_ENTRY dispatchTable_interactive[] = {
237
-        { TEXT(""), ServiceStartInteractiveOwn },
237
+        { L"", ServiceStartInteractiveOwn },
238 238
         { NULL, NULL }
239 239
     };
240 240
 
... ...
@@ -244,23 +244,23 @@ _tmain(int argc, TCHAR *argv[])
244 244
 
245 245
     for (int i = 1; i < argc; i++)
246 246
     {
247
-        if (*argv[i] == TEXT('-') || *argv[i] == TEXT('/'))
247
+        if (*argv[i] == L'-' || *argv[i] == L'/')
248 248
         {
249
-            if (_wcsicmp(TEXT("install"), argv[i] + 1) == 0)
249
+            if (_wcsicmp(L"install", argv[i] + 1) == 0)
250 250
             {
251 251
                 return CmdInstallServices();
252 252
             }
253
-            else if (_wcsicmp(TEXT("remove"), argv[i] + 1) == 0)
253
+            else if (_wcsicmp(L"remove", argv[i] + 1) == 0)
254 254
             {
255 255
                 return CmdRemoveServices();
256 256
             }
257
-            else if (_wcsicmp(TEXT("start"), argv[i] + 1) == 0)
257
+            else if (_wcsicmp(L"start", argv[i] + 1) == 0)
258 258
             {
259 259
                 return CmdStartService(interactive);
260 260
             }
261
-            else if (argc > i + 2 && _wcsicmp(TEXT("instance"), argv[i] + 1) == 0)
261
+            else if (argc > i + 2 && _wcsicmp(L"instance", argv[i] + 1) == 0)
262 262
             {
263
-                if (_wcsicmp(TEXT("interactive"), argv[i+1]) == 0)
263
+                if (_wcsicmp(L"interactive", argv[i+1]) == 0)
264 264
                 {
265 265
                     dispatchTable = dispatchTable_interactive;
266 266
                     service_instance = argv[i + 2];
... ...
@@ -274,16 +274,16 @@ _tmain(int argc, TCHAR *argv[])
274 274
             }
275 275
             else
276 276
             {
277
-                wprintf(TEXT("%ls -install        to install the interactive service\n"), APPNAME);
278
-                wprintf(TEXT("%ls -start [name]   to start the service (name = \"interactive\" is optional)\n"), APPNAME);
279
-                wprintf(TEXT("%ls -remove         to remove the service\n"), APPNAME);
277
+                wprintf(L"%ls -install        to install the interactive service\n", APPNAME);
278
+                wprintf(L"%ls -start [name]   to start the service (name = \"interactive\") is optional\n", APPNAME);
279
+                wprintf(L"%ls -remove         to remove the service\n", APPNAME);
280 280
 
281
-                wprintf(TEXT("\nService run-time parameters:\n"));
282
-                wprintf(TEXT("-instance interactive <id>\n")
283
-                        TEXT("   Runs the service as an alternate instance.\n")
284
-                        TEXT("   The service settings will be loaded from\n")
285
-                        TEXT("   HKLM\\Software\\") TEXT(PACKAGE_NAME) TEXT("<id> registry key, and the service will accept\n")
286
-                        TEXT("   requests on \\\\.\\pipe\\") TEXT(PACKAGE) TEXT("<id>\\service named pipe.\n"));
281
+                wprintf(L"\nService run-time parameters:\n");
282
+                wprintf(L"-instance interactive <id>\n"
283
+                        L"   Runs the service as an alternate instance.\n"
284
+                        L"   The service settings will be loaded from\n"
285
+                        L"   HKLM\\Software\\" _L(PACKAGE_NAME) L"<id> registry key, and the service will accept\n"
286
+                        L"   requests on \\\\.\\pipe\\" _L(PACKAGE) L"<id>\\service named pipe.\n");
287 287
 
288 288
                 return 0;
289 289
             }
... ...
@@ -294,12 +294,12 @@ _tmain(int argc, TCHAR *argv[])
294 294
      * the service control manager may be starting the service
295 295
      * so we must call StartServiceCtrlDispatcher
296 296
      */
297
-    wprintf(TEXT("\nStartServiceCtrlDispatcher being called.\n"));
298
-    wprintf(TEXT("This may take several seconds. Please wait.\n"));
297
+    wprintf(L"\nStartServiceCtrlDispatcher being called.\n");
298
+    wprintf(L"This may take several seconds. Please wait.\n");
299 299
 
300 300
     if (!StartServiceCtrlDispatcher(dispatchTable))
301 301
     {
302
-        MsgToEventLog(MSG_FLAGS_ERROR, TEXT("StartServiceCtrlDispatcher failed."));
302
+        MsgToEventLog(MSG_FLAGS_ERROR, L"StartServiceCtrlDispatcher failed.");
303 303
     }
304 304
 
305 305
     return 0;
... ...
@@ -36,11 +36,11 @@
36 36
 #include <winsock2.h>
37 37
 #include <windows.h>
38 38
 #include <stdlib.h>
39
-#include <tchar.h>
39
+#include <wchar.h>
40 40
 #include "../tapctl/basic.h"
41 41
 
42
-#define APPNAME  TEXT(PACKAGE) TEXT("serv")
43
-#define SERVICE_DEPENDENCIES  TEXT(TAP_WIN_COMPONENT_ID) TEXT("\0Dhcp\0\0")
42
+#define APPNAME  _L(PACKAGE) L"serv"
43
+#define SERVICE_DEPENDENCIES  _L(TAP_WIN_COMPONENT_ID) L"\0Dhcp\0\0"
44 44
 
45 45
 /*
46 46
  * Message handling
... ...
@@ -58,37 +58,37 @@ typedef enum {
58 58
 
59 59
 typedef struct {
60 60
     openvpn_service_type type;
61
-    TCHAR *name;
62
-    TCHAR *display_name;
63
-    TCHAR *dependencies;
61
+    WCHAR *name;
62
+    WCHAR *display_name;
63
+    WCHAR *dependencies;
64 64
     DWORD start_type;
65 65
 } openvpn_service_t;
66 66
 
67 67
 #define MAX_NAME 256
68 68
 typedef struct {
69
-    TCHAR exe_path[MAX_PATH];
70
-    TCHAR config_dir[MAX_PATH];
71
-    TCHAR ext_string[16];
72
-    TCHAR log_dir[MAX_PATH];
73
-    TCHAR ovpn_admin_group[MAX_NAME];
69
+    WCHAR exe_path[MAX_PATH];
70
+    WCHAR config_dir[MAX_PATH];
71
+    WCHAR ext_string[16];
72
+    WCHAR log_dir[MAX_PATH];
73
+    WCHAR ovpn_admin_group[MAX_NAME];
74 74
     DWORD priority;
75 75
     BOOL append;
76 76
 } settings_t;
77 77
 
78 78
 extern openvpn_service_t interactive_service;
79
-extern LPCTSTR service_instance;
79
+extern LPCWSTR service_instance;
80 80
 
81
-VOID WINAPI ServiceStartInteractiveOwn(DWORD argc, LPTSTR *argv);
81
+VOID WINAPI ServiceStartInteractiveOwn(DWORD argc, LPWSTR *argv);
82 82
 
83
-VOID WINAPI ServiceStartInteractive(DWORD argc, LPTSTR *argv);
83
+VOID WINAPI ServiceStartInteractive(DWORD argc, LPWSTR *argv);
84 84
 
85 85
 DWORD GetOpenvpnSettings(settings_t *s);
86 86
 
87 87
 BOOL ReportStatusToSCMgr(SERVICE_STATUS_HANDLE service, SERVICE_STATUS *status);
88 88
 
89
-LPCTSTR GetLastErrorText(void);
89
+LPCWSTR GetLastErrorText(void);
90 90
 
91
-DWORD MsgToEventLog(DWORD flags, LPCTSTR lpszMsg, ...);
91
+DWORD MsgToEventLog(DWORD flags, LPCWSTR lpszMsg, ...);
92 92
 
93 93
 /**
94 94
  * Convert a UTF-8 string to UTF-16
... ...
@@ -158,7 +158,7 @@ IsAuthorizedUser(PSID sid, const HANDLE token, const WCHAR *ovpn_admin_group)
158 158
     /* Get username */
159 159
     if (!LookupAccountSidW(NULL, sid, username, &len, domain, &len, &sid_type))
160 160
     {
161
-        MsgToEventLog(M_SYSERR, TEXT("LookupAccountSid"));
161
+        MsgToEventLog(M_SYSERR, L"LookupAccountSid");
162 162
         /* not fatal as this is now used only for logging */
163 163
         username[0] = '\0';
164 164
         domain[0] = '\0';
... ...
@@ -170,7 +170,7 @@ IsAuthorizedUser(PSID sid, const HANDLE token, const WCHAR *ovpn_admin_group)
170 170
     }
171 171
     else
172 172
     {
173
-        MsgToEventLog(M_SYSERR, TEXT("Failed to get the name of Administrators group. Using the default."));
173
+        MsgToEventLog(M_SYSERR, L"Failed to get the name of Administrators group. Using the default.");
174 174
         /* use the default value */
175 175
         admin_group[0] = SYSTEM_ADMIN_GROUP;
176 176
     }
... ...
@@ -182,7 +182,7 @@ IsAuthorizedUser(PSID sid, const HANDLE token, const WCHAR *ovpn_admin_group)
182 182
         ret = IsUserInGroup(sid, token_groups, admin_group[i]);
183 183
         if (ret)
184 184
         {
185
-            MsgToEventLog(M_INFO, TEXT("Authorizing user '%ls@%ls' by virtue of membership in group '%ls'"),
185
+            MsgToEventLog(M_INFO, L"Authorizing user '%ls@%ls' by virtue of membership in group '%ls'",
186 186
                           username, domain, admin_group[i]);
187 187
             goto out;
188 188
         }
... ...
@@ -302,7 +302,7 @@ IsUserInGroup(PSID sid, const PTOKEN_GROUPS token_groups, const WCHAR *group_nam
302 302
     if (err != NERR_Success && err != NERR_GroupNotFound)
303 303
     {
304 304
         SetLastError(err);
305
-        MsgToEventLog(M_SYSERR, TEXT("In NetLocalGroupGetMembers for group '%ls'"), group_name);
305
+        MsgToEventLog(M_SYSERR, L"In NetLocalGroupGetMembers for group '%ls'", group_name);
306 306
     }
307 307
 
308 308
     return ret;
... ...
@@ -28,8 +28,8 @@
28 28
 #include "service.h"
29 29
 
30 30
 /* Authorized groups who can use any options and config locations */
31
-#define SYSTEM_ADMIN_GROUP TEXT("Administrators")
32
-#define OVPN_ADMIN_GROUP TEXT("OpenVPN Administrators")
31
+#define SYSTEM_ADMIN_GROUP L"Administrators"
32
+#define OVPN_ADMIN_GROUP L"OpenVPN Administrators"
33 33
 /* The last one may be reset in registry: HKLM\Software\OpenVPN\ovpn_admin_group */
34 34
 
35 35
 BOOL
... ...
@@ -23,10 +23,10 @@
23 23
 #define BASIC_H
24 24
 
25 25
 #ifdef _UNICODE
26
-#define PRIsLPTSTR      "ls"
26
+#define PRIsLPWSTR      "ls"
27 27
 #define PRIsLPOLESTR    "ls"
28 28
 #else
29
-#define PRIsLPTSTR      "s"
29
+#define PRIsLPWSTR      "s"
30 30
 #define PRIsLPOLESTR    "ls"
31 31
 #endif
32 32
 #define PRIXGUID        "{%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}"
... ...
@@ -29,7 +29,7 @@
29 29
 #include <objbase.h>
30 30
 #include <setupapi.h>
31 31
 #include <stdio.h>
32
-#include <tchar.h>
32
+#include <wchar.h>
33 33
 
34 34
 #ifdef _MSC_VER
35 35
 #pragma comment(lib, "ole32.lib")
... ...
@@ -37,79 +37,79 @@
37 37
 #endif
38 38
 
39 39
 
40
-const TCHAR title_string[] =
41
-    TEXT(PACKAGE_NAME) TEXT(" ") TEXT(PACKAGE_VERSION)
40
+const WCHAR title_string[] =
41
+    _L(PACKAGE_NAME) L" " _L(PACKAGE_VERSION)
42 42
 ;
43 43
 
44
-static const TCHAR usage_message[] =
45
-    TEXT("%") TEXT(PRIsLPTSTR) TEXT("\n")
46
-    TEXT("\n")
47
-    TEXT("Usage:\n")
48
-    TEXT("\n")
49
-    TEXT("tapctl <command> [<command specific options>]\n")
50
-    TEXT("\n")
51
-    TEXT("Commands:\n")
52
-    TEXT("\n")
53
-    TEXT("create     Create a new TUN/TAP adapter\n")
54
-    TEXT("list       List TUN/TAP adapters\n")
55
-    TEXT("delete     Delete specified network adapter\n")
56
-    TEXT("help       Display this text\n")
57
-    TEXT("\n")
58
-    TEXT("Hint: Use \"tapctl help <command>\" to display help for particular command.\n")
44
+static const WCHAR usage_message[] =
45
+    L"%ls\n"
46
+    L"\n"
47
+    L"Usage:\n"
48
+    L"\n"
49
+    L"tapctl <command> [<command specific options>]\n"
50
+    L"\n"
51
+    L"Commands:\n"
52
+    L"\n"
53
+    L"create     Create a new TUN/TAP adapter\n"
54
+    L"list       List TUN/TAP adapters\n"
55
+    L"delete     Delete specified network adapter\n"
56
+    L"help       Display this text\n"
57
+    L"\n"
58
+    L"Hint: Use \"tapctl help <command>\" to display help for particular command.\n"
59 59
 ;
60 60
 
61
-static const TCHAR usage_message_create[] =
62
-    TEXT("%") TEXT(PRIsLPTSTR) TEXT("\n")
63
-    TEXT("\n")
64
-    TEXT("Creates a new TUN/TAP adapter\n")
65
-    TEXT("\n")
66
-    TEXT("Usage:\n")
67
-    TEXT("\n")
68
-    TEXT("tapctl create [<options>]\n")
69
-    TEXT("\n")
70
-    TEXT("Options:\n")
71
-    TEXT("\n")
72
-    TEXT("--name <name>  Set TUN/TAP adapter name. Should the adapter with given name    \n")
73
-    TEXT("               already exist, an error is returned. If this option is not      \n")
74
-    TEXT("               specified, a default adapter name is chosen by Windows.         \n")
75
-    TEXT("               Note: This name can also be specified as OpenVPN's --dev-node   \n")
76
-    TEXT("               option.                                                         \n")
77
-    TEXT("--hwid <hwid>  Adapter hardware ID. Default value is root\\tap0901, which      \n")
78
-    TEXT("               describes tap-windows6 driver. To work with wintun or ovpn-dco  \n")
79
-    TEXT("               driver, specify 'wintun' or 'ovpn-dco'.                         \n")
80
-    TEXT("\n")
81
-    TEXT("Output:\n")
82
-    TEXT("\n")
83
-    TEXT("This command prints newly created TUN/TAP adapter's GUID to stdout.            \n")
61
+static const WCHAR usage_message_create[] =
62
+    L"%ls\n"
63
+    L"\n"
64
+    L"Creates a new TUN/TAP adapter\n"
65
+    L"\n"
66
+    L"Usage:\n"
67
+    L"\n"
68
+    L"tapctl create [<options>]\n"
69
+    L"\n"
70
+    L"Options:\n"
71
+    L"\n"
72
+    L"--name <name>  Set TUN/TAP adapter name. Should the adapter with given name    \n"
73
+    L"               already exist, an error is returned. If this option is not      \n"
74
+    L"               specified, a default adapter name is chosen by Windows.         \n"
75
+    L"               Note: This name can also be specified as OpenVPN's --dev-node   \n"
76
+    L"               option.                                                         \n"
77
+    L"--hwid <hwid>  Adapter hardware ID. Default value is root\\tap0901, which      \n"
78
+    L"               describes tap-windows6 driver. To work with wintun or ovpn-dco  \n"
79
+    L"               driver, specify 'wintun' or 'ovpn-dco'.                         \n"
80
+    L"\n"
81
+    L"Output:\n"
82
+    L"\n"
83
+    L"This command prints newly created TUN/TAP adapter's GUID to stdout.            \n"
84 84
 ;
85 85
 
86
-static const TCHAR usage_message_list[] =
87
-    TEXT("%") TEXT(PRIsLPTSTR) TEXT("\n")
88
-    TEXT("\n")
89
-    TEXT("Lists TUN/TAP adapters\n")
90
-    TEXT("\n")
91
-    TEXT("Usage:\n")
92
-    TEXT("\n")
93
-    TEXT("tapctl list\n")
94
-    TEXT("\n")
95
-    TEXT("Options:\n")
96
-    TEXT("\n")
97
-    TEXT("--hwid <hwid>  Adapter hardware ID. By default, root\\tap0901, tap0901, wintun and \n")
98
-    TEXT("               ovpn-dco adapters are listed. Use this switch to limit the list.\n")
99
-    TEXT("\n")
100
-    TEXT("Output:\n")
101
-    TEXT("\n")
102
-    TEXT("This command prints all TUN/TAP adapters to stdout.                            \n")
86
+static const WCHAR usage_message_list[] =
87
+    L"%ls\n"
88
+    L"\n"
89
+    L"Lists TUN/TAP adapters\n"
90
+    L"\n"
91
+    L"Usage:\n"
92
+    L"\n"
93
+    L"tapctl list\n"
94
+    L"\n"
95
+    L"Options:\n"
96
+    L"\n"
97
+    L"--hwid <hwid>  Adapter hardware ID. By default, root\\tap0901, tap0901, wintun and \n"
98
+    L"               ovpn-dco adapters are listed. Use this switch to limit the list.\n"
99
+    L"\n"
100
+    L"Output:\n"
101
+    L"\n"
102
+    L"This command prints all TUN/TAP adapters to stdout.                            \n"
103 103
 ;
104 104
 
105
-static const TCHAR usage_message_delete[] =
106
-    TEXT("%") TEXT(PRIsLPTSTR) TEXT("\n")
107
-    TEXT("\n")
108
-    TEXT("Deletes the specified network adapter\n")
109
-    TEXT("\n")
110
-    TEXT("Usage:\n")
111
-    TEXT("\n")
112
-    TEXT("tapctl delete <adapter GUID | adapter name>\n")
105
+static const WCHAR usage_message_delete[] =
106
+    L"%ls\n"
107
+    L"\n"
108
+    L"Deletes the specified network adapter\n"
109
+    L"\n"
110
+    L"Usage:\n"
111
+    L"\n"
112
+    L"tapctl delete <adapter GUID | adapter name>\n"
113 113
 ;
114 114
 
115 115
 
... ...
@@ -119,27 +119,27 @@ static const TCHAR usage_message_delete[] =
119 119
 static void
120 120
 usage(void)
121 121
 {
122
-    _ftprintf(stderr,
123
-              usage_message,
124
-              title_string);
122
+    fwprintf(stderr,
123
+             usage_message,
124
+             title_string);
125 125
 }
126 126
 
127 127
 /**
128 128
  * Checks if adapter with given name doesn't already exist
129 129
  */
130 130
 static BOOL
131
-is_adapter_name_available(LPCTSTR name, struct tap_adapter_node *adapter_list, BOOL log)
131
+is_adapter_name_available(LPCWSTR name, struct tap_adapter_node *adapter_list, BOOL log)
132 132
 {
133 133
     for (struct tap_adapter_node *a = adapter_list; a; a = a->pNext)
134 134
     {
135
-        if (_tcsicmp(name, a->szName) == 0)
135
+        if (wcsicmp(name, a->szName) == 0)
136 136
         {
137 137
             if (log)
138 138
             {
139 139
                 LPOLESTR adapter_id = NULL;
140 140
                 StringFromIID((REFIID)&a->guid, &adapter_id);
141
-                _ftprintf(stderr, TEXT("Adapter \"%") TEXT(PRIsLPTSTR) TEXT("\" already exists (GUID %")
142
-                          TEXT(PRIsLPOLESTR) TEXT(").\n"), a->szName, adapter_id);
141
+                fwprintf(stderr, L"Adapter \"%ls\" already exists (GUID %"
142
+                         L"ls).\n", a->szName, adapter_id);
143 143
                 CoTaskMemFree(adapter_id);
144 144
             }
145 145
 
... ...
@@ -154,26 +154,26 @@ is_adapter_name_available(LPCTSTR name, struct tap_adapter_node *adapter_list, B
154 154
  * Returns unique adapter name based on hwid or NULL if name cannot be generated.
155 155
  * Caller is responsible for freeing it.
156 156
  */
157
-static LPTSTR
158
-get_unique_adapter_name(LPCTSTR hwid, struct tap_adapter_node *adapter_list)
157
+static LPWSTR
158
+get_unique_adapter_name(LPCWSTR hwid, struct tap_adapter_node *adapter_list)
159 159
 {
160 160
     if (hwid == NULL)
161 161
     {
162 162
         return NULL;
163 163
     }
164 164
 
165
-    LPCTSTR base_name;
166
-    if (_tcsicmp(hwid, TEXT("ovpn-dco")) == 0)
165
+    LPCWSTR base_name;
166
+    if (wcsicmp(hwid, L"ovpn-dco") == 0)
167 167
     {
168
-        base_name = TEXT("OpenVPN Data Channel Offload");
168
+        base_name = L"OpenVPN Data Channel Offload";
169 169
     }
170
-    else if (_tcsicmp(hwid, TEXT("wintun")) == 0)
170
+    else if (wcsicmp(hwid, L"wintun") == 0)
171 171
     {
172
-        base_name = TEXT("OpenVPN Wintun");
172
+        base_name = L"OpenVPN Wintun";
173 173
     }
174
-    else if (_tcsicmp(hwid, TEXT("root\\") TEXT(TAP_WIN_COMPONENT_ID)) == 0)
174
+    else if (wcsicmp(hwid, L"root\\" _L(TAP_WIN_COMPONENT_ID)) == 0)
175 175
     {
176
-        base_name = TEXT("OpenVPN TAP-Windows6");
176
+        base_name = L"OpenVPN TAP-Windows6";
177 177
     }
178 178
     else
179 179
     {
... ...
@@ -182,18 +182,18 @@ get_unique_adapter_name(LPCTSTR hwid, struct tap_adapter_node *adapter_list)
182 182
 
183 183
     if (is_adapter_name_available(base_name, adapter_list, FALSE))
184 184
     {
185
-        return _tcsdup(base_name);
185
+        return wcsdup(base_name);
186 186
     }
187 187
 
188
-    size_t name_len = _tcslen(base_name) + 10;
189
-    LPTSTR name = malloc(name_len * sizeof(TCHAR));
188
+    size_t name_len = wcslen(base_name) + 10;
189
+    LPWSTR name = malloc(name_len * sizeof(WCHAR));
190 190
     if (name == NULL)
191 191
     {
192 192
         return NULL;
193 193
     }
194 194
     for (int i = 1; i < 100; ++i)
195 195
     {
196
-        _stprintf_s(name, name_len, TEXT("%ls #%d"), base_name, i);
196
+        swprintf_s(name, name_len, L"%ls #%d", base_name, i);
197 197
 
198 198
         if (is_adapter_name_available(name, adapter_list, FALSE))
199 199
         {
... ...
@@ -208,7 +208,7 @@ get_unique_adapter_name(LPCTSTR hwid, struct tap_adapter_node *adapter_list)
208 208
  * Program entry point
209 209
  */
210 210
 int __cdecl
211
-_tmain(int argc, LPCTSTR argv[])
211
+wmain(int argc, LPCWSTR argv[])
212 212
 {
213 213
     int iResult;
214 214
     BOOL bRebootRequired = FALSE;
... ...
@@ -221,54 +221,54 @@ _tmain(int argc, LPCTSTR argv[])
221 221
         usage();
222 222
         return 1;
223 223
     }
224
-    else if (_tcsicmp(argv[1], TEXT("help")) == 0)
224
+    else if (wcsicmp(argv[1], L"help") == 0)
225 225
     {
226 226
         /* Output help. */
227 227
         if (argc < 3)
228 228
         {
229 229
             usage();
230 230
         }
231
-        else if (_tcsicmp(argv[2], TEXT("create")) == 0)
231
+        else if (wcsicmp(argv[2], L"create") == 0)
232 232
         {
233
-            _ftprintf(stderr, usage_message_create, title_string);
233
+            fwprintf(stderr, usage_message_create, title_string);
234 234
         }
235
-        else if (_tcsicmp(argv[2], TEXT("list")) == 0)
235
+        else if (wcsicmp(argv[2], L"list") == 0)
236 236
         {
237
-            _ftprintf(stderr, usage_message_list, title_string);
237
+            fwprintf(stderr, usage_message_list, title_string);
238 238
         }
239
-        else if (_tcsicmp(argv[2], TEXT("delete")) == 0)
239
+        else if (wcsicmp(argv[2], L"delete") == 0)
240 240
         {
241
-            _ftprintf(stderr, usage_message_delete, title_string);
241
+            fwprintf(stderr, usage_message_delete, title_string);
242 242
         }
243 243
         else
244 244
         {
245
-            _ftprintf(stderr, TEXT("Unknown command \"%") TEXT(PRIsLPTSTR)
246
-                      TEXT("\". Please, use \"tapctl help\" to list supported commands.\n"), argv[2]);
245
+            fwprintf(stderr, L"Unknown command \"%ls"
246
+                     L"\". Please, use \"tapctl help\" to list supported commands.\n", argv[2]);
247 247
         }
248 248
 
249 249
         return 1;
250 250
     }
251
-    else if (_tcsicmp(argv[1], TEXT("create")) == 0)
251
+    else if (wcsicmp(argv[1], L"create") == 0)
252 252
     {
253
-        LPCTSTR szName = NULL;
254
-        LPCTSTR szHwId = TEXT("root\\") TEXT(TAP_WIN_COMPONENT_ID);
253
+        LPCWSTR szName = NULL;
254
+        LPCWSTR szHwId = L"root\\" _L(TAP_WIN_COMPONENT_ID);
255 255
 
256 256
         /* Parse options. */
257 257
         for (int i = 2; i < argc; i++)
258 258
         {
259
-            if (_tcsicmp(argv[i], TEXT("--name")) == 0)
259
+            if (wcsicmp(argv[i], L"--name") == 0)
260 260
             {
261 261
                 szName = argv[++i];
262 262
             }
263
-            else if (_tcsicmp(argv[i], TEXT("--hwid")) == 0)
263
+            else if (wcsicmp(argv[i], L"--hwid") == 0)
264 264
             {
265 265
                 szHwId = argv[++i];
266 266
             }
267 267
             else
268 268
             {
269
-                _ftprintf(stderr, TEXT("Unknown option \"%") TEXT(PRIsLPTSTR)
270
-                          TEXT("\". Please, use \"tapctl help create\" to list supported options. Ignored.\n"),
271
-                          argv[i]);
269
+                fwprintf(stderr, L"Unknown option \"%ls"
270
+                         L"\". Please, use \"tapctl help create\" to list supported options. Ignored.\n",
271
+                         argv[i]);
272 272
             }
273 273
         }
274 274
 
... ...
@@ -277,13 +277,13 @@ _tmain(int argc, LPCTSTR argv[])
277 277
         LPOLESTR szAdapterId = NULL;
278 278
         DWORD dwResult = tap_create_adapter(
279 279
             NULL,
280
-            TEXT("Virtual Ethernet"),
280
+            L"Virtual Ethernet",
281 281
             szHwId,
282 282
             &bRebootRequired,
283 283
             &guidAdapter);
284 284
         if (dwResult != ERROR_SUCCESS)
285 285
         {
286
-            _ftprintf(stderr, TEXT("Creating TUN/TAP adapter failed (error 0x%x).\n"), dwResult);
286
+            fwprintf(stderr, L"Creating TUN/TAP adapter failed (error 0x%x).\n", dwResult);
287 287
             iResult = 1; goto quit;
288 288
         }
289 289
 
... ...
@@ -292,12 +292,12 @@ _tmain(int argc, LPCTSTR argv[])
292 292
         dwResult = tap_list_adapters(NULL, NULL, &pAdapterList);
293 293
         if (dwResult != ERROR_SUCCESS)
294 294
         {
295
-            _ftprintf(stderr, TEXT("Enumerating adapters failed (error 0x%x).\n"), dwResult);
295
+            fwprintf(stderr, L"Enumerating adapters failed (error 0x%x).\n", dwResult);
296 296
             iResult = 1;
297 297
             goto create_delete_adapter;
298 298
         }
299 299
 
300
-        LPTSTR adapter_name = szName ? _tcsdup(szName) : get_unique_adapter_name(szHwId, pAdapterList);
300
+        LPWSTR adapter_name = szName ? wcsdup(szName) : get_unique_adapter_name(szHwId, pAdapterList);
301 301
         if (adapter_name)
302 302
         {
303 303
             /* Check for duplicates when name was specified,
... ...
@@ -313,9 +313,9 @@ _tmain(int argc, LPCTSTR argv[])
313 313
             if (dwResult != ERROR_SUCCESS)
314 314
             {
315 315
                 StringFromIID((REFIID)&guidAdapter, &szAdapterId);
316
-                _ftprintf(stderr, TEXT("Renaming TUN/TAP adapter %") TEXT(PRIsLPOLESTR)
317
-                          TEXT(" to \"%") TEXT(PRIsLPTSTR) TEXT("\" failed (error 0x%x).\n"),
318
-                          szAdapterId, adapter_name, dwResult);
316
+                fwprintf(stderr, L"Renaming TUN/TAP adapter %ls"
317
+                         L" to \"%ls\" failed (error 0x%x).\n",
318
+                         szAdapterId, adapter_name, dwResult);
319 319
                 CoTaskMemFree(szAdapterId);
320 320
                 iResult = 1; goto quit;
321 321
             }
... ...
@@ -334,7 +334,7 @@ create_cleanup_pAdapterList:
334 334
 
335 335
         /* Output adapter GUID. */
336 336
         StringFromIID((REFIID)&guidAdapter, &szAdapterId);
337
-        _ftprintf(stdout, TEXT("%") TEXT(PRIsLPOLESTR) TEXT("\n"), szAdapterId);
337
+        fwprintf(stdout, L"%ls\n", szAdapterId);
338 338
         CoTaskMemFree(szAdapterId);
339 339
 
340 340
         iResult = 0; goto quit;
... ...
@@ -346,28 +346,28 @@ create_delete_adapter:
346 346
             &bRebootRequired);
347 347
         iResult = 1; goto quit;
348 348
     }
349
-    else if (_tcsicmp(argv[1], TEXT("list")) == 0)
349
+    else if (wcsicmp(argv[1], L"list") == 0)
350 350
     {
351
-        TCHAR szzHwId[0x100] =
352
-            TEXT("root\\") TEXT(TAP_WIN_COMPONENT_ID) TEXT("\0")
353
-            TEXT(TAP_WIN_COMPONENT_ID) TEXT("\0")
354
-            TEXT("Wintun\0")
355
-            TEXT("ovpn-dco\0");
351
+        WCHAR szzHwId[0x100] =
352
+            L"root\\" _L(TAP_WIN_COMPONENT_ID) L"\0"
353
+            _L(TAP_WIN_COMPONENT_ID) L"\0"
354
+            L"Wintun\0"
355
+            L"ovpn-dco\0";
356 356
 
357 357
         /* Parse options. */
358 358
         for (int i = 2; i < argc; i++)
359 359
         {
360
-            if (_tcsicmp(argv[i], TEXT("--hwid")) == 0)
360
+            if (wcsicmp(argv[i], L"--hwid") == 0)
361 361
             {
362 362
                 memset(szzHwId, 0, sizeof(szzHwId));
363 363
                 ++i;
364
-                memcpy_s(szzHwId, sizeof(szzHwId) - 2*sizeof(TCHAR) /*requires double zero termination*/, argv[i], _tcslen(argv[i])*sizeof(TCHAR));
364
+                memcpy_s(szzHwId, sizeof(szzHwId) - 2*sizeof(WCHAR) /*requires double zero termination*/, argv[i], wcslen(argv[i])*sizeof(WCHAR));
365 365
             }
366 366
             else
367 367
             {
368
-                _ftprintf(stderr, TEXT("Unknown option \"%") TEXT(PRIsLPTSTR)
369
-                          TEXT("\". Please, use \"tapctl help list\" to list supported options. Ignored.\n"),
370
-                          argv[i]);
368
+                fwprintf(stderr, L"Unknown option \"%ls"
369
+                         L"\". Please, use \"tapctl help list\" to list supported options. Ignored.\n",
370
+                         argv[i]);
371 371
             }
372 372
         }
373 373
 
... ...
@@ -376,7 +376,7 @@ create_delete_adapter:
376 376
         DWORD dwResult = tap_list_adapters(NULL, szzHwId, &pAdapterList);
377 377
         if (dwResult != ERROR_SUCCESS)
378 378
         {
379
-            _ftprintf(stderr, TEXT("Enumerating TUN/TAP adapters failed (error 0x%x).\n"), dwResult);
379
+            fwprintf(stderr, L"Enumerating TUN/TAP adapters failed (error 0x%x).\n", dwResult);
380 380
             iResult = 1; goto quit;
381 381
         }
382 382
 
... ...
@@ -384,19 +384,19 @@ create_delete_adapter:
384 384
         {
385 385
             LPOLESTR szAdapterId = NULL;
386 386
             StringFromIID((REFIID)&pAdapter->guid, &szAdapterId);
387
-            _ftprintf(stdout, TEXT("%") TEXT(PRIsLPOLESTR) TEXT("\t%")
388
-                      TEXT(PRIsLPTSTR) TEXT("\n"), szAdapterId, pAdapter->szName);
387
+            fwprintf(stdout, L"%ls\t%"
388
+                     L"ls\n", szAdapterId, pAdapter->szName);
389 389
             CoTaskMemFree(szAdapterId);
390 390
         }
391 391
 
392 392
         iResult = 0;
393 393
         tap_free_adapter_list(pAdapterList);
394 394
     }
395
-    else if (_tcsicmp(argv[1], TEXT("delete")) == 0)
395
+    else if (wcsicmp(argv[1], L"delete") == 0)
396 396
     {
397 397
         if (argc < 3)
398 398
         {
399
-            _ftprintf(stderr, TEXT("Missing adapter GUID or name. Please, use \"tapctl help delete\" for usage info.\n"));
399
+            fwprintf(stderr, L"Missing adapter GUID or name. Please, use \"tapctl help delete\" for usage info.\n");
400 400
             return 1;
401 401
         }
402 402
 
... ...
@@ -408,7 +408,7 @@ create_delete_adapter:
408 408
             DWORD dwResult = tap_list_adapters(NULL, NULL, &pAdapterList);
409 409
             if (dwResult != ERROR_SUCCESS)
410 410
             {
411
-                _ftprintf(stderr, TEXT("Enumerating TUN/TAP adapters failed (error 0x%x).\n"), dwResult);
411
+                fwprintf(stderr, L"Enumerating TUN/TAP adapters failed (error 0x%x).\n", dwResult);
412 412
                 iResult = 1; goto quit;
413 413
             }
414 414
 
... ...
@@ -416,10 +416,10 @@ create_delete_adapter:
416 416
             {
417 417
                 if (pAdapter == NULL)
418 418
                 {
419
-                    _ftprintf(stderr, TEXT("\"%") TEXT(PRIsLPTSTR) TEXT("\" adapter not found.\n"), argv[2]);
419
+                    fwprintf(stderr, L"\"%ls\" adapter not found.\n", argv[2]);
420 420
                     iResult = 1; goto delete_cleanup_pAdapterList;
421 421
                 }
422
-                else if (_tcsicmp(argv[2], pAdapter->szName) == 0)
422
+                else if (wcsicmp(argv[2], pAdapter->szName) == 0)
423 423
                 {
424 424
                     memcpy(&guidAdapter, &pAdapter->guid, sizeof(GUID));
425 425
                     break;
... ...
@@ -443,8 +443,8 @@ delete_cleanup_pAdapterList:
443 443
             &bRebootRequired);
444 444
         if (dwResult != ERROR_SUCCESS)
445 445
         {
446
-            _ftprintf(stderr, TEXT("Deleting adapter \"%") TEXT(PRIsLPTSTR)
447
-                      TEXT("\" failed (error 0x%x).\n"), argv[2], dwResult);
446
+            fwprintf(stderr, L"Deleting adapter \"%ls"
447
+                     L"\" failed (error 0x%x).\n", argv[2], dwResult);
448 448
             iResult = 1; goto quit;
449 449
         }
450 450
 
... ...
@@ -452,15 +452,15 @@ delete_cleanup_pAdapterList:
452 452
     }
453 453
     else
454 454
     {
455
-        _ftprintf(stderr, TEXT("Unknown command \"%") TEXT(PRIsLPTSTR)
456
-                  TEXT("\". Please, use \"tapctl help\" to list supported commands.\n"), argv[1]);
455
+        fwprintf(stderr, L"Unknown command \"%ls"
456
+                 L"\". Please, use \"tapctl help\" to list supported commands.\n", argv[1]);
457 457
         return 1;
458 458
     }
459 459
 
460 460
 quit:
461 461
     if (bRebootRequired)
462 462
     {
463
-        _ftprintf(stderr, TEXT("A system reboot is required.\n"));
463
+        fwprintf(stderr, L"A system reboot is required.\n");
464 464
     }
465 465
 
466 466
     return iResult;
... ...
@@ -481,19 +481,19 @@ x_msg_va(const unsigned int flags, const char *format, va_list arglist)
481 481
 {
482 482
     /* Output message string. Note: Message strings don't contain line terminators. */
483 483
     vfprintf(stderr, format, arglist);
484
-    _ftprintf(stderr, TEXT("\n"));
484
+    fwprintf(stderr, L"\n");
485 485
 
486 486
     if ((flags & M_ERRNO) != 0)
487 487
     {
488 488
         /* Output system error message (if possible). */
489 489
         DWORD dwResult = GetLastError();
490
-        LPTSTR szErrMessage = NULL;
490
+        LPWSTR szErrMessage = NULL;
491 491
         if (FormatMessage(
492 492
                 FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS,
493 493
                 0,
494 494
                 dwResult,
495 495
                 0,
496
-                (LPTSTR)&szErrMessage,
496
+                (LPWSTR)&szErrMessage,
497 497
                 0,
498 498
                 NULL) && szErrMessage)
499 499
         {
... ...
@@ -502,7 +502,7 @@ x_msg_va(const unsigned int flags, const char *format, va_list arglist)
502 502
             {
503 503
                 if (szErrMessage[i])
504 504
                 {
505
-                    if (!_istspace(szErrMessage[i]))
505
+                    if (!iswspace(szErrMessage[i]))
506 506
                     {
507 507
                         i_last = i + 1;
508 508
                     }
... ...
@@ -515,13 +515,13 @@ x_msg_va(const unsigned int flags, const char *format, va_list arglist)
515 515
             }
516 516
 
517 517
             /* Output error message. */
518
-            _ftprintf(stderr, TEXT("Error 0x%x: %") TEXT(PRIsLPTSTR) TEXT("\n"), dwResult, szErrMessage);
518
+            fwprintf(stderr, L"Error 0x%x: %ls\n", dwResult, szErrMessage);
519 519
 
520 520
             LocalFree(szErrMessage);
521 521
         }
522 522
         else
523 523
         {
524
-            _ftprintf(stderr, TEXT("Error 0x%x\n"), dwResult);
524
+            fwprintf(stderr, L"Error 0x%x\n", dwResult);
525 525
         }
526 526
     }
527 527
 }
... ...
@@ -30,7 +30,7 @@
30 30
 #include <objbase.h>
31 31
 #include <setupapi.h>
32 32
 #include <stdio.h>
33
-#include <tchar.h>
33
+#include <wchar.h>
34 34
 #include <newdev.h>
35 35
 
36 36
 #ifdef _MSC_VER
... ...
@@ -43,8 +43,8 @@
43 43
 
44 44
 const static GUID GUID_DEVCLASS_NET = { 0x4d36e972L, 0xe325, 0x11ce, { 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 } };
45 45
 
46
-const static TCHAR szAdapterRegKeyPathTemplate[] = TEXT("SYSTEM\\CurrentControlSet\\Control\\Network\\%") TEXT(PRIsLPOLESTR) TEXT("\\%") TEXT(PRIsLPOLESTR) TEXT("\\Connection");
47
-#define ADAPTER_REGKEY_PATH_MAX (_countof(TEXT("SYSTEM\\CurrentControlSet\\Control\\Network\\")) - 1 + 38 + _countof(TEXT("\\")) - 1 + 38 + _countof(TEXT("\\Connection")))
46
+const static WCHAR szAdapterRegKeyPathTemplate[] = L"SYSTEM\\CurrentControlSet\\Control\\Network\\%ls\\%ls\\Connection";
47
+#define ADAPTER_REGKEY_PATH_MAX (_countof(L"SYSTEM\\CurrentControlSet\\Control\\Network\\") - 1 + 38 + _countof(L"\\") - 1 + 38 + _countof(L"\\Connection"))
48 48
 
49 49
 /**
50 50
  * Dynamically load a library and find a function in it
... ...
@@ -104,10 +104,10 @@ find_function(const WCHAR *libname, const char *funcname, HMODULE *m)
104 104
  * @return Number of characters not counting the final zero terminator
105 105
  **/
106 106
 static inline size_t
107
-_tcszlen(_In_z_ LPCTSTR szz)
107
+wcszlen(_In_z_ LPCWSTR szz)
108 108
 {
109
-    LPCTSTR s;
110
-    for (s = szz; s[0]; s += _tcslen(s) + 1)
109
+    LPCWSTR s;
110
+    for (s = szz; s[0]; s += wcslen(s) + 1)
111 111
     {
112 112
     }
113 113
     return s - szz;
... ...
@@ -124,12 +124,12 @@ _tcszlen(_In_z_ LPCTSTR szz)
124 124
  *
125 125
  * @return Pointer to the string in szzHay that matches szNeedle is found; NULL otherwise
126 126
  */
127
-static LPCTSTR
128
-_tcszistr(_In_z_ LPCTSTR szzHay, _In_z_ LPCTSTR szNeedle)
127
+static LPCWSTR
128
+wcszistr(_In_z_ LPCWSTR szzHay, _In_z_ LPCWSTR szNeedle)
129 129
 {
130
-    for (LPCTSTR s = szzHay; s[0]; s += _tcslen(s) + 1)
130
+    for (LPCWSTR s = szzHay; s[0]; s += wcslen(s) + 1)
131 131
     {
132
-        if (_tcsicmp(s, szNeedle) == 0)
132
+        if (wcsicmp(s, szNeedle) == 0)
133 133
         {
134 134
             return s;
135 135
         }
... ...
@@ -405,8 +405,8 @@ disable_device(
405 405
 static DWORD
406 406
 get_reg_string(
407 407
     _In_ HKEY hKey,
408
-    _In_ LPCTSTR szName,
409
-    _Out_ LPTSTR *pszValue)
408
+    _In_ LPCWSTR szName,
409
+    _Out_ LPWSTR *pszValue)
410 410
 {
411 411
     if (pszValue == NULL)
412 412
     {
... ...
@@ -424,7 +424,7 @@ get_reg_string(
424 424
     if (dwResult != ERROR_SUCCESS)
425 425
     {
426 426
         SetLastError(dwResult); /* MSDN does not mention RegQueryValueEx() to set GetLastError(). But we do have an error code. Set last error manually. */
427
-        msg(M_NONFATAL | M_ERRNO, "%s: enumerating \"%" PRIsLPTSTR "\" registry value failed", __FUNCTION__, szName);
427
+        msg(M_NONFATAL | M_ERRNO, "%s: enumerating \"%ls\" registry value failed", __FUNCTION__, szName);
428 428
         return dwResult;
429 429
     }
430 430
 
... ...
@@ -434,7 +434,7 @@ get_reg_string(
434 434
         case REG_EXPAND_SZ:
435 435
         {
436 436
             /* Read value. */
437
-            LPTSTR szValue = (LPTSTR)malloc(dwSize);
437
+            LPWSTR szValue = (LPWSTR)malloc(dwSize);
438 438
             if (szValue == NULL)
439 439
             {
440 440
                 msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, dwSize);
... ...
@@ -451,7 +451,7 @@ get_reg_string(
451 451
             if (dwResult != ERROR_SUCCESS)
452 452
             {
453 453
                 SetLastError(dwResult); /* MSDN does not mention RegQueryValueEx() to set GetLastError(). But we do have an error code. Set last error manually. */
454
-                msg(M_NONFATAL | M_ERRNO, "%s: reading \"%" PRIsLPTSTR "\" registry value failed", __FUNCTION__, szName);
454
+                msg(M_NONFATAL | M_ERRNO, "%s: reading \"%ls\" registry value failed", __FUNCTION__, szName);
455 455
                 free(szValue);
456 456
                 return dwResult;
457 457
             }
... ...
@@ -463,11 +463,11 @@ get_reg_string(
463 463
                     dwSizeExp = dwSize * 2,
464 464
                     dwCountExp =
465 465
 #ifdef UNICODE
466
-                    dwSizeExp / sizeof(TCHAR);
466
+                    dwSizeExp / sizeof(WCHAR);
467 467
 #else
468
-                    dwSizeExp / sizeof(TCHAR) - 1;     /* Note: ANSI version requires one extra char. */
468
+                    dwSizeExp / sizeof(WCHAR) - 1;     /* Note: ANSI version requires one extra char. */
469 469
 #endif
470
-                LPTSTR szValueExp = (LPTSTR)malloc(dwSizeExp);
470
+                LPWSTR szValueExp = (LPWSTR)malloc(dwSizeExp);
471 471
                 if (szValueExp == NULL)
472 472
                 {
473 473
                     free(szValue);
... ...
@@ -481,7 +481,7 @@ get_reg_string(
481 481
                     );
482 482
                 if (dwCountExpResult == 0)
483 483
                 {
484
-                    msg(M_NONFATAL | M_ERRNO, "%s: expanding \"%" PRIsLPTSTR "\" registry value failed", __FUNCTION__, szName);
484
+                    msg(M_NONFATAL | M_ERRNO, "%s: expanding \"%ls\" registry value failed", __FUNCTION__, szName);
485 485
                     free(szValueExp);
486 486
                     free(szValue);
487 487
                     return dwResult;
... ...
@@ -498,13 +498,13 @@ get_reg_string(
498 498
                     /* Retry with a bigger buffer. */
499 499
                     free(szValueExp);
500 500
 #ifdef UNICODE
501
-                    dwSizeExp = dwCountExpResult * sizeof(TCHAR);
501
+                    dwSizeExp = dwCountExpResult * sizeof(WCHAR);
502 502
 #else
503 503
                     /* Note: ANSI version requires one extra char. */
504
-                    dwSizeExp = (dwCountExpResult + 1) * sizeof(TCHAR);
504
+                    dwSizeExp = (dwCountExpResult + 1) * sizeof(WCHAR);
505 505
 #endif
506 506
                     dwCountExp = dwCountExpResult;
507
-                    szValueExp = (LPTSTR)malloc(dwSizeExp);
507
+                    szValueExp = (LPWSTR)malloc(dwSizeExp);
508 508
                     if (szValueExp == NULL)
509 509
                     {
510 510
                         free(szValue);
... ...
@@ -528,7 +528,7 @@ get_reg_string(
528 528
         }
529 529
 
530 530
         default:
531
-            msg(M_NONFATAL, "%s: \"%" PRIsLPTSTR "\" registry value is not string (type %u)", __FUNCTION__, dwValueType);
531
+            msg(M_NONFATAL, "%s: \"%ls\" registry value is not string (type %u)", __FUNCTION__, dwValueType);
532 532
             return ERROR_UNSUPPORTED_TYPE;
533 533
     }
534 534
 }
... ...
@@ -584,8 +584,8 @@ get_net_adapter_guid(
584 584
     while (iNumAttempts > 0)
585 585
     {
586 586
         /* Query the NetCfgInstanceId value. Using get_reg_string() right on might clutter the output with error messages while the registry is still being populated. */
587
-        LPTSTR szCfgGuidString = NULL;
588
-        dwResult = RegQueryValueEx(hKey, TEXT("NetCfgInstanceId"), NULL, NULL, NULL, NULL);
587
+        LPWSTR szCfgGuidString = NULL;
588
+        dwResult = RegQueryValueEx(hKey, L"NetCfgInstanceId", NULL, NULL, NULL, NULL);
589 589
         if (dwResult != ERROR_SUCCESS)
590 590
         {
591 591
             if (dwResult == ERROR_FILE_NOT_FOUND && --iNumAttempts > 0)
... ...
@@ -603,7 +603,7 @@ get_net_adapter_guid(
603 603
         /* Read the NetCfgInstanceId value now. */
604 604
         dwResult = get_reg_string(
605 605
             hKey,
606
-            TEXT("NetCfgInstanceId"),
606
+            L"NetCfgInstanceId",
607 607
             &szCfgGuidString);
608 608
         if (dwResult != ERROR_SUCCESS)
609 609
         {
... ...
@@ -722,8 +722,8 @@ get_device_reg_property(
722 722
 DWORD
723 723
 tap_create_adapter(
724 724
     _In_opt_ HWND hwndParent,
725
-    _In_opt_ LPCTSTR szDeviceDescription,
726
-    _In_ LPCTSTR szHwId,
725
+    _In_opt_ LPCWSTR szDeviceDescription,
726
+    _In_ LPCWSTR szHwId,
727 727
     _Inout_ LPBOOL pbRebootRequired,
728 728
     _Out_ LPGUID pguidAdapter)
729 729
 {
... ...
@@ -747,7 +747,7 @@ tap_create_adapter(
747 747
     }
748 748
 
749 749
     /* Get the device class name from GUID. */
750
-    TCHAR szClassName[MAX_CLASS_NAME_LEN];
750
+    WCHAR szClassName[MAX_CLASS_NAME_LEN];
751 751
     if (!SetupDiClassNameFromGuid(
752 752
             &GUID_DEVCLASS_NET,
753 753
             szClassName,
... ...
@@ -790,7 +790,7 @@ tap_create_adapter(
790 790
             hDevInfoList,
791 791
             &devinfo_data,
792 792
             SPDRP_HARDWAREID,
793
-            (const BYTE *)szHwId, (DWORD)((_tcslen(szHwId) + 1) * sizeof(TCHAR))))
793
+            (const BYTE *)szHwId, (DWORD)((wcslen(szHwId) + 1) * sizeof(WCHAR))))
794 794
     {
795 795
         dwResult = GetLastError();
796 796
         msg(M_NONFATAL, "%s: SetupDiSetDeviceRegistryProperty failed", __FUNCTION__);
... ...
@@ -965,7 +965,7 @@ execute_on_first_adapter(
965 965
             {
966 966
                 LPOLESTR szAdapterId = NULL;
967 967
                 StringFromIID((REFIID)pguidAdapter, &szAdapterId);
968
-                msg(M_NONFATAL, "%s: Adapter %" PRIsLPOLESTR " not found", __FUNCTION__, szAdapterId);
968
+                msg(M_NONFATAL, "%s: Adapter %ls not found", __FUNCTION__, szAdapterId);
969 969
                 CoTaskMemFree(szAdapterId);
970 970
                 dwResult = ERROR_FILE_NOT_FOUND;
971 971
                 goto cleanup_hDevInfoList;
... ...
@@ -1062,7 +1062,7 @@ ExecCommand(const WCHAR *cmdline)
1062 1062
 DWORD
1063 1063
 tap_set_adapter_name(
1064 1064
     _In_ LPCGUID pguidAdapter,
1065
-    _In_ LPCTSTR szName,
1065
+    _In_ LPCWSTR szName,
1066 1066
     _In_ BOOL bSilent)
1067 1067
 {
1068 1068
     DWORD dwResult;
... ...
@@ -1083,8 +1083,8 @@ tap_set_adapter_name(
1083 1083
     StringFromIID((REFIID)pguidAdapter, &szAdapterId);
1084 1084
 
1085 1085
     /* Render registry key path. */
1086
-    TCHAR szRegKey[ADAPTER_REGKEY_PATH_MAX];
1087
-    _stprintf_s(
1086
+    WCHAR szRegKey[ADAPTER_REGKEY_PATH_MAX];
1087
+    swprintf_s(
1088 1088
         szRegKey, _countof(szRegKey),
1089 1089
         szAdapterRegKeyPathTemplate,
1090 1090
         szDevClassNetId,
... ...
@@ -1101,12 +1101,12 @@ tap_set_adapter_name(
1101 1101
     if (dwResult != ERROR_SUCCESS)
1102 1102
     {
1103 1103
         SetLastError(dwResult); /* MSDN does not mention RegOpenKeyEx() to set GetLastError(). But we do have an error code. Set last error manually. */
1104
-        msg(msg_flag, "%s: RegOpenKeyEx(HKLM, \"%" PRIsLPTSTR "\") failed", __FUNCTION__, szRegKey);
1104
+        msg(msg_flag, "%s: RegOpenKeyEx(HKLM, \"%ls\") failed", __FUNCTION__, szRegKey);
1105 1105
         goto cleanup_szAdapterId;
1106 1106
     }
1107 1107
 
1108
-    LPTSTR szOldName = NULL;
1109
-    dwResult = get_reg_string(hKey, TEXT("Name"), &szOldName);
1108
+    LPWSTR szOldName = NULL;
1109
+    dwResult = get_reg_string(hKey, L"Name", &szOldName);
1110 1110
     if (dwResult != ERROR_SUCCESS)
1111 1111
     {
1112 1112
         SetLastError(dwResult);
... ...
@@ -1115,11 +1115,11 @@ tap_set_adapter_name(
1115 1115
     }
1116 1116
 
1117 1117
     /* rename adapter via netsh call */
1118
-    const TCHAR *szFmt = TEXT("netsh interface set interface name=\"%")
1119
-                         TEXT(PRIsLPTSTR) TEXT("\" newname=\"%") TEXT(PRIsLPTSTR) TEXT("\"");
1120
-    size_t ncmdline = _tcslen(szFmt) + _tcslen(szOldName) + _tcslen(szName) + 1;
1121
-    WCHAR *szCmdLine = malloc(ncmdline * sizeof(TCHAR));
1122
-    _stprintf_s(szCmdLine, ncmdline, szFmt, szOldName, szName);
1118
+    const WCHAR *szFmt = L"netsh interface set interface name=\"%"
1119
+                         L"ls\" newname=\"%ls\"";
1120
+    size_t ncmdline = wcslen(szFmt) + wcslen(szOldName) + wcslen(szName) + 1;
1121
+    WCHAR *szCmdLine = malloc(ncmdline * sizeof(WCHAR));
1122
+    swprintf_s(szCmdLine, ncmdline, szFmt, szOldName, szName);
1123 1123
 
1124 1124
     free(szOldName);
1125 1125
 
... ...
@@ -1145,7 +1145,7 @@ cleanup_szAdapterId:
1145 1145
 DWORD
1146 1146
 tap_list_adapters(
1147 1147
     _In_opt_ HWND hwndParent,
1148
-    _In_opt_ LPCTSTR szzHwIDs,
1148
+    _In_opt_ LPCWSTR szzHwIDs,
1149 1149
     _Out_ struct tap_adapter_node **ppAdapter)
1150 1150
 {
1151 1151
     DWORD dwResult;
... ...
@@ -1210,7 +1210,7 @@ tap_list_adapters(
1210 1210
 
1211 1211
         /* Get device hardware ID(s). */
1212 1212
         DWORD dwDataType = REG_NONE;
1213
-        LPTSTR szzDeviceHardwareIDs = NULL;
1213
+        LPWSTR szzDeviceHardwareIDs = NULL;
1214 1214
         dwResult = get_device_reg_property(
1215 1215
             hDevInfoList,
1216 1216
             &devinfo_data,
... ...
@@ -1226,7 +1226,7 @@ tap_list_adapters(
1226 1226
         /* Check that hardware ID is REG_SZ/REG_MULTI_SZ, and optionally if it matches ours. */
1227 1227
         if (dwDataType == REG_SZ)
1228 1228
         {
1229
-            if (szzHwIDs && !_tcszistr(szzHwIDs, szzDeviceHardwareIDs))
1229
+            if (szzHwIDs && !wcszistr(szzHwIDs, szzDeviceHardwareIDs))
1230 1230
             {
1231 1231
                 /* This is not our device. Skip it. */
1232 1232
                 goto cleanup_szzDeviceHardwareIDs;
... ...
@@ -1236,14 +1236,14 @@ tap_list_adapters(
1236 1236
         {
1237 1237
             if (szzHwIDs)
1238 1238
             {
1239
-                for (LPTSTR s = szzDeviceHardwareIDs;; s += _tcslen(s) + 1)
1239
+                for (LPWSTR s = szzDeviceHardwareIDs;; s += wcslen(s) + 1)
1240 1240
                 {
1241 1241
                     if (s[0] == 0)
1242 1242
                     {
1243 1243
                         /* This is not our device. Skip it. */
1244 1244
                         goto cleanup_szzDeviceHardwareIDs;
1245 1245
                     }
1246
-                    else if (_tcszistr(szzHwIDs, s))
1246
+                    else if (wcszistr(szzHwIDs, s))
1247 1247
                     {
1248 1248
                         /* This is our device. */
1249 1249
                         break;
... ...
@@ -1271,8 +1271,8 @@ tap_list_adapters(
1271 1271
         StringFromIID((REFIID)&guidAdapter, &szAdapterId);
1272 1272
 
1273 1273
         /* Render registry key path. */
1274
-        TCHAR szRegKey[ADAPTER_REGKEY_PATH_MAX];
1275
-        _stprintf_s(
1274
+        WCHAR szRegKey[ADAPTER_REGKEY_PATH_MAX];
1275
+        swprintf_s(
1276 1276
             szRegKey, _countof(szRegKey),
1277 1277
             szAdapterRegKeyPathTemplate,
1278 1278
             szDevClassNetId,
... ...
@@ -1289,26 +1289,26 @@ tap_list_adapters(
1289 1289
         if (dwResult != ERROR_SUCCESS)
1290 1290
         {
1291 1291
             SetLastError(dwResult); /* MSDN does not mention RegOpenKeyEx() to set GetLastError(). But we do have an error code. Set last error manually. */
1292
-            msg(M_WARN | M_ERRNO, "%s: RegOpenKeyEx(HKLM, \"%" PRIsLPTSTR "\") failed", __FUNCTION__, szRegKey);
1292
+            msg(M_WARN | M_ERRNO, "%s: RegOpenKeyEx(HKLM, \"%ls\") failed", __FUNCTION__, szRegKey);
1293 1293
             goto cleanup_szAdapterId;
1294 1294
         }
1295 1295
 
1296 1296
         /* Read adapter name. */
1297
-        LPTSTR szName = NULL;
1297
+        LPWSTR szName = NULL;
1298 1298
         dwResult = get_reg_string(
1299 1299
             hKey,
1300
-            TEXT("Name"),
1300
+            L"Name",
1301 1301
             &szName);
1302 1302
         if (dwResult != ERROR_SUCCESS)
1303 1303
         {
1304 1304
             SetLastError(dwResult);
1305
-            msg(M_WARN | M_ERRNO, "%s: Cannot determine %" PRIsLPOLESTR " adapter name", __FUNCTION__, szAdapterId);
1305
+            msg(M_WARN | M_ERRNO, "%s: Cannot determine %ls adapter name", __FUNCTION__, szAdapterId);
1306 1306
             goto cleanup_hKey;
1307 1307
         }
1308 1308
 
1309 1309
         /* Append to the list. */
1310
-        size_t hwid_size = (_tcszlen(szzDeviceHardwareIDs) + 1) * sizeof(TCHAR);
1311
-        size_t name_size = (_tcslen(szName) + 1) * sizeof(TCHAR);
1310
+        size_t hwid_size = (wcszlen(szzDeviceHardwareIDs) + 1) * sizeof(WCHAR);
1311
+        size_t name_size = (wcslen(szName) + 1) * sizeof(WCHAR);
1312 1312
         struct tap_adapter_node *node = (struct tap_adapter_node *)malloc(sizeof(struct tap_adapter_node) + hwid_size + name_size);
1313 1313
         if (node == NULL)
1314 1314
         {
... ...
@@ -1317,9 +1317,9 @@ tap_list_adapters(
1317 1317
         }
1318 1318
 
1319 1319
         memcpy(&node->guid, &guidAdapter, sizeof(GUID));
1320
-        node->szzHardwareIDs = (LPTSTR)(node + 1);
1320
+        node->szzHardwareIDs = (LPWSTR)(node + 1);
1321 1321
         memcpy(node->szzHardwareIDs, szzDeviceHardwareIDs, hwid_size);
1322
-        node->szName = (LPTSTR)((LPBYTE)node->szzHardwareIDs + hwid_size);
1322
+        node->szName = (LPWSTR)((LPBYTE)node->szzHardwareIDs + hwid_size);
1323 1323
         memcpy(node->szName, szName, name_size);
1324 1324
         node->pNext = NULL;
1325 1325
         if (pAdapterTail)
... ...
@@ -52,8 +52,8 @@
52 52
 DWORD
53 53
 tap_create_adapter(
54 54
     _In_opt_ HWND hwndParent,
55
-    _In_opt_ LPCTSTR szDeviceDescription,
56
-    _In_ LPCTSTR szHwId,
55
+    _In_opt_ LPCWSTR szDeviceDescription,
56
+    _In_ LPCWSTR szHwId,
57 57
     _Inout_ LPBOOL pbRebootRequired,
58 58
     _Out_ LPGUID pguidAdapter);
59 59
 
... ...
@@ -126,7 +126,7 @@ tap_enable_adapter(
126 126
 DWORD
127 127
 tap_set_adapter_name(
128 128
     _In_ LPCGUID pguidAdapter,
129
-    _In_ LPCTSTR szName,
129
+    _In_ LPCWSTR szName,
130 130
     _In_ BOOL bSilent);
131 131
 
132 132
 
... ...
@@ -136,8 +136,8 @@ tap_set_adapter_name(
136 136
 struct tap_adapter_node
137 137
 {
138 138
     GUID guid;             /**< Adapter GUID */
139
-    LPTSTR szzHardwareIDs; /**< Device hardware ID(s) */
140
-    LPTSTR szName;         /**< Adapter name */
139
+    LPWSTR szzHardwareIDs; /**< Device hardware ID(s) */
140
+    LPWSTR szName;         /**< Adapter name */
141 141
 
142 142
     struct tap_adapter_node *pNext; /**< Pointer to next adapter */
143 143
 };
... ...
@@ -165,7 +165,7 @@ struct tap_adapter_node
165 165
 DWORD
166 166
 tap_list_adapters(
167 167
     _In_opt_ HWND hwndParent,
168
-    _In_opt_ LPCTSTR szzHwIDs,
168
+    _In_opt_ LPCWSTR szzHwIDs,
169 169
     _Out_ struct tap_adapter_node **ppAdapterList);
170 170
 
171 171