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