Skip to content

Commit ddca2af

Browse files
committed
[TASKLIST] Improve imports, simplify code
1 parent 4750869 commit ddca2af

3 files changed

Lines changed: 14 additions & 32 deletions

File tree

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11

2-
include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/conutils)
3-
42
add_executable(tasklist tasklist.c tasklist.rc)
53
set_module_type(tasklist win32cui UNICODE)
6-
target_link_libraries(tasklist conutils ${PSEH_LIB})
7-
add_importlibs(tasklist msvcrt user32 kernel32 ntdll)
4+
target_link_libraries(tasklist conutils)
5+
add_importlibs(tasklist msvcrt kernel32 ntdll)
86
add_cd_file(TARGET tasklist DESTINATION reactos/system32 FOR all)

base/applications/cmdutils/tasklist/tasklist.c

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,10 @@ VOID PrintString(LPCWSTR String, UINT MaxWidth, BOOL bAlignLeft)
4545
// if bAlignLeft == TRUE then aligned to left, otherwise aligned to right
4646
// MaxWidth is the width for printing.
4747
// The string WILL be truncated if it's longer than RES_STR_MAXLEN
48-
VOID PrintResString(HINSTANCE hInstance, UINT uID, UINT MaxWidth, BOOL bAlignLeft)
48+
VOID PrintResString(UINT uID, UINT MaxWidth, BOOL bAlignLeft)
4949
{
50-
if (!hInstance)
51-
return;
52-
5350
WCHAR StringBuffer[RES_STR_MAXLEN];
54-
LoadStringW(hInstance, uID, StringBuffer, _countof(StringBuffer));
51+
LoadStringW(NULL, uID, StringBuffer, _countof(StringBuffer));
5552
PrintString(StringBuffer, MaxWidth, bAlignLeft);
5653
}
5754

@@ -66,11 +63,8 @@ VOID PrintNum(LONGLONG Number, UINT MaxWidth)
6663
// Print memory size using KB as unit, with comma-separated number, aligned to right.
6764
// MaxWidth is the width for printing.
6865
// the number WILL be truncated if it's longer than MaxWidth
69-
BOOL PrintMemory(SIZE_T MemorySizeByte, UINT MaxWidth, HINSTANCE hInstance)
66+
BOOL PrintMemory(SIZE_T MemorySizeByte, UINT MaxWidth)
7067
{
71-
if (!hInstance)
72-
return FALSE;
73-
7468
SIZE_T MemorySize = MemorySizeByte >> 10;
7569

7670
WCHAR NumberString[27] = { 0 }; // length 26 is enough to display ULLONG_MAX in decimal with comma, one more for zero-terminated.
@@ -105,28 +99,24 @@ BOOL PrintMemory(SIZE_T MemorySizeByte, UINT MaxWidth, HINSTANCE hInstance)
10599
}
106100

107101
WCHAR FormatStr[RES_STR_MAXLEN];
108-
LoadStringW(hInstance, IDS_MEMORY_STR, FormatStr, _countof(FormatStr));
102+
LoadStringW(NULL, IDS_MEMORY_STR, FormatStr, _countof(FormatStr));
109103

110104
WCHAR String[RES_STR_MAXLEN + _countof(NumberString)] = { 0 };
111-
112105
StringCchPrintfW(String, _countof(String), FormatStr, NumberString);
113106
PrintString(String, MaxWidth, FALSE);
114107

115108
return TRUE;
116109
}
117110

118-
VOID PrintHeader(HINSTANCE hInstance)
111+
VOID PrintHeader(VOID)
119112
{
120-
if (!hInstance)
121-
return;
122-
123-
PrintResString(hInstance, IDS_HEADER_IMAGENAME, COLUMNWIDTH_IMAGENAME, TRUE);
113+
PrintResString(IDS_HEADER_IMAGENAME, COLUMNWIDTH_IMAGENAME, TRUE);
124114
PrintSpace(1);
125-
PrintResString(hInstance, IDS_HEADER_PID, COLUMNWIDTH_PID, FALSE);
115+
PrintResString(IDS_HEADER_PID, COLUMNWIDTH_PID, FALSE);
126116
PrintSpace(1);
127-
PrintResString(hInstance, IDS_HEADER_SESSION, COLUMNWIDTH_SESSION, FALSE);
117+
PrintResString(IDS_HEADER_SESSION, COLUMNWIDTH_SESSION, FALSE);
128118
PrintSpace(1);
129-
PrintResString(hInstance, IDS_HEADER_MEMUSAGE, COLUMNWIDTH_MEMUSAGE, FALSE);
119+
PrintResString(IDS_HEADER_MEMUSAGE, COLUMNWIDTH_MEMUSAGE, FALSE);
130120

131121
ConPuts(StdOut, L"\n");
132122

@@ -205,15 +195,10 @@ BOOL EnumProcessAndPrint(BOOL bNoHeader)
205195
return FALSE;
206196
}
207197

208-
HINSTANCE hInstance = GetModuleHandleW(NULL);
209-
assert(hInstance);
210-
211198
ConPuts(StdOut, L"\n");
212199

213200
if (!bNoHeader)
214-
{
215-
PrintHeader(hInstance);
216-
}
201+
PrintHeader();
217202

218203
PSYSTEM_PROCESS_INFORMATION pSPI;
219204
pSPI = (PSYSTEM_PROCESS_INFORMATION)ProcessInfoBuffer;
@@ -225,7 +210,7 @@ BOOL EnumProcessAndPrint(BOOL bNoHeader)
225210
PrintSpace(1);
226211
PrintNum((ULONGLONG)pSPI->SessionId, COLUMNWIDTH_SESSION);
227212
PrintSpace(1);
228-
PrintMemory(pSPI->WorkingSetSize, COLUMNWIDTH_MEMUSAGE, hInstance);
213+
PrintMemory(pSPI->WorkingSetSize, COLUMNWIDTH_MEMUSAGE);
229214

230215
ConPuts(StdOut, L"\n");
231216

base/applications/cmdutils/tasklist/tasklist.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
#include <stdio.h>
1111
#include <stdlib.h>
1212
#include <wchar.h>
13-
#include <assert.h>
1413

1514
#define WIN32_NO_STATUS
1615
#include <windows.h>
17-
#include <ntndk.h>
16+
#include <ndk/exfuncs.h>
1817
#include <strsafe.h>
1918

2019
#include <conutils.h>

0 commit comments

Comments
 (0)