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.

109 lines
3.1 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // GlobalFuncs.cpp
  7. //
  8. // Description:
  9. // Contains the definitions of a few unrelated global functions
  10. //
  11. // Maintained By:
  12. // Vij Vasu (Vvasu) 06-SEP-2000
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. //////////////////////////////////////////////////////////////////////////////
  16. // Include Files
  17. //////////////////////////////////////////////////////////////////////////////
  18. // The precompiled header.
  19. #include "pch.h"
  20. //////////////////////////////////////////////////////////////////////////////
  21. //++
  22. //
  23. // DwLoadString()
  24. //
  25. // Description:
  26. // Allocate memory for and load a string from the string table.
  27. //
  28. // Arguments:
  29. // uiStringIdIn
  30. // Id of the string to look up
  31. //
  32. // rsszDestOut
  33. // Reference to the smart pointer to the loaded string.
  34. //
  35. // Return Value:
  36. // S_OK
  37. // If the call succeeded
  38. //
  39. // Other Win32 error codes
  40. // If the call failed.
  41. //
  42. // Remarks:
  43. // This function cannot load a zero length string.
  44. //--
  45. //////////////////////////////////////////////////////////////////////////////
  46. DWORD
  47. DwLoadString(
  48. UINT nStringIdIn
  49. , SmartSz & rsszDestOut
  50. )
  51. {
  52. TraceFunc( "" );
  53. DWORD dwError = ERROR_SUCCESS;
  54. UINT uiCurrentSize = 0;
  55. SmartSz sszCurrentString;
  56. UINT uiReturnedStringLen = 0;
  57. do
  58. {
  59. // Grow the current string by an arbitrary amount.
  60. uiCurrentSize += 256;
  61. sszCurrentString.Assign( new WCHAR[ uiCurrentSize ] );
  62. if ( sszCurrentString.FIsEmpty() )
  63. {
  64. dwError = TW32( ERROR_NOT_ENOUGH_MEMORY );
  65. TraceFlow2( "Error %#x occurred trying allocate memory for string (string id is %d).", dwError, nStringIdIn );
  66. LogMsg( "Error %#x occurred trying allocate memory for string (string id is %d).", dwError, nStringIdIn );
  67. break;
  68. } // if: the memory allocation has failed
  69. uiReturnedStringLen = ::LoadString(
  70. g_hInstance
  71. , nStringIdIn
  72. , sszCurrentString.PMem()
  73. , uiCurrentSize
  74. );
  75. if ( uiReturnedStringLen == 0 )
  76. {
  77. dwError = TW32( GetLastError() );
  78. TraceFlow2( "Error %#x occurred trying load string (string id is %d).", dwError, nStringIdIn );
  79. LogMsg( "Error %#x occurred trying load string (string id is %d).", dwError, nStringIdIn );
  80. break;
  81. } // if: LoadString() had an error
  82. ++uiReturnedStringLen;
  83. }
  84. while( uiCurrentSize <= uiReturnedStringLen );
  85. if ( dwError == ERROR_SUCCESS )
  86. {
  87. rsszDestOut = sszCurrentString;
  88. } // if: there were no errors in this function
  89. else
  90. {
  91. rsszDestOut.PRelease();
  92. } // else: something went wrong
  93. RETURN( dwError );
  94. } //*** DwLoadString()