Leaked source code of windows server 2003
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.

162 lines
4.0 KiB

  1. #include "regdata.hxx"
  2. #include "regsys.hxx"
  3. #include <stdio.h>
  4. extern "C" HINSTANCE g_hInstance;
  5. #ifndef ARRAYSIZE
  6. #define ARRAYSIZE(x) (sizeof(x) / sizeof(x[0]))
  7. #endif
  8. BOOLEAN
  9. REGEDIT_BASE_SYSTEM::QueryResourceString(
  10. OUT PWSTRING ResourceString,
  11. IN MSGID MsgId,
  12. IN PCSTR Format ...
  13. )
  14. /*++
  15. Routine Description:
  16. This routine computes the resource string identified by the resource
  17. identifier 'MsgId'. In addition to the 'printf' format strings
  18. supported, 'QueryResourceString' supports :
  19. 1. '%W' - Expects a pointer to a WSTRING.
  20. Arguments:
  21. ResourceString - Returns the resource string.
  22. MsgId - Supplies the message id of the resource string.
  23. Format - Supplies a 'printf' style format descriptor for the
  24. arguments to the resource string.
  25. ... - Supplies the arguments to the resource string.
  26. Return Value:
  27. FALSE - Failure.
  28. TRUE - Success.
  29. --*/
  30. {
  31. va_list ap;
  32. BOOLEAN r;
  33. va_start(ap, Format);
  34. r = QueryResourceStringV(ResourceString, MsgId, Format, ap);
  35. va_end(ap);
  36. return r;
  37. }
  38. BOOLEAN
  39. REGEDIT_BASE_SYSTEM::QueryResourceStringV(
  40. OUT PWSTRING ResourceString,
  41. IN MSGID MsgId,
  42. IN PCSTR Format,
  43. IN va_list VarPointer
  44. )
  45. /*++
  46. Routine Description:
  47. This is a 'varargs' implementation of 'QueryResourceString'.
  48. Arguments:
  49. ResourceString - Returns the resource string.
  50. MsgId - Supplies the message id of the resource string.
  51. Format - Supplies a 'printf' style format descriptor for the
  52. arguments to the resource string.
  53. VarPointer - Supplies a varargs pointer to the arguments of the
  54. resource string.
  55. Return Value:
  56. FALSE - Failure.
  57. TRUE - Success.
  58. --*/
  59. {
  60. WCHAR display_buffer[2048];
  61. WCHAR UnformattedMessage[1024];
  62. DWORD Status;
  63. if( LoadStringW(g_hInstance,
  64. MsgId,
  65. UnformattedMessage,
  66. 1024 ) == 0 ) {
  67. Status = GetLastError();
  68. DebugPrint( "LoadStringW() failed" );
  69. DebugPrintTrace(("LoadStringW() failed. Error = %d \n", Status ));
  70. return FALSE;
  71. }
  72. if( FormatMessageW(FORMAT_MESSAGE_FROM_STRING,
  73. (LPVOID)UnformattedMessage,
  74. 0,
  75. 0L,
  76. display_buffer,
  77. ARRAYSIZE(display_buffer),
  78. &VarPointer ) == 0 )
  79. {
  80. Status = GetLastError();
  81. DebugPrint( "FormatMessageW() failed" );
  82. DebugPrintTrace(("FormatMessageW() failed. Error = %d \n", Status ));
  83. return FALSE;
  84. }
  85. return ResourceString->Initialize(display_buffer);
  86. }
  87. PWSTRING
  88. REGEDIT_BASE_SYSTEM::QueryString(
  89. IN MSGID MsgId,
  90. IN PCSTR Format ...
  91. )
  92. /*++
  93. Routine Description:
  94. This routine computes the resource string identified by the resource
  95. identifier 'MsgId'. In addition to the 'printf' format strings
  96. supported, 'QueryResourceString' supports :
  97. 1. '%W' - Expects a pointer to a WSTRING.
  98. Arguments:
  99. MsgId - Supplies the message id of the resource string.
  100. Format - Supplies a 'printf' style format descriptor for the
  101. arguments to the resource string.
  102. ... - Supplies the arguments to the resource string.
  103. Return Value:
  104. FALSE - Failure.
  105. TRUE - Success.
  106. --*/
  107. {
  108. va_list ap;
  109. BOOLEAN r;
  110. PWSTRING String;
  111. va_start(ap, Format);
  112. String = NEW( DSTRING );
  113. if (String)
  114. {
  115. r = QueryResourceStringV(String, MsgId, Format, ap);
  116. va_end(ap);
  117. if( !r )
  118. {
  119. DELETE( String );
  120. String = NULL;
  121. }
  122. }
  123. return String;
  124. }