Prechádzať zdrojové kódy

Use string size to create strings, found data sometimes didn't have a null terminator so extra data was at the end of the string

scott brogden 5 rokov pred
rodič
commit
765f0b18be
10 zmenil súbory, kde vykonal 257 pridanie a 408 odobranie
  1. 16 38
      Clip.cpp
  2. 36 0
      Clip.h
  3. 9 20
      Clip_ImportExport.cpp
  4. 1 7
      DittoChaiScript.cpp
  5. 9 27
      DittoRulerRichEditCtrl.cpp
  6. 111 213
      OleClipSource.cpp
  7. 20 50
      QListCtrl.cpp
  8. 51 49
      Shared/IClip.h
  9. 3 3
      ToolTipEx.cpp
  10. 1 1
      ToolTipEx.h

+ 16 - 38
Clip.cpp

@@ -439,7 +439,7 @@ int CClip::LoadFromClipboard(CClipTypes* pClipTypes, bool checkClipboardIgnore,
 			TCHAR* text = (TCHAR *)GlobalLock(cfDesc.m_hgData);
 			if (text != NULL)
 			{
-				std::wstring stringData(text);
+				std::wstring stringData(text, GlobalSize(cfDesc.m_hgData));
 				GlobalUnlock(cfDesc.m_hgData);
 				if (g_Opt.m_regexHelper.TextMatchFilters(activeApp, stringData))
 				{
@@ -648,7 +648,7 @@ bool CClip::SetDescFromText(HGLOBAL hgData, bool unicode)
 		TCHAR* text = (TCHAR *) GlobalLock(hgData);
 		bufLen = GlobalSize(hgData);
 
-		m_Desc = text;
+		m_Desc = CString(text, bufLen/(sizeof(wchar_t)));
 		bRet = true;
 	}
 	else
@@ -656,7 +656,7 @@ bool CClip::SetDescFromText(HGLOBAL hgData, bool unicode)
 		char* text = (char *) GlobalLock(hgData);
 		bufLen = GlobalSize(hgData);
 	
-		m_Desc = text;
+		m_Desc = CString(text, bufLen);
 		bRet = true;
 	}
 		
@@ -1722,15 +1722,7 @@ CStringW CClip::GetUnicodeTextFormat()
 	IClipFormat *pFormat = this->Clips()->FindFormatEx(CF_UNICODETEXT);
 	if(pFormat != NULL)
 	{
-		wchar_t *stringData = (wchar_t *)GlobalLock(pFormat->Data());
-		if(stringData != NULL)
-		{
-			CStringW string(stringData);
-
-			GlobalUnlock(pFormat->Data());
-
-			return string;
-		}
+		return pFormat->GetAsCString();
 	}
 
 	return _T("");
@@ -1741,15 +1733,7 @@ CStringA CClip::GetCFTextTextFormat()
 	IClipFormat *pFormat = this->Clips()->FindFormatEx(CF_TEXT);
 	if(pFormat != NULL)
 	{
-		char *stringData = (char *)GlobalLock(pFormat->Data());
-		if(stringData != NULL)
-		{
-			CStringA string(stringData);
-			
-			GlobalUnlock(pFormat->Data());
-
-			return string;
-		}
+		return pFormat->GetAsCStringA();
 	}
 
 	return _T("");
@@ -1810,25 +1794,19 @@ BOOL CClip::WriteTextToHtmlFile(CString path)
 		IClipFormat *pFormat = this->Clips()->FindFormatEx(theApp.m_HTML_Format);
 		if (pFormat != NULL)
 		{
-			char *stringData = (char *)GlobalLock(pFormat->Data());
-			if (stringData != NULL)
-			{
-				CStringA html(stringData);							
+			CStringA html = pFormat->GetAsCStringA();
 
-				int pos = html.Find("<html");
-				if (pos >= 0)
-				{
-					html = html.Mid(pos);
-				}
-				else
-				{
-					html = html;
-				}
-
-				f.Write(html.GetBuffer(), html.GetLength());
-
-				GlobalUnlock(pFormat->Data());
+			int pos = html.Find("<html");
+			if (pos >= 0)
+			{
+				html = html.Mid(pos);
 			}
+			else
+			{
+				html = html;
+			}
+
+			f.Write(html.GetBuffer(), html.GetLength());			
 		}
 
 		f.Close();

+ 36 - 0
Clip.h

@@ -54,6 +54,42 @@ public:
 	virtual void AutoDeleteData(bool autoDeleteData) { m_autoDeleteData = autoDeleteData; }
 	virtual bool AutoDeleteData()	{ return m_autoDeleteData; }
 
+	CStringA GetAsCStringA() {
+		CStringA ret;
+
+		if (m_hgData)
+		{
+			LPVOID data = GlobalLock(m_hgData);
+			SIZE_T size = GlobalSize(m_hgData);
+			if (data != NULL && size > 0)
+			{
+				ret = CStringA((char *)data, size);
+			}
+
+			GlobalUnlock(m_hgData);
+		}
+
+		return ret;
+	}
+
+	CString GetAsCString() {
+		CString ret;
+		
+		if (m_hgData)
+		{
+			LPVOID data = GlobalLock(m_hgData);
+			SIZE_T size = GlobalSize(m_hgData);
+			if (data != NULL && size > 0)
+			{
+				ret = CString((wchar_t *)data, size / (sizeof(wchar_t)));
+			}
+
+			GlobalUnlock(m_hgData);
+		}
+
+		return ret;
+	}
+	
 	Gdiplus::Bitmap *CreateGdiplusBitmap();
 };
 

+ 9 - 20
Clip_ImportExport.cpp

@@ -295,32 +295,21 @@ bool CClip_ImportExport::Append_CF_TEXT_AND_CF_UNICODETEXT(CStringA &csCF_TEXT,
 		{
 		case CF_TEXT:
 			{	
-				const char *Data = (const char *)GlobalLock(pCF->m_hgData);
-				if(Data)
-				{
-					if(csCF_TEXT.IsEmpty() == FALSE)
-						csCF_TEXT += "\r\n";
-
-					csCF_TEXT += Data;
-					bRet = true;
+			
+				if(csCF_TEXT.IsEmpty() == FALSE)
+					csCF_TEXT += "\r\n";
 
-					GlobalUnlock(pCF->m_hgData);
-				}
+				csCF_TEXT += pCF->GetAsCStringA();
+				bRet = true;
 			}
 			break;
 		case CF_UNICODETEXT:
 			{	
-				const wchar_t *Data = (const wchar_t *)GlobalLock(pCF->m_hgData);
-				if(Data)
-				{
-					if(csCF_UNICODETEXT.IsEmpty() == FALSE)
-						csCF_UNICODETEXT += _T("\r\n");
-
-					csCF_UNICODETEXT += Data;
-					bRet = true;
+				if(csCF_UNICODETEXT.IsEmpty() == FALSE)
+					csCF_UNICODETEXT += _T("\r\n");
 
-					GlobalUnlock(pCF->m_hgData);
-				}
+				csCF_UNICODETEXT += pCF->GetAsCString();;
+				bRet = true;
 			}
 			break;
 		}

+ 1 - 7
DittoChaiScript.cpp

@@ -29,13 +29,7 @@ std::string CDittoChaiScript::GetAsciiString()
 		IClipFormat *pFormat = m_pClip->Clips()->FindFormatEx(CF_TEXT);
 		if (pFormat)
 		{
-			char *stringData = (char *)GlobalLock(pFormat->Data());
-			if (stringData != NULL)
-			{
-				s = stringData;
-
-				GlobalUnlock(pFormat->Data());
-			}
+			s = pFormat->GetAsCStringA();
 		}
 	}
 

+ 9 - 27
DittoRulerRichEditCtrl.cpp

@@ -31,14 +31,9 @@ bool CDittoRulerRichEditCtrl::LoadItem(long lID, CString csDesc)
 	Clip.m_cfType = RegisterClipboardFormat(CF_RTF);
 	if(theApp.GetClipData(lID, Clip) && Clip.m_hgData)
 	{
-		LPVOID pvData = GlobalLock(Clip.m_hgData);
-		if(pvData)
-		{
-			SetRTF((char*)pvData);
-			bSetText = true;
-		}
-
-		GlobalUnlock(Clip.m_hgData);
+		CString cs(Clip.GetAsCStringA());
+		SetRTF(cs);
+		bSetText = true;		
 
 		Clip.Free();
 		Clip.Clear();
@@ -49,15 +44,8 @@ bool CDittoRulerRichEditCtrl::LoadItem(long lID, CString csDesc)
 		Clip.m_cfType = CF_UNICODETEXT;
 		if(theApp.GetClipData(lID, Clip) && Clip.m_hgData)
 		{
-			LPVOID pvData = GlobalLock(Clip.m_hgData);
-			if(pvData)
-			{
-				CString csText = (WCHAR*)pvData;
-				SetText(csText);
-				bSetText = true;
-			}
-
-			GlobalUnlock(Clip.m_hgData);
+			SetText(Clip.GetAsCString());
+			bSetText = true;		
 
 			Clip.Free();
 			Clip.Clear();
@@ -69,17 +57,11 @@ bool CDittoRulerRichEditCtrl::LoadItem(long lID, CString csDesc)
 		Clip.m_cfType = CF_TEXT;
 		if(theApp.GetClipData(lID, Clip) && Clip.m_hgData)
 		{
-			LPVOID pvData = GlobalLock(Clip.m_hgData);
-			if(pvData)
-			{
-				CString csText = (char*)pvData;
-				SetText(csText);
-
-				bSetText = true;
-			}
-
-			GlobalUnlock(Clip.m_hgData);
+			CString csText(Clip.GetAsCStringA());
+			SetText(csText);
 
+			bSetText = true;
+		
 			Clip.Free();
 			Clip.Clear();
 		}

+ 111 - 213
OleClipSource.cpp

@@ -246,12 +246,8 @@ void COleClipSource::DoUpperLowerCase(CClip &clip, bool upper)
 {
 	IClipFormat *unicodeTextFormat = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
 	if (unicodeTextFormat != NULL)
-	{
-		HGLOBAL data = unicodeTextFormat->Data();
-		wchar_t * stringData = (wchar_t *) GlobalLock(data);
-		int size = (int) GlobalSize(data);
-		icu::UnicodeString s = stringData;
-		GlobalUnlock(data);		
+	{		
+		icu::UnicodeString s = unicodeTextFormat->GetAsCString();
 
 		//free the old text we are going to replace it below with an upper case version
 		unicodeTextFormat->Free();
@@ -276,11 +272,7 @@ void COleClipSource::DoUpperLowerCase(CClip &clip, bool upper)
 	IClipFormat *asciiTextFormat = clip.m_Formats.FindFormatEx(CF_TEXT);
 	if (asciiTextFormat != NULL)
 	{
-		HGLOBAL data = asciiTextFormat->Data();
-		char * stringData = (char *) GlobalLock(data);
-		int size = (int) GlobalSize(data);
-		CStringA cs(stringData);
-		GlobalUnlock(data);
+		CStringA cs(asciiTextFormat->GetAsCStringA());
 
 		//free the old text we are going to replace it below with an upper case version
 		asciiTextFormat->Free();
@@ -308,11 +300,7 @@ void COleClipSource::InvertCase(CClip &clip)
 	IClipFormat *unicodeTextFormat = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
 	if (unicodeTextFormat != NULL)
 	{
-		HGLOBAL data = unicodeTextFormat->Data();
-		wchar_t * stringData = (wchar_t *)GlobalLock(data);
-		int size = (int)GlobalSize(data);
-		CString cs(stringData);
-		GlobalUnlock(data);
+		CString cs(unicodeTextFormat->GetAsCString());	
 
 		//free the old text we are going to replace it below with an upper case version
 		unicodeTextFormat->Free();
@@ -347,11 +335,7 @@ void COleClipSource::InvertCase(CClip &clip)
 	IClipFormat *asciiTextFormat = clip.m_Formats.FindFormatEx(CF_TEXT);
 	if (asciiTextFormat != NULL)
 	{
-		HGLOBAL data = asciiTextFormat->Data();
-		char * stringData = (char *)GlobalLock(data);
-		int size = (int)GlobalSize(data);
-		CStringA cs(stringData);
-		GlobalUnlock(data);
+		CStringA cs(asciiTextFormat->GetAsCStringA());
 
 		//free the old text we are going to replace it below with an upper case version
 		asciiTextFormat->Free();
@@ -389,11 +373,7 @@ void COleClipSource::Capitalize(CClip &clip)
 	IClipFormat *unicodeTextFormat = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
 	if (unicodeTextFormat != NULL)
 	{
-		HGLOBAL data = unicodeTextFormat->Data();
-		wchar_t * stringData = (wchar_t *) GlobalLock(data);
-		int size = (int) GlobalSize(data);
-		CString cs(stringData);
-		GlobalUnlock(data);
+		CString cs(unicodeTextFormat->GetAsCString());	
 
 		//free the old text we are going to replace it below with an upper case version
 		unicodeTextFormat->Free();
@@ -439,11 +419,7 @@ void COleClipSource::Capitalize(CClip &clip)
 	IClipFormat *asciiTextFormat = clip.m_Formats.FindFormatEx(CF_TEXT);
 	if (asciiTextFormat != NULL)
 	{
-		HGLOBAL data = asciiTextFormat->Data();
-		char * stringData = (char *) GlobalLock(data);
-		int size = (int) GlobalSize(data);
-		CStringA cs(stringData);
-		GlobalUnlock(data);
+		CStringA cs(asciiTextFormat->GetAsCStringA());
 
 		//free the old text we are going to replace it below with an upper case version
 		asciiTextFormat->Free();
@@ -486,11 +462,7 @@ void COleClipSource::SentenceCase(CClip &clip)
 	IClipFormat *unicodeTextFormat = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
 	if (unicodeTextFormat != NULL)
 	{
-		HGLOBAL data = unicodeTextFormat->Data();
-		wchar_t * stringData = (wchar_t *) GlobalLock(data);
-		int size = (int) GlobalSize(data);
-		CString cs(stringData);
-		GlobalUnlock(data);
+		CString cs(unicodeTextFormat->GetAsCString());
 
 		//free the old text we are going to replace it below with an upper case version
 		unicodeTextFormat->Free();
@@ -535,11 +507,7 @@ void COleClipSource::SentenceCase(CClip &clip)
 	IClipFormat *asciiTextFormat = clip.m_Formats.FindFormatEx(CF_TEXT);
 	if (asciiTextFormat != NULL)
 	{
-		HGLOBAL data = asciiTextFormat->Data();
-		char * stringData = (char *) GlobalLock(data);
-		int size = (int) GlobalSize(data);
-		CStringA cs(stringData);
-		GlobalUnlock(data);
+		CStringA cs(asciiTextFormat->GetAsCStringA());
 
 		//free the old text we are going to replace it below with an upper case version
 		asciiTextFormat->Free();
@@ -623,65 +591,50 @@ void COleClipSource::RemoveLineFeeds(CClip &clip)
 {
 	IClipFormat *pUnicodeText = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
 	if (pUnicodeText != NULL)
-	{
-		wchar_t *stringData = (wchar_t *) GlobalLock(pUnicodeText->Data());
-		if (stringData != NULL)
-		{
-			CStringW string(stringData);
-
-			GlobalUnlock(pUnicodeText->Data());
-			pUnicodeText->Free();
+	{		
+		CStringW string(pUnicodeText->GetAsCString());
+		
+		pUnicodeText->Free();
 
-			int count = string.Replace(_T("\r\n"), _T(" "));
-			count = string.Replace(_T("\r"), _T(" "));
-			count = string.Replace(_T("\n"), _T(" "));
+		int count = string.Replace(_T("\r\n"), _T(" "));
+		count = string.Replace(_T("\r"), _T(" "));
+		count = string.Replace(_T("\n"), _T(" "));
 			
-			HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1) * sizeof(wchar_t)));
+		HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1) * sizeof(wchar_t)));
 
-			pUnicodeText->Data(hGlobal);
-		}
+		pUnicodeText->Data(hGlobal);
 	}
 
 	IClipFormat *pAsciiText = clip.m_Formats.FindFormatEx(CF_TEXT);
 	if (pAsciiText != NULL)
 	{
-		char *stringData = (char *) GlobalLock(pAsciiText->Data());
-		if (stringData != NULL)
-		{
-			CStringA string(stringData);
+		CStringA string(pAsciiText->GetAsCStringA());
 
-			GlobalUnlock(pAsciiText->Data());
-			pAsciiText->Free();
+		pAsciiText->Free();
 
-			int count = string.Replace("\r\n", " ");
-			count = string.Replace("\r", " ");
-			count = string.Replace("\n", " ");
+		int count = string.Replace("\r\n", " ");
+		count = string.Replace("\r", " ");
+		count = string.Replace("\n", " ");
 
-			HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1)));
+		HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1)));
 
-			pAsciiText->Data(hGlobal);
-		}
+		pAsciiText->Data(hGlobal);
 	}
 
 	IClipFormat *pRTFFormat = clip.m_Formats.FindFormatEx(theApp.m_RTFFormat);
 	if (pRTFFormat != NULL)
 	{
-		char *stringData = (char *) GlobalLock(pRTFFormat->Data());
-		if (stringData != NULL)
-		{
-			CStringA string(stringData);
-
-			GlobalUnlock(pRTFFormat->Data());
-			pRTFFormat->Free();
+		CStringA string(pRTFFormat->GetAsCStringA());
+		
+		pRTFFormat->Free();
 
-			int count = string.Replace("\\par\r\n", " ");
-			int count2 = string.Replace("\\par ", " ");
-			int count3 = string.Replace("\\line ", " ");
+		int count = string.Replace("\\par\r\n", " ");
+		int count2 = string.Replace("\\par ", " ");
+		int count3 = string.Replace("\\line ", " ");
 			
-			HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1)));
+		HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1)));
 
