• DLL建立读写共享节区(Segment)


    // Hook.cpp : Defines the entry point for the DLL application.
    //
    
    #include "stdafx.h"
    #include "Hook.h"
    
    HHOOK g_hHook;
    HHOOK g_hHookKey;
    HINSTANCE g_hIns;
    
    #pragma data_seg("MySeg")
    HWND g_hWnd =NULL;
    #pragma data_seg()
    
    //#pragma comment(linker,"/section:MySeg,RWS")
    
    BOOL APIENTRY DllMain( HANDLE hModule, 
                           DWORD  ul_reason_for_call, 
                           LPVOID lpReserved
    					 )
    {
    	g_hIns =(HINSTANCE) hModule;
    //     switch (ul_reason_for_call)
    // 	{
    // 		case DLL_PROCESS_ATTACH:
    // 		case DLL_THREAD_ATTACH:
    // 		case DLL_THREAD_DETACH:
    // 		case DLL_PROCESS_DETACH:
    // 			break;
    //     }
        return TRUE;
    }
    
    LRESULT CALLBACK MouseProc(
    						   int nCode,      // hook code
    						   WPARAM wParam,  // message identifier
    						   LPARAM lParam   // mouse coordinates
    						   )
    {
    	return 1;
    }
    
    
    LRESULT CALLBACK KeyProc(
    						   int nCode,      // hook code
    						   WPARAM wParam,  // message identifier
    						   LPARAM lParam   // mouse coordinates
    						   )
    {
    	if(wParam == VK_F2){
    		UnhookWindowsHookEx(g_hHook);
    		UnhookWindowsHookEx(g_hHookKey);
    		//MessageBox(0,"去掉了Hook","提示",0);
    		::SendMessage(g_hWnd,WM_CLOSE,0,0);
    		return 1;
    	}
    	else return CallNextHookEx(g_hHookKey,nCode,wParam,lParam);	
    }
    
    HOOK_API void SetHook(HWND hWnd)
    {
    	g_hWnd = hWnd;
    // 	g_hHook = SetWindowsHookEx(WH_MOUSE,MouseProc,g_hIns,0);
    // 	g_hHookKey = SetWindowsHookEx(WH_KEYBOARD,KeyProc,g_hIns,0);
    	g_hHook = SetWindowsHookEx(WH_MOUSE,MouseProc,GetModuleHandle("Hook.dll"),0);
    	g_hHookKey = SetWindowsHookEx(WH_KEYBOARD,KeyProc,GetModuleHandle("Hook"),0);
     
    }
    

      Hook.def

    LIBRARY Hook
    EXPORTS
    SetHook @23
    
    SEGMENTS
    MySeg	READ WRITE SHARED
    

      

    Client:

    /////////////////////////////////////////////////////////////////////////////
    // CHookTestDlg message handlers
    
    BOOL CHookTestDlg::OnInitDialog()
    {
    	CDialog::OnInitDialog();
    
    	// Add "About..." menu item to system menu.
    
    	// IDM_ABOUTBOX must be in the system command range.
    	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    	ASSERT(IDM_ABOUTBOX < 0xF000);
    
    	CMenu* pSysMenu = GetSystemMenu(FALSE);
    	if (pSysMenu != NULL)
    	{
    		CString strAboutMenu;
    		strAboutMenu.LoadString(IDS_ABOUTBOX);
    		if (!strAboutMenu.IsEmpty())
    		{
    			pSysMenu->AppendMenu(MF_SEPARATOR);
    			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    		}
    	}
    
    	// Set the icon for this dialog.  The framework does this automatically
    	//  when the application's main window is not a dialog
    	SetIcon(m_hIcon, TRUE);			// Set big icon
    	SetIcon(m_hIcon, FALSE);		// Set small icon
    	
    	// TODO: Add extra initialization here
    	int cx,cy;
    	cx=GetSystemMetrics(SM_CXSCREEN);
    	cy=GetSystemMetrics(SM_CYSCREEN);
    	SetWindowPos(&wndTopMost,0,0,cx,cy,SWP_SHOWWINDOW);
    
    	SetHook(this->m_hWnd);  
    
    	return TRUE;  // return TRUE  unless you set the focus to a control
    }
    

      

  • 相关阅读:
    50个jQuery 插件可将你的网站带到另外一个高度
    Web 开发中 20 个很有用的 CSS 库
    【算法】1、约瑟夫环
    智造微博
    银河系中央超大黑洞可能是个虫洞 其连接着两个不同的时空。
    创意文案:我害怕阅读的人
    解决Oracle ORA-00984: column not allowed here
    舌尖上的程序员
    技术贴 本地代码与svn关联教程 svn upgrade问题解决
    Aimp3的播放列表 按评分排序 落雨
  • 原文地址:https://www.cnblogs.com/wucg/p/2433985.html
Copyright © 2020-2023  润新知