11af856ee06e0cadf5a5b3da12706ff771504e8a
[reactos.git] / rostests / apitests / msvcrt / CmdLineUtil / CmdLineUtil.c
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 <windows.h>
11 #include <ndk/ntndk.h>
12
13 #include "CmdLineUtil.h"
14
15 int APIENTRY wWinMain(HINSTANCE hInstance,
16 HINSTANCE hPrevInstance,
17 LPWSTR lpCmdLine,
18 int nCmdShow)
19 {
20 /*
21 * Get the unparsed command line as seen in Win32 mode,
22 * and the NT-native mode one.
23 */
24 LPWSTR CmdLine = GetCommandLineW();
25 UNICODE_STRING CmdLine_U = NtCurrentPeb()->ProcessParameters->CommandLine;
26
27 /* Write the results into a file. */
28 HANDLE hFile = CreateFileW(DATAFILE,
29 GENERIC_WRITE,
30 0, NULL,
31 CREATE_ALWAYS,
32 FILE_ATTRIBUTE_NORMAL,
33 NULL);
34 if (hFile != INVALID_HANDLE_VALUE)
35 {
36 DWORD dwSize, dwStringSize;
37
38 /*
39 * Format of the data file :
40 *
41 * [size_of_string 4 bytes][null_terminated_C_string]
42 * [size_of_string 4 bytes][null_terminated_C_string]
43 * [UNICODE_STRING_structure][string_buffer_of_UNICODE_STRING]
44 */
45
46 /* 1- Write the WinMain's command line. */
47 dwStringSize = (wcslen(lpCmdLine) + 1) * sizeof(WCHAR);
48
49 WriteFile(hFile,
50 &dwStringSize,
51 sizeof(dwStringSize),
52 &dwSize,
53 NULL);
54
55 WriteFile(hFile,
56 lpCmdLine,
57 dwStringSize,
58 &dwSize,
59 NULL);
60
61 /* 2- Write the Win32 mode command line. */
62 dwStringSize = (wcslen(CmdLine) + 1) * sizeof(WCHAR);
63
64 WriteFile(hFile,
65 &dwStringSize,
66 sizeof(dwStringSize),
67 &dwSize,
68 NULL);
69
70 WriteFile(hFile,
71 CmdLine,
72 dwStringSize,
73 &dwSize,
74 NULL);
75
76 /* 3- Finally, write the UNICODE_STRING command line. */
77 WriteFile(hFile,
78 &CmdLine_U,
79 sizeof(CmdLine_U),
80 &dwSize,
81 NULL);
82
83 WriteFile(hFile,
84 CmdLine_U.Buffer,
85 CmdLine_U.Length,
86 &dwSize,
87 NULL);
88
89 /* Now close the file. */
90 CloseHandle(hFile);
91 }
92
93 return 0;
94 }
95
96 /* EOF */