CF_UnicodeTextAggregator.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "stdafx.h"
  2. #include ".\cf_unicodetextaggregator.h"
  3. #include "Misc.h"
  4. CCF_UnicodeTextAggregator::CCF_UnicodeTextAggregator(CStringW csSeparator) :
  5. m_csSeparator(csSeparator)
  6. {
  7. }
  8. CCF_UnicodeTextAggregator::~CCF_UnicodeTextAggregator(void)
  9. {
  10. }
  11. bool CCF_UnicodeTextAggregator::AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount)
  12. {
  13. LPCWSTR pText = (LPCWSTR)lpData;
  14. if(pText == NULL)
  15. {
  16. return false;
  17. }
  18. int stringLen = nDataSize/sizeof(wchar_t);
  19. //Ensure it's null terminated
  20. if(pText[stringLen-1] != '\0')
  21. {
  22. int len = 0;
  23. for(len = 0; len < stringLen && pText[len] != '\0'; len++ )
  24. {
  25. }
  26. // if it is not null terminated, skip this item
  27. if(len >= stringLen)
  28. return false;
  29. }
  30. m_csNewText += pText;
  31. if(nPos != nCount-1)
  32. {
  33. m_csNewText += m_csSeparator;
  34. }
  35. return true;
  36. }
  37. HGLOBAL CCF_UnicodeTextAggregator::GetHGlobal()
  38. {
  39. long lLen = m_csNewText.GetLength() * sizeof(wchar_t);
  40. HGLOBAL hGlobal = NewGlobalP(m_csNewText.GetBuffer(lLen), lLen+sizeof(wchar_t));
  41. m_csNewText.ReleaseBuffer();
  42. return hGlobal;
  43. }