-			pRTFFormat->Data(hGlobal);
-		}
+		pRTFFormat->Data(hGlobal);
 	}
 }
 
@@ -689,72 +642,57 @@ void COleClipSource::AddLineFeeds(CClip &clip, int count)
 {
 	IClipFormat *pUnicodeText = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
 	if (pUnicodeText != NULL)
-	{
-		wchar_t *stringData = (wchar_t *) GlobalLock(pUnicodeText->Data());
-		if (stringData != NULL)
-		{
-			CStringW string(stringData);
-
-			GlobalUnlock(pUnicodeText->Data());
-			pUnicodeText->Free();
+	{		
+		CStringW string(pUnicodeText->GetAsCString());
+		
+		pUnicodeText->Free();
 
-			for(int i = 0; i < count; i++)
-			{
-				string += _T("\r\n");
-			}
+		for(int i = 0; i < count; i++)
+		{
+			string += _T("\r\n");
+		}
 
-			HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1) * sizeof(wchar_t)));
+		HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1) * sizeof(wchar_t)));
 
-			pUnicodeText->Data(hGlobal);
-		}
+		pUnicodeText->Data(hGlobal);
 	}
 
 	IClipFormat *pAsciiText = clip.m_Formats.FindFormatEx(CF_TEXT);
 	if (pAsciiText != NULL)
