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.

85 lines
1.5 KiB

  1. /*
  2. * Misc.c
  3. *
  4. * Author: BreenH
  5. *
  6. * Miscellaneous utilities.
  7. */
  8. /*
  9. * Includes
  10. */
  11. #include "precomp.h"
  12. /*
  13. * Function Implementations
  14. */
  15. BOOL WINAPI
  16. LoadStringResourceW(
  17. HMODULE hModule,
  18. UINT uiResourceId,
  19. PWSTR *ppString,
  20. PDWORD pcchString
  21. )
  22. {
  23. BOOL fRet;
  24. INT iRet;
  25. PWSTR pROString;
  26. PWSTR pString;
  27. ASSERT(ppString != NULL);
  28. //
  29. // Get a pointer to the string in memory. This string is the actual read-
  30. // only memory into which the module is loaded. This string is not NULL
  31. // terminated, so allocate a buffer and copy the exact number of bytes,
  32. // then set the NULL terminator.
  33. //
  34. fRet = FALSE;
  35. pROString = NULL;
  36. iRet = LoadStringW(
  37. hModule,
  38. uiResourceId,
  39. (PWSTR)(&pROString),
  40. 0
  41. );
  42. if (iRet > 0)
  43. {
  44. //
  45. // For better performance, don't zero out the entire allocation just
  46. // to copy the string. Zero out the last WCHAR to terminate the
  47. // string.
  48. //
  49. pString = (PWSTR)LocalAlloc(LMEM_FIXED, (iRet + 1) * sizeof(WCHAR));
  50. if (pString != NULL)
  51. {
  52. RtlCopyMemory(pString, pROString, iRet * sizeof(WCHAR));
  53. pString[iRet] = (WCHAR)0;
  54. *ppString = pString;
  55. if (pcchString != NULL)
  56. {
  57. *pcchString = (DWORD)iRet;
  58. }
  59. fRet = TRUE;
  60. }
  61. else
  62. {
  63. SetLastError(ERROR_OUTOFMEMORY);
  64. }
  65. }
  66. return(fRet);
  67. }