Hi,
I am using jeffrey richters's example 22 LastMsgBoxInfoLib, modified to hook User32.dll's SetClipboardData and GetClipboardData functions. But after hooking, neither the client app nor dll is able to successfully call OpenClipboard().
The dll is win32 based and client is in mfc, Visual Studiio 2005 SP1, Windows XP Sp3
HANDLE WINAPI Hook_GetClipboardData(UINT uType)
{ ......
if(_tcsicmp(allowedAppName, szProcessPathname) == 0)
{
HANDLE nResult = ((PFNGETCLIPBOARDDATA)(PROC) g_GetClipboardData)(uType);
if(OpenClipboard(NULL)){
....I never reach here...
}
return nResult;
}
}
//Code inside mfc client
Before hooking this call works, so I can set data in clipboard first time. But after hooking OpenClipboard() fails.
if(OpenClipboard()){
HGLOBAL hClipboardData;
bool res = EmptyClipboard();
TCHAR* arr;
size_t bytes = (m_szCer.GetLength()+1)*sizeof(TCHAR);
hClipboardData = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE,(m_szCer.GetLength()+1)*sizeof(TCHAR));
if (!hClipboardData) return;
arr=(TCHAR*)GlobalLock(hClipboardData);
_tcscpy(arr, LPCTSTR(m_szCer));
res = GlobalUnlock(hClipboardData);
VERIFY(SetClipboardData(CF_UNICODETEXT, hClipboardData));
res = CloseClipboard();
}
Also the following line in the function always returns false whether called before or after hooking.
res = GlobalUnlock(hClipboardData);
My idea was to try to unhook the the two clipboard function before I reset the clipboard second time, but no luck.
LastClipBoardInfo_HookAllApps(TRUE,dwThreadId,"fsd","as",.....);
LastClipBoardInfo_HookAllApps(FALSE,dwThreadId,"","",.....);
Please help me on this.
Thanks
Bikram...