-	{
-		char *stringData = (char *) GlobalLock(pAsciiText->Data());
-		if (stringData != NULL)
-		{
-			CStringA string(stringData);
+	{		
+		CStringA string(pAsciiText->GetAsCStringA());
 
-			GlobalUnlock(pAsciiText->Data());
-			pAsciiText->Free();
+		pAsciiText->Free();
 
-			for (int i = 0; i < count; i++)
-			{
-				string += "\r\n";
-			}
+		for (int i = 0; i < count; i++)
+		{
+			string += "\r\n";
+		}
 
-			HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1)));
+		HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1)));
 
-			pAsciiText->Data(hGlobal);
-		}
+		pAsciiText->Data(hGlobal);
 	}
 
 	IClipFormat *pRTFFormat = clip.m_Formats.FindFormatEx(theApp.m_RTFFormat);
 	if (pRTFFormat != NULL)
 	{
-		char *stringData = (char *) GlobalLock(pRTFFormat->Data());
-		if (stringData != NULL)
-		{
-			CStringA string(stringData);
-
-			GlobalUnlock(pRTFFormat->Data());
-			pRTFFormat->Free();
+		CStringA string(pRTFFormat->GetAsCStringA());
+			
+		pRTFFormat->Free();
 
-			for (int i = 0; i < count; i++)
+		for (int i = 0; i < count; i++)
+		{
+			int pos = string.ReverseFind('}');
+			if (pos >= 0)
 			{
-				int pos = string.ReverseFind('}');
-				if (pos >= 0)
-				{
-					int count = string.Insert(pos, "\\par\r\n");
-				}
+				int count = string.Insert(pos, "\\par\r\n");
 			}
+		}
 
-			HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1)));
+		HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1)));
 
