ReactOS
0.4.17-dev-243-g1369312
CmdLineUtil.c
Go to the documentation of this file.
1
/*
2
* PROJECT: ReactOS API Tests
3
* LICENSE: GPLv2+ - See COPYING in the top level directory
4
* PURPOSE: Test for CRT command-line handling - Utility GUI program.
5
* PROGRAMMER: Hermès BÉLUSCA - MAÏTO <hermes.belusca@sfr.fr>
6
*/
7
8
#define WIN32_NO_STATUS
9
#include <stdio.h>
10
#include <
windef.h
>
11
#include <
winbase.h
>
12
#include <
ndk/rtlfuncs.h
>
13
14
#include "
CmdLineUtil.h
"
15
16
int
APIENTRY
wWinMain
(
HINSTANCE
hInstance
,
17
HINSTANCE
hPrevInstance,
18
LPWSTR
lpCmdLine,
19
int
nCmdShow)
20
{
21
/*
22
* Get the unparsed command line as seen in Win32 mode,
23
* and the NT-native mode one.
24
*/
25
LPWSTR
CmdLine
=
GetCommandLineW
();
26
UNICODE_STRING
CmdLine_U =
NtCurrentPeb
()->ProcessParameters->CommandLine;
27
28
/* Write the results into a file. */
29
HANDLE
hFile
=
CreateFileW
(
DATAFILE
,
30
GENERIC_WRITE
,
31
0,
NULL
,
32
CREATE_ALWAYS
,
33
FILE_ATTRIBUTE_NORMAL
,
34
NULL
);
35
if
(
hFile
!=
INVALID_HANDLE_VALUE
)
36
{
37
DWORD
dwSize
, dwStringSize;
38
39
/*
40
* Format of the data file :
41
*
42
* [size_of_string 4 bytes][null_terminated_C_string]
43
* [size_of_string 4 bytes][null_terminated_C_string]
44
* [UNICODE_STRING_structure][string_buffer_of_UNICODE_STRING]
45
*/
46
47
/* 1- Write the WinMain's command line. */
48
dwStringSize = (
lstrlenW
(lpCmdLine) + 1) *
sizeof
(
WCHAR
);
49
50
WriteFile
(
hFile
,
51
&dwStringSize,
52
sizeof
(dwStringSize),
53
&
dwSize
,
54
NULL
);
55
56
WriteFile
(
hFile
,
57
lpCmdLine,
58
dwStringSize,
59
&
dwSize
,
60
NULL
);
61
62
/* 2- Write the Win32 mode command line. */
63
dwStringSize = (
lstrlenW
(
CmdLine
) + 1) *
sizeof
(
WCHAR
);
64
65
WriteFile
(
hFile
,
66
&dwStringSize,
67
sizeof
(dwStringSize),
68
&
dwSize
,
69
NULL
);
70
71
WriteFile
(
hFile
,
72
CmdLine
,
73
dwStringSize,
74
&
dwSize
,
75
NULL
);
76
77
/* 3- Finally, write the UNICODE_STRING command line. */
78
WriteFile
(
hFile
,
79
&CmdLine_U,
80
sizeof
(CmdLine_U),
81
&
dwSize
,
82
NULL
);
83
84
WriteFile
(
hFile
,
85
CmdLine_U.
Buffer
,
86
CmdLine_U.
Length
,
87
&
dwSize
,
88
NULL
);
89
90
/* Now close the file. */
91
CloseHandle
(
hFile
);
92
}
93
94
return
0;
95
}
96
97
/* EOF */
wWinMain
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
Definition:
CmdLineUtil.c:16
CmdLineUtil.h
DATAFILE
#define DATAFILE
Definition:
CmdLineUtil.h:11
NtCurrentPeb
#define NtCurrentPeb()
Definition:
FLS.c:22
hInstance
HINSTANCE hInstance
Definition:
charmap.c:19
NULL
#define NULL
Definition:
types.h:112
APIENTRY
#define APIENTRY
Definition:
api.h:79
CloseHandle
#define CloseHandle
Definition:
compat.h:739
INVALID_HANDLE_VALUE
#define INVALID_HANDLE_VALUE
Definition:
compat.h:731
CreateFileW
#define CreateFileW
Definition:
compat.h:741
FILE_ATTRIBUTE_NORMAL
#define FILE_ATTRIBUTE_NORMAL
Definition:
compat.h:137
lstrlenW
#define lstrlenW
Definition:
compat.h:750
WriteFile
BOOL WINAPI WriteFile(_In_ HANDLE hFile, _In_reads_bytes_opt_(nNumberOfBytesToWrite) LPCVOID lpBuffer, _In_ DWORD nNumberOfBytesToWrite, _Out_opt_ LPDWORD lpNumberOfBytesWritten, _Inout_opt_ LPOVERLAPPED lpOverlapped)
Definition:
rw.c:25
GetCommandLineW
LPWSTR WINAPI GetCommandLineW(void)
Definition:
process.c:1338
CmdLine
static const WCHAR CmdLine[]
Definition:
install.c:48
DWORD
unsigned long DWORD
Definition:
ntddk_ex.h:95
void
Definition:
nsiface.idl:2307
CREATE_ALWAYS
#define CREATE_ALWAYS
Definition:
disk.h:72
dwSize
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition:
env.c:56
hFile
_In_ HANDLE hFile
Definition:
mswsock.h:90
rtlfuncs.h
GENERIC_WRITE
#define GENERIC_WRITE
Definition:
nt_native.h:90
WCHAR
short WCHAR
Definition:
pedump.c:58
_UNICODE_STRING
Definition:
env_spec_w32.h:368
_UNICODE_STRING::Length
USHORT Length
Definition:
env_spec_w32.h:369
_UNICODE_STRING::Buffer
PWSTR Buffer
Definition:
env_spec_w32.h:371
LPWSTR
uint16_t * LPWSTR
Definition:
typedefs.h:56
winbase.h
windef.h
modules
rostests
apitests
msvcrt
CmdLineUtil
CmdLineUtil.c
Generated on Tue Jun 2 2026 06:08:49 for ReactOS by
1.9.6