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.

72 lines
1.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 2002
  6. //
  7. // File: strings.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. /*----------------------------------------------------------------------------
  11. / Title;
  12. / strings.cpp
  13. /
  14. / Authors;
  15. / Rick Turner (ricktu)
  16. /
  17. / Notes;
  18. / Useful string manipulation functions.
  19. /----------------------------------------------------------------------------*/
  20. #include "precomp.hxx"
  21. #pragma hdrstop
  22. /*-----------------------------------------------------------------------------
  23. / StrRetFromString
  24. / -----------------
  25. / Package a WIDE string into a LPSTRRET structure.
  26. /
  27. / In:
  28. / pStrRet -> receieves the newly allocate string
  29. / pString -> string to be copied.
  30. /
  31. / Out:
  32. / -
  33. /----------------------------------------------------------------------------*/
  34. HRESULT StrRetFromString(LPSTRRET lpStrRet, LPCWSTR pString)
  35. {
  36. HRESULT hr = S_OK;
  37. TraceEnter(TRACE_COMMON_STR, "StrRetFromString");
  38. Trace(TEXT("pStrRet %08x, lpszString -%ls-"), lpStrRet, pString);
  39. TraceAssert(lpStrRet);
  40. TraceAssert(pString);
  41. if (!lpStrRet || !pString)
  42. {
  43. hr = E_INVALIDARG;
  44. }
  45. else
  46. {
  47. int cch = wcslen(pString)+1;
  48. // SHAlloc zero-inits memory
  49. lpStrRet->pOleStr = reinterpret_cast<LPWSTR>(SHAlloc(cch*sizeof(WCHAR)));
  50. if ( !(lpStrRet->pOleStr) )
  51. {
  52. hr = E_OUTOFMEMORY;
  53. }
  54. else
  55. {
  56. lpStrRet->uType = STRRET_WSTR;
  57. lstrcpyn(lpStrRet->pOleStr, pString, cch);
  58. }
  59. }
  60. TraceLeaveResult(hr);
  61. }