-			pRTFFormat->Data(hGlobal);
-		}
+		pRTFFormat->Data(hGlobal);
 	}
 }
 
@@ -763,75 +701,58 @@ void COleClipSource::AddDateTime(CClip &clip)
 	IClipFormat *pUnicodeText = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
 	if (pUnicodeText != NULL)
 	{
-		wchar_t *stringData = (wchar_t *)GlobalLock(pUnicodeText->Data());
-		if (stringData != NULL)
-		{
-			CStringW string(stringData);
+		CStringW string(pUnicodeText->GetAsCString());
+		pUnicodeText->Free();
 
-			GlobalUnlock(pUnicodeText->Data());
-			pUnicodeText->Free();
+		string += _T("\r\n");
 
-			string += _T("\r\n");
+		COleDateTime now(COleDateTime::GetCurrentTime());
+		string += now.Format();			
 
-			COleDateTime now(COleDateTime::GetCurrentTime());
-			string += now.Format();			
+		HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1) * sizeof(wchar_t)));
 
-			HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1) * sizeof(wchar_t)));
-
-			pUnicodeText->Data(hGlobal);
-		}
+		pUnicodeText->Data(hGlobal);
 	}
 
 	IClipFormat *pAsciiText = clip.m_Formats.FindFormatEx(CF_TEXT);
 	if (pAsciiText != NULL)
 	{
-		char *stringData = (char *)GlobalLock(pAsciiText->Data());
-		if (stringData != NULL)
-		{
-			CStringA string(stringData);
-
-			GlobalUnlock(pAsciiText->Data());
-			pAsciiText->Free();
+		CStringA string(pAsciiText->GetAsCStringA());
+		pAsciiText->Free();
 
-			string += "\r\n\r\n";
+		string += "\r\n\r\n";
 
-			COleDateTime now(COleDateTime::GetCurrentTime());
-			string += CTextConvert::UnicodeStringToMultiByte(now.Format());
+		COleDateTime now(COleDateTime::GetCurrentTime());
+		string += CTextConvert::UnicodeStringToMultiByte(now.Format());
 
-			HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1)));
+		HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1)));
 
