Skip to content

Commit 68fbbb5

Browse files
committed
[CONUTILS] Improve library build interface; avoid using winuser.h; fix x64 build warnings
conutils\pager.c(658): warning C4267: '=': conversion from 'size_t' to 'DWORD', possible loss of data conutils\outstream.c(179),(263): warning C4267: '=': conversion from 'size_t' to 'DWORD', possible loss of data conutils\outstream.c(433): warning C4267: '=': conversion from 'size_t' to 'INT', possible loss of data
1 parent d5697b2 commit 68fbbb5

9 files changed

Lines changed: 63 additions & 39 deletions

File tree

sdk/lib/conutils/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ list(APPEND SOURCE
99
# conutils.h
1010
)
1111

12-
add_library(conutils ${SOURCE})
12+
add_library(conutils STATIC ${SOURCE})
1313
# add_pch(conutils conutils.h SOURCE)
1414
add_dependencies(conutils xdk)
15+
target_include_directories(conutils INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
1516
target_link_libraries(conutils ${PSEH_LIB})
1617
add_importlibs(conutils msvcrt kernel32)

sdk/lib/conutils/instream.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@
3636

3737
#include <windef.h>
3838
#include <winbase.h>
39+
#include <wincon.h> // Console APIs (only if kernel32 support included)
3940
#include <winnls.h>
40-
#include <winuser.h> // MAKEINTRESOURCEW, RT_STRING
41-
#include <wincon.h> // Console APIs (only if kernel32 support included)
4241
#include <strsafe.h>
4342

4443
/* PSEH for SEH Support */
@@ -48,5 +47,4 @@
4847
#include "stream.h"
4948
#include "stream_private.h"
5049

51-
5250
/* EOF */

sdk/lib/conutils/outstream.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@
3636

3737
#include <windef.h>
3838
#include <winbase.h>
39+
#include <wincon.h> // Console APIs (only if kernel32 support included)
3940
#include <winnls.h>
40-
#include <winuser.h> // MAKEINTRESOURCEW, RT_STRING
41-
#include <wincon.h> // Console APIs (only if kernel32 support included)
4241
#include <strsafe.h>
4342

4443
/* PSEH for SEH Support */
@@ -176,7 +175,7 @@ ConWrite(
176175
}
177176

178177
/* Write everything up to \n */
179-
dwNumBytes = ((PCWCH)p - (PCWCH)szStr) * sizeof(WCHAR);
178+
dwNumBytes = (DWORD)(((PCWCH)p - (PCWCH)szStr) * sizeof(WCHAR));
180179
WriteFile(Stream->hHandle, szStr, dwNumBytes, &dwNumBytes, NULL);
181180

182181
/*
@@ -260,7 +259,7 @@ ConWrite(
260259
}
261260

262261
/* Write everything up to \n */
263-
dwNumBytes = ((PCCH)p - (PCCH)szStr) * sizeof(CHAR);
262+
dwNumBytes = (DWORD)(((PCCH)p - (PCCH)szStr) * sizeof(CHAR));
264263
WriteFile(Stream->hHandle, szStr, dwNumBytes, &dwNumBytes, NULL);
265264

266265
/*
@@ -430,8 +429,8 @@ ConPuts(
430429
{
431430
INT Len;
432431

433-
Len = wcslen(szStr);
434-
CON_STREAM_WRITE2(Stream, szStr, Len, Len);
432+
Len = (INT)wcslen(szStr);
433+
CON_STREAM_WRITE2(Stream, szStr, (DWORD)Len, Len);
435434

436435
/* Fixup returned length in case of errors */
437436
if (Len < 0)
@@ -611,8 +610,8 @@ ConResPuts(
611610
IN PCON_STREAM Stream,
612611
IN UINT uID)
613612
{
614-
return ConResPutsEx(Stream, NULL /*GetModuleHandleW(NULL)*/,
615-
uID, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
613+
return ConResPutsEx(Stream, NULL, uID,
614+
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
616615
}
617616

618617
/**
@@ -697,9 +696,8 @@ ConResPrintfV(
697696
IN UINT uID,
698697
IN va_list args)
699698
{
700-
return ConResPrintfExV(Stream, NULL /*GetModuleHandleW(NULL)*/,
701-
uID, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
702-
args);
699+
return ConResPrintfExV(Stream, NULL, uID,
700+
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), args);
703701
}
704702

