Browse Source

load new clipboard monitor functions dynamically so Ditto works on xp

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@811 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 10 years ago
parent
commit
5e67bcbe06
1 changed files with 35 additions and 5 deletions
  1. 35 5
      ClipboardViewer.cpp

+ 35 - 5
ClipboardViewer.cpp

@@ -68,12 +68,26 @@ void CClipboardViewer::Connect()
 	
 	
 	m_bCalling_SetClipboardViewer = true;
 	m_bCalling_SetClipboardViewer = true;
 
 
+	bool useSetClipboardWnd = true;
+
 	if(IsVista())
 	if(IsVista())
 	{
 	{
-		Log(_T("Connecting to clipboard with function AddClipboardFormatListener"));
-		AddClipboardFormatListener(m_hWnd);
+		HMODULE hUser32 = LoadLibrary(_T("USER32.dll"));
+		if (hUser32) 
+		{
+			typedef BOOL (__stdcall *AddClipFormatListener)( HWND hwnd );
+
+			AddClipFormatListener addListener = (AddClipFormatListener) GetProcAddress(hUser32, "AddClipboardFormatListener");
+			if(addListener)
+			{
+				Log(_T("Connecting to clipboard with function AddClipboardFormatListener"));
+				useSetClipboardWnd = false;
+				addListener(m_hWnd);				
+			}
+		}
 	}
 	}
-	else
+	
+	if(useSetClipboardWnd)
 	{
 	{
 		Log(_T("Connecting to clipboard with function SetClipboardViewer"));
 		Log(_T("Connecting to clipboard with function SetClipboardViewer"));
 		m_hNextClipboardViewer = CWnd::SetClipboardViewer();		
 		m_hNextClipboardViewer = CWnd::SetClipboardViewer();		
@@ -98,13 +112,29 @@ void CClipboardViewer::Disconnect(bool bSendPing)
 	Log(_T("Disconnect From Clipboard"));
 	Log(_T("Disconnect From Clipboard"));
 
 
 	KillTimer(TIMER_ENSURE_VIEWER_IN_CHAIN);
 	KillTimer(TIMER_ENSURE_VIEWER_IN_CHAIN);
+	bool removeOldWay = true;
 
 
 	if(IsVista())
 	if(IsVista())
 	{
 	{
-		RemoveClipboardFormatListener(m_hWnd);
+		HMODULE hUser32 = LoadLibrary(_T("USER32.dll"));
+		if (hUser32) 
+		{
+			typedef BOOL (__stdcall *RemoveClipFormatListener)( HWND hwnd );
+
+			RemoveClipFormatListener removeListener = (RemoveClipFormatListener) GetProcAddress(hUser32, "RemoveClipboardFormatListener");
+			if(removeListener)
+			{
+				Log(_T("Disconnecting from clipboard with function RemoveClipboardFormatListener"));
+				removeOldWay = false;
+				removeListener(m_hWnd);				
+			}
+		}
 	}
 	}
-	else
+	
+	if(removeOldWay)
 	{
 	{
+		Log(_T("Disconnecting from clipboard with function ChangeClipboardChain"));
+
 		BOOL bRet = CWnd::ChangeClipboardChain(m_hNextClipboardViewer);
 		BOOL bRet = CWnd::ChangeClipboardChain(m_hNextClipboardViewer);
 		if(!bRet)
 		if(!bRet)
 		{
 		{