From 2d07d8a7cdc3ee420c121e5c680331a3c0f01c93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Fri, 27 Mar 2026 18:19:52 +0100 Subject: [PATCH] [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 --- sdk/lib/conutils/CMakeLists.txt | 3 ++- sdk/lib/conutils/instream.c | 4 +--- sdk/lib/conutils/outstream.c | 23 ++++++++++------------- sdk/lib/conutils/pager.c | 17 +++++++---------- sdk/lib/conutils/pager.h | 4 ++-- sdk/lib/conutils/screen.c | 3 +-- sdk/lib/conutils/stream.c | 3 +-- sdk/lib/conutils/utils.c | 22 ++++++++++++++++------ sdk/lib/conutils/utils.h | 23 +++++++++++++++++++++++ 9 files changed, 63 insertions(+), 39 deletions(-) diff --git a/sdk/lib/conutils/CMakeLists.txt b/sdk/lib/conutils/CMakeLists.txt index 90d8dfb98dc..a91d998ff4a 100644 --- a/sdk/lib/conutils/CMakeLists.txt +++ b/sdk/lib/conutils/CMakeLists.txt @@ -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) diff --git a/sdk/lib/conutils/instream.c b/sdk/lib/conutils/instream.c index 73e40382abe..76c72b9d9f0 100644 --- a/sdk/lib/conutils/instream.c +++ b/sdk/lib/conutils/instream.c @@ -36,9 +36,8 @@ #include #include +#include // Console APIs (only if kernel32 support included) #include -#include // MAKEINTRESOURCEW, RT_STRING -#include // Console APIs (only if kernel32 support included) #include /* PSEH for SEH Support */ @@ -48,5 +47,4 @@ #include "stream.h" #include "stream_private.h" - /* EOF */ diff --git a/sdk/lib/conutils/outstream.c b/sdk/lib/conutils/outstream.c index 428a0b00c40..ada3f838299 100644 --- a/sdk/lib/conutils/outstream.c +++ b/sdk/lib/conutils/outstream.c @@ -36,9 +36,8 @@ #include #include +#include // Console APIs (only if kernel32 support included) #include -#include // MAKEINTRESOURCEW, RT_STRING -#include // Console APIs (only if kernel32 support included) #include /* 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); } diff --git a/sdk/lib/conutils/pager.c b/sdk/lib/conutils/pager.c index 56b0f3e95e3..0ad20d65bf0 100644 --- a/sdk/lib/conutils/pager.c +++ b/sdk/lib/conutils/pager.c @@ -19,9 +19,8 @@ #include #include -// #include -#include // Console APIs (only if kernel32 support included) -#include // for WideCharToMultiByte +#include // Console APIs (only if kernel32 support included) +#include // For WideCharToMultiByte #include #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 */ diff --git a/sdk/lib/conutils/pager.h b/sdk/lib/conutils/pager.h index 1ddc5606970..90e27f6ccd5 100644 --- a/sdk/lib/conutils/pager.h +++ b/sdk/lib/conutils/pager.h @@ -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( diff --git a/sdk/lib/conutils/screen.c b/sdk/lib/conutils/screen.c index b3d1c01b520..5a4fe42456c 100644 --- a/sdk/lib/conutils/screen.c +++ b/sdk/lib/conutils/screen.c @@ -19,8 +19,7 @@ #include #include -// #include -#include // Console APIs (only if kernel32 support included) +#include // Console APIs (only if kernel32 support included) #include #include "conutils.h" diff --git a/sdk/lib/conutils/stream.c b/sdk/lib/conutils/stream.c index 462bc826cbc..c88402ebd5e 100644 --- a/sdk/lib/conutils/stream.c +++ b/sdk/lib/conutils/stream.c @@ -34,9 +34,8 @@ #include #include +#include // Console APIs (only if kernel32 support included) #include -// #include // MAKEINTRESOURCEW, RT_STRING -#include // Console APIs (only if kernel32 support included) #include #include "conutils.h" diff --git a/sdk/lib/conutils/utils.c b/sdk/lib/conutils/utils.c index 35f7f6b92d6..5790d0fd7b2 100644 --- a/sdk/lib/conutils/utils.c +++ b/sdk/lib/conutils/utils.c @@ -21,9 +21,8 @@ #include #include -#include -#include // MAKEINTRESOURCEW, RT_STRING -#include // Console APIs (only if kernel32 support included) +#include // Console APIs (only if kernel32 support included) +//#include #include /* 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) { diff --git a/sdk/lib/conutils/utils.h b/sdk/lib/conutils/utils.h index 7d613d996fd..c5fd65e6d75 100644 --- a/sdk/lib/conutils/utils.h +++ b/sdk/lib/conutils/utils.h @@ -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(