一点猥琐代码


   
   
// Register app for pen windows (if possible) bPenWin = FALSE; if ((hPenWin = GetSystemMetrics (SM_PENWINDOWS)) != NULL) { if ((RegisterPenApp = (LPREGISTERPENAPP) GetProcAddress (hPenWin, " RegisterPenApp " )) != NULL) { ( * RegisterPenApp)(RPA_DEFAULT, TRUE); bPenWin = TRUE; } }

SetWinEventHook这个函数可以用来注入DLL..

具体如何注入看MSDN吧..还有其他很多猥琐的用法```具体如何猥琐大家自己想吧。

我刚开始用这个函数的时候始终能安装成功,但是就是无法捕获到信息..

最后翻墙到国外...再查阅MSDN发现有这么一句话..

The client thread that calls SetWinEventHook must have a message loop in order to receive events.

翻译一下就是:调用了SetWinEventHook h函数的线程需要一个消息循环来接受事件。

之前一直写个MAIN就完了..杯具啊!!

代码如下:

#include <Windows.h>

#include <stdio.h>

#include <WinUser.h>

#include <oleacc.h>

#include "resource.h"

 

#pragma comment(lib, "Oleacc.lib")

 

// Global variable.

HWINEVENTHOOK g_hook;

// Callback function that handles events.

//

void _stdcall HandleWinEvent(HWINEVENTHOOK hook, DWORD event, HWND hwnd, 

LONG idObject, LONG idChild, 

DWORD dwEventThread, DWORD dwmsEventTime)

{

IAccessible* pAcc = NULL;

VARIANT varChild;

HRESULT hr = AccessibleObjectFromEvent(hwnd, idObject, idChild, &pAcc, &varChild);  

if ((hr == S_OK) && (pAcc != NULL))

{

BSTR bstrName;

pAcc->lpVtbl->get_accName(pAcc, varChild, &bstrName);

if (event == EVENT_SYSTEM_MENUSTART) 

{

printf("Begin: ");

}

else if (event == EVENT_SYSTEM_MENUEND)

{

printf("End:   ");

}

printf("%S\n", bstrName);

SysFreeString(bstrName);

pAcc->lpVtbl->Release(pAcc);

}

}

 

// Initializes COM and sets up the event hook.

//

void InitializeMSAA()

{

CoInitialize(NULL);

g_hook = SetWinEventHook(

EVENT_MIN, EVENT_MAX,  // Range of events (4 to 5).

NULL,                                          // Handle to DLL.

HandleWinEvent,                                // The callback.

0, 0,              // Process and thread IDs of interest (0 = all)

WINEVENT_OUTOFCONTEXT); // Flags.

}

 

// Unhooks the event and shuts down COM.

//

void ShutdownMSAA()

{

UnhookWinEvent(g_hook);

CoUninitialize();

}

 

INT_PTR CALLBACK DialogProc(

__in  HWND hwndDlg,

__in  UINT uMsg,

__in  WPARAM wParam,

__in  LPARAM lParam

)

{

switch(uMsg)

{

case WM_CLOSE:

EndDialog(hwndDlg, 0);

break;

default:

return FALSE;

}

return TRUE;

 

}

 

int main(int _argc, char **_argv, char **_evn)

{

HINSTANCE hInstance;

hInstance = GetModuleHandle(NULL);

InitializeMSAA();

DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL,

DialogProc, 0);

ShutdownMSAA();

return 0;

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值