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.

51 lines
1.1 KiB

  1. /*
  2. * BSTRING.CPP
  3. *
  4. * Implementation of the member functions of the BSTRING C++ class. See
  5. * BSTRING.H for the class declaration and the implementation of the inline
  6. * member functions.
  7. *
  8. * Author:
  9. * dannygl, 29 Oct 96
  10. */
  11. #include "precomp.h"
  12. #include <bstring.h>
  13. // We don't support construction from an ANSI string in the Unicode build.
  14. #if !defined(UNICODE)
  15. BSTRING::BSTRING(LPCSTR lpcString)
  16. {
  17. // Initialize the member pointer to NULL
  18. m_bstr = NULL;
  19. if (NULL == lpcString)
  20. return;
  21. // Compute the length of the required BSTR, including the null
  22. int cWC;
  23. cWC = MultiByteToWideChar(CP_ACP, 0, lpcString, -1, NULL, 0);
  24. if (cWC <= 0)
  25. {
  26. return;
  27. };
  28. // Allocate the BSTR, including the null
  29. m_bstr = SysAllocStringLen(NULL, cWC - 1); // SysAllocStringLen adds another 1
  30. ASSERT(NULL != m_bstr);
  31. if (NULL == m_bstr)
  32. {
  33. return;
  34. }
  35. // Copy the string
  36. MultiByteToWideChar(CP_ACP, 0, lpcString, -1, (LPWSTR) m_bstr, cWC);
  37. // Verify that the string is null terminated
  38. ASSERT(0 == m_bstr[cWC - 1]);
  39. }
  40. #endif // !defined(UNICODE)