posted by 방랑군 2010. 1. 8. 16:23

http://support.microsoft.com/kb/601978/ko


IME message들은 OS가 Application의 message queue 로 posting하는 message가 아니라, 각 application의 WinProc를 직접 call하는 message이므로, CallWndProc hook procedure를 이용하여 hooking해야 합니다. 
다음은 WM_IME_NOTIFY message를 hooking하는 DLL 의 예제코드입니다.

## Hooking Procedure에서 추가되는 함수들은 user의 input를 기다리는 API는 사용하지 마십시오. 이것은 system의 performance를 떨어뜨리거나 심지어는 dead-lock 발생의 원인이 됩니다.


HHOOK hHook = NULL;
HINSTANCE hHookDll;
LRESULT CALLBACK GetMsgProc(int code,  WPARAM wParam,  LPARAM lParam);

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
)
{
hHookDll = (HINSTANCE )hModule;
     return TRUE;
}

BOOL APIENTRY  SetHookProc()
{
hHook =  SetWindowsHookEx(WH_GETMESSAGE,GetMsgProc,hHookDll,0);
if (hHook)
return true;
else
return false;
}

void APIENTRY UnsetHookProc()
{
UnhookWindowsHookEx(hHook);
}

LRESULT CALLBACK GetMsgProc(int code,  WPARAM wParam,  LPARAM lParam)
{
   MSG *msg = (MSG *)lParam;
   if ( msg->message == WM_IME_NOTIFY)
   {
   // TODO : Add to code what you want to act
  
   // Always call next hook in chain 
   return CallNextHookEx(hHook, code,  wParam, lParam);
}



'IT > 후킹' 카테고리의 다른 글

[MFC] 활성화 창 한/영 체크 및 변환  (0) 2010.02.23