-			pAsciiText->Data(hGlobal);
-		}
+		pAsciiText->Data(hGlobal);
 	}
 
 	IClipFormat *pRTFFormat = clip.m_Formats.FindFormatEx(theApp.m_RTFFormat);
 	if (pRTFFormat != NULL)
 	{
-		char *stringData = (char *)GlobalLock(pRTFFormat->Data());
-		if (stringData != NULL)
-		{
-			CStringA string(stringData);
+		CStringA string(pRTFFormat->GetAsCStringA());
 
-			GlobalUnlock(pRTFFormat->Data());
-			pRTFFormat->Free();
+		pRTFFormat->Free();
 			
-			int pos = string.ReverseFind('}');
-			if (pos >= 0)
-			{
-				string += _T("\r\n\r\n");
+		int pos = string.ReverseFind('}');
+		if (pos >= 0)
+		{
+			string += _T("\r\n\r\n");
 
-				COleDateTime now(COleDateTime::GetCurrentTime());
+			COleDateTime now(COleDateTime::GetCurrentTime());
 				
-				CStringA insert;
-				insert.Format("\\par\r\n\\par\r\n%s", CTextConvert::UnicodeStringToMultiByte(now.Format()));
+			CStringA insert;
+			insert.Format("\\par\r\n\\par\r\n%s", CTextConvert::UnicodeStringToMultiByte(now.Format()));
 
-				int count = string.Insert(pos, insert);
-			}
+			int count = string.Insert(pos, insert);
+		}
 
-			HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1)));
+		HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1)));
 
