EDN Admin
Well-known member
Hi,<br/>
<br/>
I am using jeffrey richterss example 22 LastMsgBoxInfoLib, modified to hook User32.dlls SetClipboardData and GetClipboardData functions. But after hooking, neither the client app nor dll is able to successfully call OpenClipboard().<br/>
The dll is in win32 ;and client is in mfc. Visual Studiio 2005 SP1, Windows XP Sp3<br/>
//This is a GetClipboardData replacement function inside dll<br/>
HANDLE WINAPI Hook_GetClipboardData(UINT uType)<br/>
{ ......<br/>
<br/>
//Check if notepad or wordpad<br/>
if(_tcsicmp(allowedAppName, szProcessPathname) == 0)//If user allowed app send info to change value of clipboard<br/>
{<br/>
<br/>
HANDLE nResult = ((PFNGETCLIPBOARDDATA)(PROC) g_GetClipboardData)(uType); //original hooked fn called.<br/>
//now call the openclipboard to set custom data in clipboard.<br/>
//This call fails<br/>
if(OpenClipboard(NULL)){ //this call fails<br/>
<br/>
....I never reach here...<br/>
}<br/>
return nResult;<br/>
<br/>
}<br/>
} <br/>
<br/>
//Code inside mfc client<br/>
Before hooking this call works, so I can set data in clipboard first time. But after hooking OpenClipboard() fails.<br/>
<br/>
if(OpenClipboard()){<br/>
HGLOBAL hClipboardData;<br/>
bool res = EmptyClipboard();<br/>
TCHAR* arr;<br/>
size_t bytes = (m_szCer.GetLength()+1)*sizeof(TCHAR);<br/>
hClipboardData = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE,(m_szCer.GetLength()+1)*sizeof(TCHAR));<br/>
if (!hClipboardData) return;<br/>
arr=(TCHAR*)GlobalLock(hClipboardData);<br/>
_tcscpy(arr, LPCTSTR(m_szCer)); <br/>
//This call always returns false;<br/>
res = GlobalUnlock(hClipboardData);//Here result is always false.<br/>
//Why the above call always fails...<br/>
<br/>
VERIFY(SetClipboardData(CF_UNICODETEXT, hClipboardData));<br/>
res = CloseClipboard();<br/>
<br/>
} <br/>
<br/>
Also the following line in the function always returns false whether called before or after hooking.<br/>
<br/>
res = GlobalUnlock(hClipboardData);//Here result is always false.
My idea was to try to unhook the the two clipboard function before I reset the clipboard second time, but no luck.<br/>
///this call is to set the hook, dwThreadId =0;<br/>
LastClipBoardInfo_HookAllApps(TRUE,dwThreadId,"fsd","as",.....);<br/>
///and this call to unhook is<br/>
LastClipBoardInfo_HookAllApps(FALSE,dwThreadId,"","",.....);<br/>
<br/>
Please guide<br/>
<br/>
<br/>
Thanks<br/>
<br/>
Bikram...
<br/>
View the full article
<br/>
I am using jeffrey richterss example 22 LastMsgBoxInfoLib, modified to hook User32.dlls SetClipboardData and GetClipboardData functions. But after hooking, neither the client app nor dll is able to successfully call OpenClipboard().<br/>
The dll is in win32 ;and client is in mfc. Visual Studiio 2005 SP1, Windows XP Sp3<br/>
//This is a GetClipboardData replacement function inside dll<br/>
HANDLE WINAPI Hook_GetClipboardData(UINT uType)<br/>
{ ......<br/>
<br/>
//Check if notepad or wordpad<br/>
if(_tcsicmp(allowedAppName, szProcessPathname) == 0)//If user allowed app send info to change value of clipboard<br/>
{<br/>
<br/>
HANDLE nResult = ((PFNGETCLIPBOARDDATA)(PROC) g_GetClipboardData)(uType); //original hooked fn called.<br/>
//now call the openclipboard to set custom data in clipboard.<br/>
//This call fails<br/>
if(OpenClipboard(NULL)){ //this call fails<br/>
<br/>
....I never reach here...<br/>
}<br/>
return nResult;<br/>
<br/>
}<br/>
} <br/>
<br/>
//Code inside mfc client<br/>
Before hooking this call works, so I can set data in clipboard first time. But after hooking OpenClipboard() fails.<br/>
<br/>
if(OpenClipboard()){<br/>
HGLOBAL hClipboardData;<br/>
bool res = EmptyClipboard();<br/>
TCHAR* arr;<br/>
size_t bytes = (m_szCer.GetLength()+1)*sizeof(TCHAR);<br/>
hClipboardData = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE,(m_szCer.GetLength()+1)*sizeof(TCHAR));<br/>
if (!hClipboardData) return;<br/>
arr=(TCHAR*)GlobalLock(hClipboardData);<br/>
_tcscpy(arr, LPCTSTR(m_szCer)); <br/>
//This call always returns false;<br/>
res = GlobalUnlock(hClipboardData);//Here result is always false.<br/>
//Why the above call always fails...<br/>
<br/>
VERIFY(SetClipboardData(CF_UNICODETEXT, hClipboardData));<br/>
res = CloseClipboard();<br/>
<br/>
} <br/>
<br/>
Also the following line in the function always returns false whether called before or after hooking.<br/>
<br/>
res = GlobalUnlock(hClipboardData);//Here result is always false.
My idea was to try to unhook the the two clipboard function before I reset the clipboard second time, but no luck.<br/>
///this call is to set the hook, dwThreadId =0;<br/>
LastClipBoardInfo_HookAllApps(TRUE,dwThreadId,"fsd","as",.....);<br/>
///and this call to unhook is<br/>
LastClipBoardInfo_HookAllApps(FALSE,dwThreadId,"","",.....);<br/>
<br/>
Please guide<br/>
<br/>
<br/>
Thanks<br/>
<br/>
Bikram...
<br/>
View the full article