[CONUTILS]: Add some string resources functions that can support a specified hModule parameter, and add small construction helpers for CON_SCREEN and CON_PAGER.

svn path=/trunk/; revision=76022
This commit is contained in:
Hermès Bélusca-Maïto 2017-10-01 16:03:44 +00:00
parent d47bb60c1c
commit 0599206b8b
5 changed files with 110 additions and 13 deletions

View File

@ -130,6 +130,24 @@ ConPutsPaging(
return ConWritePaging(Pager, PagePrompt, StartPaging, szStr, len);
}
BOOL
ConResPagingEx(
IN PCON_PAGER Pager,
IN PAGE_PROMPT PagePrompt,
IN BOOL StartPaging,
IN HINSTANCE hInstance OPTIONAL,
IN UINT uID)
{
INT Len;
PWCHAR szStr = NULL;
Len = K32LoadStringW(hInstance, uID, (PWSTR)&szStr, 0);
if (szStr && Len)
return ConWritePaging(Pager, PagePrompt, StartPaging, szStr, Len);
else
return TRUE;
}
BOOL
ConResPaging(
IN PCON_PAGER Pager,
@ -137,12 +155,6 @@ ConResPaging(
IN BOOL StartPaging,
IN UINT uID)
{
INT Len;
PWCHAR szStr = NULL;
Len = K32LoadStringW(GetModuleHandleW(NULL), uID, (PWSTR)&szStr, 0);
if (szStr && Len)
return ConWritePaging(Pager, PagePrompt, StartPaging, szStr, Len);
else
return TRUE;
return ConResPagingEx(Pager, PagePrompt, StartPaging,
NULL /*GetModuleHandleW(NULL)*/, uID);
}

View File

@ -30,6 +30,14 @@ typedef struct _CON_PAGER
DWORD LineCount;
} CON_PAGER, *PCON_PAGER;
#define INIT_CON_PAGER(pScreen) {(pScreen), 0}
#define InitializeConPager(pPager, pScreen) \
do { \
(pPager)->Screen = (pScreen); \
(pPager)->LineCount = 0; \
} while (0)
// Pager, Done, Total
typedef BOOL (__stdcall *PAGE_PROMPT)(IN PCON_PAGER, IN DWORD, IN DWORD);
@ -48,6 +56,14 @@ ConPutsPaging(
IN BOOL StartPaging,
IN LPTSTR szStr);
BOOL
ConResPagingEx(
IN PCON_PAGER Pager,
IN PAGE_PROMPT PagePrompt,
IN BOOL StartPaging,
IN HINSTANCE hInstance OPTIONAL,
IN UINT uID);
BOOL
ConResPaging(
IN PCON_PAGER Pager,

View File

@ -35,6 +35,15 @@ typedef struct _CON_SCREEN
CONSOLE_CURSOR_INFO cci;
} CON_SCREEN, *PCON_SCREEN;
#define INIT_CON_SCREEN(pStream) {(pStream)} /* {(pStream), {{}}, {{}}} */
#define InitializeConScreen(pScreen, pStream) \
do { \
(pScreen)->Stream = (pStream); \
RtlZeroMemory(&(pScreen)->csbi, sizeof((pScreen)->csbi)); \
RtlZeroMemory(&(pScreen)->cci , sizeof((pScreen)->cci )); \
} while (0)
BOOL
ConGetScreenInfo(
IN PCON_SCREEN Screen,

View File

@ -483,7 +483,9 @@ ConWrite(
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return 0;
}
len = WideCharToMultiByte(Stream->CodePage, 0, szStr, len, buffer, len * MB_LEN_MAX, NULL, NULL);
len = WideCharToMultiByte(Stream->CodePage, 0,
szStr, len, buffer, len * MB_LEN_MAX,
NULL, NULL);
szStr = (PVOID)buffer;
#else
/*
@ -705,14 +707,15 @@ ConPrintf(
}
INT
ConResPuts(
ConResPutsEx(
IN PCON_STREAM Stream,
IN HINSTANCE hInstance OPTIONAL,
IN UINT uID)
{
INT Len;
PWCHAR szStr = NULL;
Len = K32LoadStringW(GetModuleHandleW(NULL), uID, (PWSTR)&szStr, 0);
Len = K32LoadStringW(hInstance, uID, (PWSTR)&szStr, 0);
if (szStr && Len)
// Len = ConPuts(Stream, szStr);
CON_STREAM_WRITE2(Stream, szStr, Len, Len);
@ -725,8 +728,17 @@ ConResPuts(
}
INT
ConResPrintfV(
ConResPuts(
IN PCON_STREAM Stream,
IN UINT uID)
{
return ConResPutsEx(Stream, NULL /*GetModuleHandleW(NULL)*/, uID);
}
INT
ConResPrintfExV(
IN PCON_STREAM Stream,
IN HINSTANCE hInstance OPTIONAL,
IN UINT uID,
IN va_list args) // arg_ptr
{
@ -734,13 +746,40 @@ ConResPrintfV(
WCHAR bufSrc[CON_RC_STRING_MAX_SIZE];
// NOTE: We may use the special behaviour where nBufMaxSize == 0
Len = K32LoadStringW(GetModuleHandleW(NULL), uID, bufSrc, ARRAYSIZE(bufSrc));
Len = K32LoadStringW(hInstance, uID, bufSrc, ARRAYSIZE(bufSrc));
if (Len)
Len = ConPrintfV(Stream, bufSrc, args);
return Len;
}
INT
ConResPrintfV(
IN PCON_STREAM Stream,
IN UINT uID,
IN va_list args) // arg_ptr
{
return ConResPrintfExV(Stream, NULL /*GetModuleHandleW(NULL)*/, uID, args);
}
INT
__cdecl
ConResPrintfEx(
IN PCON_STREAM Stream,
IN HINSTANCE hInstance OPTIONAL,
IN UINT uID,
...)
{
INT Len;
va_list args;
va_start(args, uID);
Len = ConResPrintfExV(Stream, hInstance, uID, args);
va_end(args);
return Len;
}
INT
__cdecl
ConResPrintf(

View File

@ -183,17 +183,38 @@ ConPrintf(
IN LPWSTR szStr,
...);
INT
ConResPutsEx(
IN PCON_STREAM Stream,
IN HINSTANCE hInstance OPTIONAL,
IN UINT uID);
INT
ConResPuts(
IN PCON_STREAM Stream,
IN UINT uID);
INT
ConResPrintfExV(
IN PCON_STREAM Stream,
IN HINSTANCE hInstance OPTIONAL,
IN UINT uID,
IN va_list args); // arg_ptr
INT
ConResPrintfV(
IN PCON_STREAM Stream,
IN UINT uID,
IN va_list args); // arg_ptr
INT
__cdecl
ConResPrintfEx(
IN PCON_STREAM Stream,
IN HINSTANCE hInstance OPTIONAL,
IN UINT uID,
...);
INT
__cdecl
ConResPrintf(