钩住SetClipboardData和Getclipboardata之后,OpenClipboard()失败 [英] After hooking SetClipboardData and Getclipboardata, OpenClipboard() fails

查看:112
本文介绍了钩住SetClipboardData和Getclipboardata之后,OpenClipboard()失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用jeffrey richters的示例22 LastMsgBoxInfoLib,将其修改为挂钩User32.dll的SetClipboardData和GetClipboardData函数.但是在挂接之后,客户端应用程序和dll都无法成功调用OpenClipboard().
该dll基于Win32,客户端位于MFC,Visual Studiio 2005 SP1,Windows XP Sp3中.

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

//This is a GetClipboardData replacement function inside dll
HANDLE WINAPI Hook_GetClipboardData(UINT uType)
{    ......

    //Check if notepad or wordpad
    if(_tcsicmp(allowedAppName, szProcessPathname) == 0)//If user allowed app send info to change value of clipboard
    {
        
        HANDLE nResult = ((PFNGETCLIPBOARDDATA)(PROC) g_GetClipboardData)(uType); //original hooked fn called.
       //now call the openclipboard to set custom data in clipboard.
       //This call fails
       if(OpenClipboard(NULL)){       //this call fails

        ....I never reach here...
        }
         return nResult;

    }
}   

//mfc客户端中的代码
在挂起此调用之前,我可以在剪贴板中第一次设置数据.但是,钩住OpenClipboard()后失败.

//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));         
         //This call always returns false;
          res = GlobalUnlock(hClipboardData);//Here result is always false.
        //Why the above call always fails...
        
         VERIFY(SetClipboardData(CF_UNICODETEXT, hClipboardData));
         res = CloseClipboard();
        
    }   

此外,函数中的以下行无论在挂钩之前还是之后都始终返回false.

Also the following line in the function always returns false whether called before or after hooking.

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.

///this call is to set the hook, dwThreadId =0;
LastClipBoardInfo_HookAllApps(TRUE,dwThreadId,"fsd","as",.....);
///and this call to unhook is
LastClipBoardInfo_HookAllApps(FALSE,dwThreadId,"","",.....);


请帮助我.

谢谢

Bikram ...


Please help me on this.

Thanks

Bikram...

推荐答案

在每次成功调用OpenClipboard之后,应用程序应调用CloseClipboard函数."

http://msdn.microsoft.com/en-us/library/ms649048 (v = vs.85).aspx [
"An application should call the CloseClipboard function after every successful call to OpenClipboard."

http://msdn.microsoft.com/en-us/library/ms649048(v=vs.85).aspx[^]


这篇关于钩住SetClipboardData和Getclipboardata之后,OpenClipboard()失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