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.

161 lines
3.8 KiB

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