705703
/**
@@ -1332,8 +1330,7 @@ ConResMsgPrintfV(
13321330
IN UINT uID,
13331331
IN va_list *Arguments OPTIONAL)
13341332
{
1335-
return ConResMsgPrintfExV(Stream, NULL /*GetModuleHandleW(NULL)*/,
1336-
dwFlags, uID,
1333+
return ConResMsgPrintfExV(Stream, NULL, dwFlags, uID,
13371334
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
13381335
Arguments);
13391336
}

sdk/lib/conutils/pager.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919

2020
#include <windef.h>
2121
#include <winbase.h>
22-
// #include <winnls.h>
23-
#include <wincon.h> // Console APIs (only if kernel32 support included)
24-
#include <winnls.h> // for WideCharToMultiByte
22+
#include <wincon.h> // Console APIs (only if kernel32 support included)
23+
#include <winnls.h> // For WideCharToMultiByte
2524
#include <strsafe.h>
2625

2726
#include "conutils.h"
@@ -219,7 +218,7 @@ static BOOL
219218
ConPagerWorker(
220219
IN PCON_PAGER Pager,
221220
IN PCTCH TextBuff,
222-
IN DWORD cch)
221+
IN SIZE_T cch)
223222
{
224223
const DWORD PageColumns = Pager->PageColumns;
225224
const DWORD ScrollRows = Pager->ScrollRows;
@@ -551,7 +550,7 @@ ConWritePaging(
551550
IN PAGE_PROMPT PagePrompt,
552551
IN BOOL StartPaging,
553552
IN PCTCH szStr,
554-
IN DWORD len)
553+
IN SIZE_T len)
555554
{
556555
CONSOLE_SCREEN_BUFFER_INFO csbi;
557556
BOOL bIsConsole;
@@ -649,7 +648,7 @@ ConPutsPaging(
649648
IN BOOL StartPaging,
650649
IN PCTSTR szStr)
651650
{
652-
DWORD len;
651+
SIZE_T len;
653652

654653
/* Return if no string has been given */
655654
if (szStr == NULL)
@@ -673,8 +672,7 @@ ConResPagingEx(
673672
Len = K32LoadStringW(hInstance, uID, (PWSTR)&szStr, 0);
674673
if (szStr && Len)
675674
return ConWritePaging(Pager, PagePrompt, StartPaging, szStr, Len);
676-
else
677-
return TRUE;
675+
return TRUE;
678676
}
679677

680678
BOOL
@@ -684,8 +682,7 @@ ConResPaging(
684682
IN BOOL StartPaging,
685683
IN UINT uID)
686684
{
687-
return ConResPagingEx(Pager, PagePrompt, StartPaging,
688-
NULL /*GetModuleHandleW(NULL)*/, uID);
685+
return ConResPagingEx(Pager, PagePrompt, StartPaging, NULL, uID);
689686
}
690687

691688
/* EOF */

sdk/lib/conutils/pager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ typedef BOOL
3434
(__stdcall *CON_PAGER_LINE_FN)(
3535
IN OUT struct _CON_PAGER *Pager,
3636
IN PCTCH line,
37-
IN DWORD cch);
37+
IN SIZE_T cch);
3838

3939
/* Flags for CON_PAGER */
4040
#define CON_PAGER_EXPAND_TABS (1 << 0)
@@ -91,7 +91,7 @@ ConWritePaging(
9191
IN PAGE_PROMPT PagePrompt,
9292
IN BOOL StartPaging,
9393
IN PCTCH szStr,
94-
IN DWORD len);
94+
IN SIZE_T len);
9595