-			pRTFFormat->Data(hGlobal);
-		}
+		pRTFFormat->Data(hGlobal);
 	}
 }
 
@@ -839,46 +760,36 @@ void COleClipSource::TrimWhiteSpace(CClip &clip)
 {
 	IClipFormat *pUnicodeText = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
 	if (pUnicodeText != NULL)
-	{
-		wchar_t *stringData = (wchar_t *)GlobalLock(pUnicodeText->Data());
-		if (stringData != NULL)
-		{
-			CStringW string(stringData);
+	{		
+		CStringW string(pUnicodeText->GetAsCString());
 
-			GlobalUnlock(pUnicodeText->Data());
-			pUnicodeText->Free();
+		pUnicodeText->Free();
 
-			string = string.Trim();
-			string = string.Trim(_T("\t"));
-			string = string.Trim(_T("\r"));
-			string = string.Trim(_T("\n"));			
+		string = string.Trim();
+		string = string.Trim(_T("\t"));
+		string = string.Trim(_T("\r"));
+		string = string.Trim(_T("\n"));			
 
-			HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1) * sizeof(wchar_t)));
+		HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1) * sizeof(wchar_t)));
 
-			pUnicodeText->Data(hGlobal);
-		}
+		pUnicodeText->Data(hGlobal);
 	}
 
 	IClipFormat *pAsciiText = clip.m_Formats.FindFormatEx(CF_TEXT);
 	if (pAsciiText != NULL)
-	{
-		char *stringData = (char *)GlobalLock(pAsciiText->Data());
-		if (stringData != NULL)
-		{
-			CStringA string(stringData);
-
-			GlobalUnlock(pAsciiText->Data());
-			pAsciiText->Free();
+	{		
+		CStringA string(pAsciiText->GetAsCStringA());
+				
+		pAsciiText->Free();
 
-			string = string.Trim();
-			string = string.Trim("\t");
-			string = string.Trim("\r");
-			string = string.Trim("\n");
+		string = string.Trim();
+		string = string.Trim("\t");
+		string = string.Trim("\r");
+		string = string.Trim("\n");
 
-			HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1)));
+		HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1)));
 
-			pAsciiText->Data(hGlobal);
-		}
+		pAsciiText->Data(hGlobal);
 	}
 }
 
@@ -977,11 +888,7 @@ void COleClipSource::Typoglycemia(CClip &clip)
 	IClipFormat *unicodeTextFormat = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
 	if (unicodeTextFormat != NULL)
 	{
-		HGLOBAL data = unicodeTextFormat->Data();
-		wchar_t * stringData = (wchar_t *) GlobalLock(data);
-		int size = (int) GlobalSize(data);
-		CString cs(stringData);
-		GlobalUnlock(data);
+		CString cs(unicodeTextFormat->GetAsCString());	
 
 		//free the old text we are going to replace it below with an upper case version
 		unicodeTextFormat->Free();
@@ -1095,11 +1002,6 @@ INT_PTR COleClipSource::PutFormatOnClipboard(CClipFormats *pFormats)
 
 			continue;
 		}
-
-		wchar_t * stringData = (wchar_t *) GlobalLock(pCF->m_hgData);
-		int size = (int) GlobalSize(pCF->m_hgData);
-		CString cs(stringData);
-		GlobalUnlock(pCF->m_hgData);
 		
 		Log(StrF(_T("Setting clipboard type: %s to the clipboard"), GetFormatName(pCF->m_cfType)));
 
