[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
This commit is contained in:
Hermès Bélusca-Maïto
2026-03-28 14:11:23 +01:00
parent 7a9265ac30
commit 2d07d8a7cd
9 changed files with 63 additions and 39 deletions
+2 -1
View File
@@ -9,8 +9,9 @@ list(APPEND SOURCE
# conutils.h
)
add_library(conutils ${SOURCE})
add_library(conutils STATIC ${SOURCE})
# add_pch(conutils conutils.h SOURCE)
add_dependencies(conutils xdk)
target_include_directories(conutils INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(conutils ${PSEH_LIB})
add_importlibs(conutils msvcrt kernel32)
+1 -3
View File
@@ -36,9 +36,8 @@
#include <windef.h>
#include <winbase.h>
#include <wincon.h> // Console APIs (only if kernel32 support included)
#include <winnls.h>
#include <winuser.h> // MAKEINTRESOURCEW, RT_STRING
#include <wincon.h> // Console APIs (only if kernel32 support included)
#include <strsafe.h>
/* PSEH for SEH Support */
@@ -48,5 +47,4 @@
#include "stream.h"
#include "stream_private.h"
/* EOF */
+10 -13
View File
@@ -36,9 +36,8 @@
#include <windef.h>
#include <winbase.h>
#include <wincon.h> // Console APIs (only if kernel32 support included)
#include <winnls.h>
#include <winuser.h> // MAKEINTRESOURCEW, RT_STRING
#include <wincon.h> // Console APIs (only if kernel32 support included)
#include <strsafe.h>
/* PSEH for SEH Support */
@@ -176,7 +175,7 @@ ConWrite(
}
/* Write everything up to \n */
dwNumBytes = ((PCWCH)p - (PCWCH)szStr) * sizeof(WCHAR);
dwNumBytes = (DWORD)(((PCWCH)p - (PCWCH)szStr) * sizeof(WCHAR));
WriteFile(Stream->hHandle, szStr, dwNumBytes, &dwNumBytes, NULL);
/*
@@ -260,7 +259,7 @@ ConWrite(
}
/* Write everything up to \n */
dwNumBytes = ((PCCH)p - (PCCH)szStr) * sizeof(CHAR);
dwNumBytes = (DWORD)(((PCCH)p - (PCCH)szStr) * sizeof(CHAR));
WriteFile(Stream->hHandle, szStr, dwNumBytes, &dwNumBytes, NULL);
/*
@@ -430,8 +429,8 @@ ConPuts(
{
INT Len;
Len = wcslen(szStr);
CON_STREAM_WRITE2(Stream, szStr, Len, Len);
Len = (INT)wcslen(szStr);
CON_STREAM_WRITE2(Stream, szStr, (DWORD)Len, Len);
/* Fixup returned length in case of errors */
if (Len < 0)
@@ -611,8 +610,8 @@ ConResPuts(
IN PCON_STREAM Stream,
IN UINT uID)
{
return ConResPutsEx(Stream, NULL /*GetModuleHandleW(NULL)*/,
uID, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
return ConResPutsEx(Stream, NULL, uID,
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
}
/**
@@ -697,9 +696,8 @@ ConResPrintfV(
IN UINT uID,
IN va_list args)
{
return ConResPrintfExV(Stream, NULL /*GetModuleHandleW(NULL)*/,
uID, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
args);
return ConResPrintfExV(Stream, NULL, uID,
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), args);
}
/**
@@ -1332,8 +1330,7 @@ ConResMsgPrintfV(
IN UINT uID,
IN va_list *Arguments OPTIONAL)
{
return ConResMsgPrintfExV(Stream, NULL /*GetModuleHandleW(NULL)*/,
dwFlags, uID,
return ConResMsgPrintfExV(Stream, NULL, dwFlags, uID,
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
Arguments);
}
+7 -10
View File
@@ -19,9 +19,8 @@
#include <windef.h>
#include <winbase.h>
// #include <winnls.h>
#include <wincon.h> // Console APIs (only if kernel32 support included)
#include <winnls.h> // for WideCharToMultiByte
#include <wincon.h> // Console APIs (only if kernel32 support included)
#include <winnls.h> // For WideCharToMultiByte
#include <strsafe.h>
#include "conutils.h"
@@ -219,7 +218,7 @@ static BOOL
ConPagerWorker(
IN PCON_PAGER Pager,
IN PCTCH TextBuff,
IN DWORD cch)
IN SIZE_T cch)
{
const DWORD PageColumns = Pager->PageColumns;
const DWORD ScrollRows = Pager->ScrollRows;
@@ -551,7 +550,7 @@ ConWritePaging(
IN PAGE_PROMPT PagePrompt,
IN BOOL StartPaging,
IN PCTCH szStr,
IN DWORD len)
IN SIZE_T len)
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
BOOL bIsConsole;
@@ -649,7 +648,7 @@ ConPutsPaging(
IN BOOL StartPaging,
IN PCTSTR szStr)
{
DWORD len;
SIZE_T len;
/* Return if no string has been given */
if (szStr == NULL)
@@ -673,8 +672,7 @@ ConResPagingEx(
Len = K32LoadStringW(hInstance, uID, (PWSTR)&szStr, 0);
if (szStr && Len)
return ConWritePaging(Pager, PagePrompt, StartPaging, szStr, Len);
else
return TRUE;
return TRUE;
}
BOOL
@@ -684,8 +682,7 @@ ConResPaging(
IN BOOL StartPaging,
IN UINT uID)
{
return ConResPagingEx(Pager, PagePrompt, StartPaging,
NULL /*GetModuleHandleW(NULL)*/, uID);
return ConResPagingEx(Pager, PagePrompt, StartPaging, NULL, uID);
}
/* EOF */
+2 -2
View File
@@ -34,7 +34,7 @@ typedef BOOL
(__stdcall *CON_PAGER_LINE_FN)(
IN OUT struct _CON_PAGER *Pager,
IN PCTCH line,
IN DWORD cch);
IN SIZE_T cch);
/* Flags for CON_PAGER */
#define CON_PAGER_EXPAND_TABS (1 << 0)
@@ -91,7 +91,7 @@ ConWritePaging(
IN PAGE_PROMPT PagePrompt,
IN BOOL StartPaging,
IN PCTCH szStr,
IN DWORD len);
IN SIZE_T len);
BOOL
ConPutsPaging(
+1 -2
View File
@@ -19,8 +19,7 @@
#include <windef.h>
#include <winbase.h>
// #include <winnls.h>
#include <wincon.h> // Console APIs (only if kernel32 support included)
#include <wincon.h> // Console APIs (only if kernel32 support included)
#include <strsafe.h>
#include "conutils.h"
+1 -2
View File
@@ -34,9 +34,8 @@
#include <windef.h>
#include <winbase.h>
#include <wincon.h> // Console APIs (only if kernel32 support included)
#include <winnls.h>
// #include <winuser.h> // MAKEINTRESOURCEW, RT_STRING
#include <wincon.h> // Console APIs (only if kernel32 support included)
#include <strsafe.h>
#include "conutils.h"
+16 -6
View File
@@ -21,9 +21,8 @@
#include <windef.h>
#include <winbase.h>
#include <winnls.h>
#include <winuser.h> // MAKEINTRESOURCEW, RT_STRING
#include <wincon.h> // Console APIs (only if kernel32 support included)
#include <wincon.h> // Console APIs (only if kernel32 support included)
//#include <winnls.h>
#include <strsafe.h>
/* PSEH for SEH Support */
@@ -32,6 +31,18 @@
// #include "conutils.h"
#include "utils.h"
/* Predefined Resource Types */
#ifndef MAKEINTRESOURCE
#define MAKEINTRESOURCE(i) ((ULONG_PTR)((WORD)(i)))
#endif
#ifndef RT_STRING
#define RT_STRING MAKEINTRESOURCE(6)
#endif
#ifndef RT_MESSAGETABLE
#define RT_MESSAGETABLE MAKEINTRESOURCE(11)
#endif
#if 0 // The following function may be useful in the future...
// Performs MultiByteToWideChar then WideCharToMultiByte .
@@ -131,9 +142,8 @@ K32LoadStringExW(
p += *p + 1;
/*
* If nBufferMax == 0, then return a read-only pointer
* to the resource itself in lpBuffer it is assumed that
* lpBuffer is actually a (LPWSTR*).
* If nBufferMax == 0, then return a read-only pointer to the resource
* itself in lpBuffer. It is assumed that lpBuffer is actually a (LPWSTR*).
*/
if (nBufferMax == 0)
{
+23
View File
@@ -28,6 +28,18 @@
extern "C" {
#endif
/* Avoid including winuser.h for these definitions */
#ifndef IS_INTRESOURCE
#define IS_INTRESOURCE(i) (((ULONG_PTR)(i) >> 16) == 0)
#endif
#ifndef MAKEINTRESOURCEA
#define MAKEINTRESOURCEA(i) ((LPSTR)(ULONG_PTR)LOWORD(i))
#endif
#ifndef MAKEINTRESOURCEW
#define MAKEINTRESOURCEW(i) ((LPWSTR)(ULONG_PTR)LOWORD(i))
#endif
// #define MAKEINTRESOURCE(i) ((ULONG_PTR)((WORD)(i)))
INT
WINAPI
K32LoadStringExW(
@@ -45,6 +57,17 @@ K32LoadStringW(
OUT LPWSTR lpBuffer,
IN INT nBufferMax);
/* Override LoadString */
#ifdef LoadString
#undef LoadString
#endif
#define LoadStringW K32LoadStringW
#if defined(UNICODE) || defined(_UNICODE)
#define LoadString LoadStringW
#else
#error The ConUtils library only supports UNICODE at the moment!
#endif // UNICODE
DWORD
WINAPI
FormatMessageSafeW(