9696
BOOL
9797
ConPutsPaging(

sdk/lib/conutils/screen.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919

2020
#include <windef.h>
2121
#include <winbase.h>
22-
// #include <winnls.h>
23-
#include <wincon.h> // Console APIs (only if kernel32 support included)
22+
#include <wincon.h> // Console APIs (only if kernel32 support included)
2423
#include <strsafe.h>
2524

2625
#include "conutils.h"

sdk/lib/conutils/stream.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@
3434

3535
#include <windef.h>
3636
#include <winbase.h>
37+
#include <wincon.h> // Console APIs (only if kernel32 support included)
3738
#include <winnls.h>
38-
// #include <winuser.h> // MAKEINTRESOURCEW, RT_STRING
39-
#include <wincon.h> // Console APIs (only if kernel32 support included)
4039
#include <strsafe.h>
4140

4241
#include "conutils.h"

sdk/lib/conutils/utils.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121

2222
#include <windef.h>
2323
#include <winbase.h>
24-
#include <winnls.h>
25-
#include <winuser.h> // MAKEINTRESOURCEW, RT_STRING
26-
#include <wincon.h> // Console APIs (only if kernel32 support included)
24+
#include <wincon.h> // Console APIs (only if kernel32 support included)
25+
//#include <winnls.h>
2726
#include <strsafe.h>
2827

2928
/* PSEH for SEH Support */
@@ -32,6 +31,18 @@
3231
// #include "conutils.h"
3332
#include "utils.h"
3433

34+
/* Predefined Resource Types */
35+
#ifndef MAKEINTRESOURCE
36+
#define MAKEINTRESOURCE(i) ((ULONG_PTR)((WORD)(i)))
37+
#endif
38+
#ifndef RT_STRING
39+
#define RT_STRING MAKEINTRESOURCE(6)
40+
#endif
41+
#ifndef RT_MESSAGETABLE
42+
#define RT_MESSAGETABLE MAKEINTRESOURCE(11)
43+
#endif
44+
45+
3546
#if 0 // The following function may be useful in the future...
3647

3748
// Performs MultiByteToWideChar then WideCharToMultiByte .
@@ -131,9 +142,8 @@ K32LoadStringExW(
131142
p += *p + 1;
132143

133144
/*
134-
* If nBufferMax == 0, then return a read-only pointer
135-
* to the resource itself in lpBuffer it is assumed that
136-
* lpBuffer is actually a (LPWSTR*).
145+
* If nBufferMax == 0, then return a read-only pointer to the resource
146+
* itself in lpBuffer. It is assumed that lpBuffer is actually a (LPWSTR*).
137147
*/
138148
if (nBufferMax == 0)
139149
{

sdk/lib/conutils/utils.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@
2828
extern "C" {
2929
#endif
3030

31+
/* Avoid including winuser.h for these definitions */
32+
#ifndef IS_INTRESOURCE
33+
#define IS_INTRESOURCE(i) (((ULONG_PTR)(i) >> 16) == 0)
34+
#endif
35+
#ifndef MAKEINTRESOURCEA
36+
#define MAKEINTRESOURCEA(i) ((LPSTR)(ULONG_PTR)LOWORD(i))
37+
#endif
38+
#ifndef MAKEINTRESOURCEW
39+
#define MAKEINTRESOURCEW(i) ((LPWSTR)(ULONG_PTR)LOWORD(i))
40+
#endif
41+
// #define MAKEINTRESOURCE(i) ((ULONG_PTR)((WORD)(i)))
42+
3143
INT
3244
WINAPI
3345
K32LoadStringExW(
@@ -45,6 +57,17 @@ K32LoadStringW(
4557
OUT LPWSTR lpBuffer,
4658
IN INT nBufferMax);
4759

60+
/* Override LoadString */
61+
#ifdef LoadString
62+
#undef LoadString
63+
#endif
64+
#define LoadStringW K32LoadStringW
65+
#if defined(UNICODE) || defined(_UNICODE)
66+
#define LoadString LoadStringW
67+
#else
68+
#error The ConUtils library only supports UNICODE at the moment!
69+
#endif // UNICODE
70+
4871
DWORD
4972
WINAPI
5073
FormatMessageSafeW(

0 commit comments

Comments
 (0)