@@ -1301,11 +1203,7 @@ void COleClipSource::Slugify(CClip &clip)
 	IClipFormat *unicodeTextFormat = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
 	if (unicodeTextFormat != NULL)
 	{
-		HGLOBAL data = unicodeTextFormat->Data();
-		wchar_t * stringData = (wchar_t *)GlobalLock(data);
-		int size = (int)GlobalSize(data);
-		CString cs(stringData);
-		GlobalUnlock(data);
+		CString cs(unicodeTextFormat->GetAsCString());	
 
 		//free the old text we are going to replace it below with an upper case version
 		unicodeTextFormat->Free();

+ 20 - 50
QListCtrl.cpp

@@ -518,21 +518,17 @@ BOOL CQListCtrl::DrawRtfText(int nItem, CRect &crRect, CDC *pDC)
 
 	if (m_pFormatter)
 	{
-		char *pData = (char*)GlobalLock(pThumbnail->m_hgData);
-		if (pData)
-		{
-			//somehow ms word places crazy rtf text onto the clipboard and our draw routine doesn't handle that
-			//pass the rtf text into a richtext control and get it out and the contorl will clean  the rtf so our routine can draw it
-			m_rtfFormater.SetRTF((char*)pData);
-			CString betterRTF = m_rtfFormater.GetRTF();
+		//somehow ms word places crazy rtf text onto the clipboard and our draw routine doesn't handle that
+		//pass the rtf text into a richtext control and get it out and the contorl will clean  the rtf so our routine can draw it
+		m_rtfFormater.SetRTF(pThumbnail->GetAsCStringA());
+		CString betterRTF = m_rtfFormater.GetRTF();
 
-			CComBSTR bStr(betterRTF);
-			m_pFormatter->put_RTFText(bStr);
+		CComBSTR bStr(betterRTF);
+		m_pFormatter->put_RTFText(bStr);
 
-			m_pFormatter->Draw(pDC->m_hDC, crRect);
+		m_pFormatter->Draw(pDC->m_hDC, crRect);
 
-			bRet = TRUE;
-		}
+		bRet = TRUE;
 	}
 
 	return bRet;
@@ -1016,18 +1012,11 @@ bool CQListCtrl::ShowFullDescription(bool bFromAuto, bool fromNextPrev)
 		}
 		CATCH_SQLITE_EXCEPTION
 
