Index: base/applications/cmdutils/hostname/CMakeLists.txt =================================================================== --- base/applications/cmdutils/hostname/CMakeLists.txt (revision 58892) +++ base/applications/cmdutils/hostname/CMakeLists.txt (working copy) @@ -1,6 +1,6 @@ add_executable(hostname hostname.c hostname.rc) -set_module_type(hostname win32cui) -add_importlibs(hostname msvcrt kernel32) +set_module_type(hostname win32cui UNICODE) +add_importlibs(hostname user32 msvcrt kernel32) add_cd_file(TARGET hostname DESTINATION reactos/system32 FOR all) Index: base/applications/cmdutils/hostname/hostname.c =================================================================== --- base/applications/cmdutils/hostname/hostname.c (revision 58892) +++ base/applications/cmdutils/hostname/hostname.c (working copy) @@ -29,32 +29,83 @@ #include #include +#include -int main (int argc, char ** argv) +#include "resource.h" + +DWORD +FormatString( + DWORD dwFlags, + HINSTANCE hInstance, + DWORD dwStringId, + DWORD dwLanguageId, + LPWSTR lpBuffer, + DWORD nSize, + va_list* Arguments +) { + DWORD dwRet; + int len; + WCHAR Buffer[100]; + + len = LoadStringW(hInstance, dwStringId, (LPTSTR)Buffer, 100); + + if (len) + { + dwFlags |= FORMAT_MESSAGE_FROM_STRING; + dwFlags &= ~(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_FROM_SYSTEM); + dwRet = FormatMessageW(dwFlags, Buffer, 0, dwLanguageId, lpBuffer, nSize, Arguments); + return dwRet; + } + return 0; +} +int wmain(int argc, WCHAR ** argv) +{ + HLOCAL tmpBuffer; + if (1 == argc) - { - TCHAR ComputerName [MAX_COMPUTERNAME_LENGTH + 1]; - DWORD ComputerNameSize = sizeof ComputerName / sizeof ComputerName[0]; + { + WCHAR ComputerName [MAX_COMPUTERNAME_LENGTH + 1]; + DWORD ComputerNameSize = sizeof ComputerName / sizeof ComputerName[0]; - ZeroMemory (ComputerName, sizeof ComputerName ); - if (GetComputerName(ComputerName, & ComputerNameSize)) - { - printf ("%s\n", ComputerName); - return EXIT_SUCCESS; - } - fprintf (stderr, "%s: Win32 error %lu.\n", - argv[0], GetLastError()); - return EXIT_FAILURE; - }else{ - if (0 == strcmp(argv[1],"-s")) - { - fprintf(stderr,"%s: -s not supported.\n",argv[0]); - return EXIT_FAILURE; - }else{ - printf("Print the current host's name.\n\nhostname\n"); - } - } - return EXIT_SUCCESS; + ZeroMemory (ComputerName, sizeof ComputerName ); + if (GetComputerName(ComputerName, & ComputerNameSize)) + { + /* Prints out the computer's name */ + wprintf(TEXT("%s\n"), ComputerName); + + LocalFree(tmpBuffer); + return EXIT_SUCCESS; + } + FormatString(FORMAT_MESSAGE_ALLOCATE_BUFFER, + NULL, IDS_ERROR, 0, (LPWSTR)&tmpBuffer, 0, NULL); + + /* If there was an error with the program output */ + fwprintf(stderr, TEXT("%s: %s %lu.\n"), + argv[0], tmpBuffer, GetLastError()); + + LocalFree(tmpBuffer); + return EXIT_FAILURE; + } else { + if ((0 == wcscmp(argv[1],TEXT("-s"))) || (0 == wcscmp(argv[1],TEXT("/s")))) + { + FormatString(FORMAT_MESSAGE_ALLOCATE_BUFFER, + NULL, IDS_NOSET, 0, (LPWSTR)&tmpBuffer, 0, NULL); + + /* The program doesn't allow the user to set the computer's name */ + fwprintf(stderr,TEXT("%s: %s"),argv[0], tmpBuffer); + + LocalFree(tmpBuffer); + return EXIT_FAILURE; + } else { + /* Lets the user know what the program does */ + FormatString(FORMAT_MESSAGE_ALLOCATE_BUFFER, + NULL, IDS_USAGE, 0, (LPWSTR)&tmpBuffer, 0, NULL); + wprintf(TEXT("%s"), tmpBuffer); + } + } + + LocalFree(tmpBuffer); + return EXIT_SUCCESS; } /* EOF */ Index: base/applications/cmdutils/hostname/hostname.rc =================================================================== --- base/applications/cmdutils/hostname/hostname.rc (revision 58892) +++ base/applications/cmdutils/hostname/hostname.rc (working copy) @@ -1,3 +1,10 @@ +#include +#include + +#include "resource.h" + +LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL + #define REACTOS_STR_FILE_DESCRIPTION "Win32 Get local host name\0" #define REACTOS_STR_INTERNAL_NAME "hostname\0" #define REACTOS_STR_ORIGINAL_FILENAME "hostname.exe\0" @@ -2 +9,7 @@ #include + +// UTF-8 +#pragma code_page(65001) +#ifdef LANGUAGE_EN_US + #include "lang/en_us.rc" +#endif \ No newline at end of file Index: base/applications/cmdutils/hostname/lang/en_us.rc =================================================================== --- base/applications/cmdutils/hostname/lang/en_us.rc (revision 0) +++ base/applications/cmdutils/hostname/lang/en_us.rc (working copy) @@ -0,0 +1,8 @@ +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +STRINGTABLE DISCARDABLE +BEGIN + IDS_USAGE, "Print the current host's name.\n\nhostname\n" + IDS_NOSET, "-s is not supported.\n" + IDS_ERROR, "Win32 error\n" +END Index: base/applications/cmdutils/hostname/resource.h =================================================================== --- base/applications/cmdutils/hostname/resource.h (revision 0) +++ base/applications/cmdutils/hostname/resource.h (working copy) @@ -0,0 +1,8 @@ +#ifndef RESOURCE_H +#define RESOURCE_H + +#define IDS_USAGE 0 +#define IDS_NOSET 1 +#define IDS_ERROR 2 + +#endif /* RESOURCE_H */ \ No newline at end of file