Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
3.4 KiB

  1. /*++
  2. Copyright (c) 1997 FORE Systems, Inc.
  3. Copyright (c) 1997 Microsoft Corporation
  4. Module Name:
  5. utils.c
  6. Abstract:
  7. ATM ARP Admin Utility.
  8. Usage:
  9. atmarp
  10. Revision History:
  11. Who When What
  12. -------- -------- ---------------------------------------------
  13. josephj 06-10-1998 Created (adapted from atmlane admin utility).
  14. Notes:
  15. Modelled after atmlane utility.
  16. --*/
  17. #include "common.h"
  18. //
  19. // LoadMessageTable
  20. //
  21. // Loads internationalizable strings into a table, replacing the default for
  22. // each. If an error occurs, the English language default is left in place.
  23. //
  24. //
  25. VOID
  26. LoadMessageTable(
  27. PMESSAGE_STRING Table,
  28. UINT MessageCount
  29. )
  30. {
  31. LPTSTR string;
  32. DWORD count;
  33. //
  34. // for all messages in a MESSAGE_STRING table, load the string from this
  35. // module, replacing the default string in the table (only there in case
  36. // we get an error while loading the string, so we at least have English
  37. // to fall back on)
  38. //
  39. while (MessageCount--) {
  40. if (Table->Message != MSG_NO_MESSAGE) {
  41. //
  42. // we really want LoadString here, but LoadString doesn't indicate
  43. // how big the string is, so it doesn't give us an opportunity to
  44. // allocate exactly the right buffer size. FormatMessage does the
  45. // right thing
  46. //
  47. count = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
  48. | FORMAT_MESSAGE_FROM_HMODULE,
  49. NULL, // use default hModule
  50. Table->Message,
  51. 0, // use default language
  52. (LPTSTR)&string,
  53. 0, // minimum size to allocate
  54. NULL // no arguments for inclusion in strings
  55. );
  56. if (count) {
  57. //
  58. // Format message returned the string: replace the English
  59. // language default
  60. //
  61. Table->String = string;
  62. } else {
  63. //
  64. // this is ok if there is no string (e.g. just %0) in the .mc
  65. // file
  66. //
  67. Table->String = TEXT("");
  68. }
  69. }
  70. ++Table;
  71. }
  72. }
  73. VOID
  74. DisplayMessage(
  75. IN BOOLEAN Tabbed,
  76. IN DWORD MessageId,
  77. ...
  78. )
  79. {
  80. va_list pArg;
  81. CHAR MessageBuffer[2048];
  82. INT Count;
  83. va_start(pArg, MessageId);
  84. Count = FormatMessage(
  85. FORMAT_MESSAGE_FROM_HMODULE,
  86. NULL, // default hModule
  87. MessageId,
  88. 0, // default language
  89. MessageBuffer,
  90. sizeof(MessageBuffer),
  91. &pArg
  92. );
  93. va_end(pArg);
  94. if (Tabbed)
  95. {
  96. putchar('\t');
  97. }
  98. printf(MessageBuffer);
  99. }
  100. HANDLE
  101. OpenDevice(
  102. CHAR *pDeviceName
  103. )
  104. {
  105. DWORD DesiredAccess;
  106. DWORD ShareMode;
  107. LPSECURITY_ATTRIBUTES lpSecurityAttributes = NULL;
  108. DWORD CreationDistribution;
  109. DWORD FlagsAndAttributes;
  110. HANDLE TemplateFile;
  111. HANDLE Handle;
  112. DesiredAccess = GENERIC_READ|GENERIC_WRITE;
  113. ShareMode = 0;
  114. CreationDistribution = OPEN_EXISTING;
  115. FlagsAndAttributes = FILE_ATTRIBUTE_NORMAL;
  116. TemplateFile = (HANDLE)INVALID_HANDLE_VALUE;
  117. Handle = CreateFile(
  118. pDeviceName,
  119. DesiredAccess,
  120. ShareMode,
  121. lpSecurityAttributes,
  122. CreationDistribution,
  123. FlagsAndAttributes,
  124. TemplateFile
  125. );
  126. return (Handle);
  127. }
  128. VOID
  129. CloseDevice(
  130. HANDLE DeviceHandle
  131. )
  132. {
  133. CloseHandle(DeviceHandle);
  134. }