-			Clip.m_cfType = CF_UNICODETEXT;
+		Clip.m_cfType = CF_UNICODETEXT;
 		if (GetClipData(nItem, Clip) && Clip.m_hgData)
 		{
-			LPVOID pvData = GlobalLock(Clip.m_hgData);
-			if (pvData)
-			{
-				CString csText = (WCHAR*)pvData;
-				m_pToolTip->SetToolTipText(csText);
-				bSetPlainText = true;
-			}
-
-			GlobalUnlock(Clip.m_hgData);
+			m_pToolTip->SetToolTipText(Clip.GetAsCString());
+			bSetPlainText = true;		
 
 			Clip.Free();
 			Clip.Clear();
@@ -1037,17 +1026,11 @@ bool CQListCtrl::ShowFullDescription(bool bFromAuto, bool fromNextPrev)
 		{
 			Clip.m_cfType = CF_TEXT;
 			if (GetClipData(nItem, Clip) && Clip.m_hgData)
-			{
-				LPVOID pvData = GlobalLock(Clip.m_hgData);
-				if (pvData)
-				{
-					CString csText = (char*)pvData;
-					m_pToolTip->SetToolTipText(csText);
-
-					bSetPlainText = true;
-				}
+			{	
+				CString cs(Clip.GetAsCStringA());
 
-				GlobalUnlock(Clip.m_hgData);
+				m_pToolTip->SetToolTipText(cs);
+				bSetPlainText = true;
 
 				Clip.Free();
 				Clip.Clear();
@@ -1063,14 +1046,8 @@ bool CQListCtrl::ShowFullDescription(bool bFromAuto, bool fromNextPrev)
 
 		if (GetClipData(nItem, Clip) && Clip.m_hgData)
 		{
-			LPVOID pvData = GlobalLock(Clip.m_hgData);
-			if (pvData)
-			{
-				m_pToolTip->SetRTFText((char*)pvData);
-			}
-
-			GlobalUnlock(Clip.m_hgData);
-
+			m_pToolTip->SetRTFText(Clip.GetAsCStringA());
+		
 			Clip.Free();
 			Clip.Clear();
 		}
@@ -1079,15 +1056,9 @@ bool CQListCtrl::ShowFullDescription(bool bFromAuto, bool fromNextPrev)
 		Clip.m_cfType = GetFormatID(_T("HTML Format"));
 		if (GetClipData(nItem, Clip) && Clip.m_hgData)
 		{
-			LPVOID pvData = GlobalLock(Clip.m_hgData);
-			if (pvData)
-			{
-				CString html;
-				CTextConvert::ConvertFromUTF8(CStringA((char*)pvData), html);
-				m_pToolTip->SetHtmlText(html);
-			}
-
-			GlobalUnlock(Clip.m_hgData);
+			CString html;
+			CTextConvert::ConvertFromUTF8(Clip.GetAsCStringA(), html);
+			m_pToolTip->SetHtmlText(html);		
 
 			Clip.Free();
 			Clip.Clear();
@@ -1103,7 +1074,6 @@ bool CQListCtrl::ShowFullDescription(bool bFromAuto, bool fromNextPrev)
 			Clip.m_cfType = theApp.m_PNG_Format;
 			if (GetClipData(nItem, Clip) && Clip.m_hgData)
 			{
-
 				m_pToolTip->SetGdiplusBitmap(Clip.CreateGdiplusBitmap());
 			}
 		}

+ 51 - 49
Shared/IClip.h

@@ -1,50 +1,52 @@
-#pragma once
-
-#include "DittoDefines.h"
-
-//Contains the actual data of a clip format
-// Type is the type of clipboard format
-// Data is a HGLOBAL object pointing to the clipboard format data
-class IClipFormat
-{
-public:
-	virtual CLIPFORMAT Type() = 0;
-	virtual HGLOBAL Data() = 0;
-	virtual bool AutoDeleteData() = 0;
-	virtual void Type(CLIPFORMAT type) = 0;
-	virtual void Data(HGLOBAL data) = 0;
-	virtual void AutoDeleteData(bool autoDelete) = 0;
-	virtual void Free() = 0;
-};
-
-//Contains a list of IClipFormats
-//This is a list of all data associated with a clip
-class IClipFormats
-{
-public:
-	virtual int Size() = 0;
-	virtual IClipFormat *GetAt(int nPos) = 0;
-	virtual void DeleteAt(int nPos) = 0;
-	virtual void DeleteAll() = 0;
-	virtual INT_PTR AddNew(CLIPFORMAT type, HGLOBAL data) = 0;
-	virtual IClipFormat *FindFormatEx(CLIPFORMAT type) = 0;
-	virtual bool RemoveFormat(CLIPFORMAT type) = 0;
-};
-
-class IClip
-{
-public:
-	virtual CString Description() = 0;
-	virtual void Description(CString csValue) = 0;
-	virtual CTime PasteTime() = 0;
-	virtual int ID() = 0;
-	virtual int Parent() = 0;
-	virtual void Parent(int nParent) = 0;
-	virtual int DontAutoDelete() = 0;
-	virtual void DontAutoDelete(int Dont) = 0;
-	virtual CString QuickPaste() = 0;
-	virtual void QuickPaste(CString csValue) = 0;
-	virtual void SetSaveToDbSticky(AddToDbStickyEnum::AddToDbSticky option) = 0;
-
-	virtual IClipFormats *Clips() = 0;
+#pragma once
+
+#include "DittoDefines.h"
+
+//Contains the actual data of a clip format
+// Type is the type of clipboard format
+// Data is a HGLOBAL object pointing to the clipboard format data
+class IClipFormat
+{
+public:
+	virtual CLIPFORMAT Type() = 0;
+	virtual HGLOBAL Data() = 0;
+	virtual bool AutoDeleteData() = 0;
+	virtual void Type(CLIPFORMAT type) = 0;
+	virtual void Data(HGLOBAL data) = 0;
+	virtual void AutoDeleteData(bool autoDelete) = 0;
+	virtual void Free() = 0;
+	virtual CStringA GetAsCStringA() = 0;
+	virtual CString GetAsCString() = 0;
+};
+
+//Contains a list of IClipFormats
+//This is a list of all data associated with a clip
+class IClipFormats
+{
+public:
+	virtual int Size() = 0;
+	virtual IClipFormat *GetAt(int nPos) = 0;
+	virtual void DeleteAt(int nPos) = 0;
+	virtual void DeleteAll() = 0;
+	virtual INT_PTR AddNew(CLIPFORMAT type, HGLOBAL data) = 0;
+	virtual IClipFormat *FindFormatEx(CLIPFORMAT type) = 0;
+	virtual bool RemoveFormat(CLIPFORMAT type) = 0;
+};
+
+class IClip
+{
+public:
+	virtual CString Description() = 0;
+	virtual void Description(CString csValue) = 0;
+	virtual CTime PasteTime() = 0;
+	virtual int ID() = 0;
+	virtual int Parent() = 0;
+	virtual void Parent(int nParent) = 0;
+	virtual int DontAutoDelete() = 0;
+	virtual void DontAutoDelete(int Dont) = 0;
+	virtual CString QuickPaste() = 0;
+	virtual void QuickPaste(CString csValue) = 0;
+	virtual void SetSaveToDbSticky(AddToDbStickyEnum::AddToDbSticky option) = 0;
+
+	virtual IClipFormats *Clips() = 0;
 };

+ 3 - 3
ToolTipEx.cpp

@@ -829,10 +829,10 @@ void CToolTipEx::SetHtmlText(const CString &html)
 	}
 }
 
-void CToolTipEx::SetRTFText(const char *pRTF)
+void CToolTipEx::SetRTFText(const CStringA &rtf)
 {
-    m_RichEdit.SetRTF(pRTF);
-    m_csRTF = pRTF;
+    m_RichEdit.SetRTF(rtf);
+    m_csRTF = rtf;
 	m_RichEdit.SetSel(0, 0);
 	
 	HighlightSearchText();

+ 1 - 1
ToolTipEx.h

@@ -26,7 +26,7 @@ public:
 	BOOL Show(CPoint point);
 	BOOL Hide();
 	void SetToolTipText(const CString &csText);
-	void SetRTFText(const char *pRTF);
+	void SetRTFText(const CStringA &rtf);
 	void SetHtmlText(const CString &html);
 	void SetGdiplusBitmap(Gdiplus::Bitmap *gdiplusBitmap);
 	void SetNotifyWnd(CWnd *pNotify)		{ m_pNotifyWnd = pNotify;	}