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.

80 lines
1.6 KiB

  1. #include "precomp.h"
  2. #ifdef EXT_DEBUG
  3. #undef THIS_FILE
  4. static char THIS_FILE[] = __FILE__;
  5. #endif
  6. #include "CHString1.h"
  7. CHString1::CHString1() : CHString()
  8. {
  9. }
  10. CHString1::CHString1(TCHAR ch, int nLength) : CHString(ch,nLength)
  11. {
  12. }
  13. //CHString1::CHString1(LPCTSTR lpch, int nLength) : CHString(lpch,nLength)
  14. //{
  15. //}
  16. #ifdef _UNICODE
  17. CHString1::CHString1(LPCSTR lpsz) : CHString(lpsz)
  18. {
  19. }
  20. #else //_UNICODE
  21. CHString1::CHString1(LPCWSTR lpsz) : CHString(lpsz)
  22. {
  23. }
  24. #endif //!_UNICODE
  25. CHString1::CHString1(LPCTSTR lpsz) : CHString(lpsz)
  26. {
  27. }
  28. CHString1::CHString1(const CHString& stringSrc) : CHString(stringSrc)
  29. {
  30. }
  31. CHString1::CHString1(const CHString1& stringSrc) : CHString((CHString)stringSrc)
  32. {
  33. }
  34. BOOL CHString1::LoadString(UINT nID)
  35. {
  36. // try fixed buffer first (to avoid wasting space in the heap)
  37. #ifdef _UNICODE
  38. const UINT CHAR_FUDGE = 1; // one WCHAR unused is good enough
  39. #else
  40. const UINT CHAR_FUDGE = 2; // two BYTES unused for case of DBC last char
  41. #endif
  42. const UINT STR_BLK_SIZE = 256 ;
  43. int nLen = 0;
  44. int nSize = STR_BLK_SIZE;
  45. do
  46. {
  47. nSize += STR_BLK_SIZE;
  48. nLen = ::LoadStringW(_Module.GetModuleInstance(),nID, GetBuffer(nSize-1), nSize);
  49. }
  50. while (nSize - nLen <= CHAR_FUDGE);
  51. ReleaseBuffer();
  52. return nLen > 0;
  53. }
  54. BOOL CHString1::LoadString(UINT nID,LPWSTR lpszBuf, UINT nMaxBuf)
  55. {
  56. int nSize = 256;
  57. int nLen = ::LoadStringW(_Module.GetModuleInstance(), nID, lpszBuf, nMaxBuf);
  58. if (nLen == 0)
  59. lpszBuf[0] = '\0';
  60. return nLen;
  61. }