|
어디서 어떻게 안되시는지요?
예제를 원하시는것 같아 간단한 예제 만들어서 올려드립니다.
이전에 말씀하셨던, 키보드 감지해서 Msg.TXT 파일로 저장하는 형태입니다.
우선, DLL 파일의 사용에 관해서 참고하시고, SetWindowsHookEx에 관하여
레퍼런스를 참고하시는 것이 접근이 좀 더 쉬우실것 같습니다.
cuperido
실행 파일및 전체 프로젝트 파일은 첨부파일 참조하십시오.
** DLL 파일 **
//---------------------------------------------------------------------------
#include <vcl.h>
#include <windows.h>
#include <stdio.h>
#pragma hdrstop
//---------------------------------------------------------------------------
// Important note about DLL memory management when your DLL uses the
// static version of the RunTime Library:
//
// If your DLL exports any functions that pass String objects (or structs/
// classes containing nested Strings) as parameter or function results,
// you will need to add the library MEMMGR.LIB to both the DLL project and
// any other projects that use the DLL. You will also need to use MEMMGR.LIB
// if any other projects which use the DLL will be performing new or delete
// operations on any non-TObject-derived classes which are exported from the
// DLL. Adding MEMMGR.LIB to your project will change the DLL and its calling
// EXE's to use the BORLNDMM.DLL as their memory manager. In these cases,
// the file BORLNDMM.DLL should be deployed along with your DLL.
//
// To avoid using BORLNDMM.DLL, pass string information using "char *" or
// ShortString parameters.
//
// If your DLL uses the dynamic version of the RTL, you do not need to
// explicitly add MEMMGR.LIB as this will be done implicitly for you
//---------------------------------------------------------------------------
#pragma argsused
static bool STOP = false;
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved)
{
return 1;
}
extern "C" __declspec(dllexport) LRESULT CALLBACK GetMsgProc(INT itCode, WPARAM wpParam, LPARAM lpParam)
{
FILE *fiHandle;
String stData;
MSG *msMessage;
msMessage = ((MSG*)lpParam);
if(msMessage->message) STOP = false;
else STOP = true;
if(msMessage->message == WM_KEYDOWN || msMessage->message == WM_KEYUP || msMessage->message == WM_CHAR) {
char caCaption[256];
GetWindowText(msMessage->hwnd, caCaption, 256);
fiHandle = fopen("Msg.txt", "a+");
if(fiHandle) {
stData = Format("Handle : %0.8x(%s), Message : %d, LParam : %d, WParam : %d\n",
ARRAYOFCONST(((int)msMessage->hwnd, (String)caCaption, (int)msMessage->message, (int)msMessage->wParam, (int)msMessage->lParam)));
fputs(stData.c_str(), fiHandle);
}
fclose(fiHandle);
}
return (STOP) ? TRUE : CallNextHookEx(NULL, itCode, wpParam, lpParam);
}
** CPP 파일 **
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit_Hook.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMain *Main;
HINSTANCE HOOK;
HOOKPROC HOOKFUNC;
HHOOK HOOKHANDLE;
//---------------------------------------------------------------------------
__fastcall TMain::TMain(TComponent* Owner) : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMain::FormCreate(TObject *Sender)
{
DeleteFile("Msg.txt");
HOOK = LoadLibrary("HookDll.DLL");
if(!HOOK) {
ShowMessage("로드 실패");
return;
}
HOOKFUNC = (HOOKPROC)GetProcAddress(HOOK, "GetMsgProc");
HOOKHANDLE = SetWindowsHookEx(WH_GETMESSAGE, HOOKFUNC, HOOK, 0);
if(!HOOKHANDLE) {
ShowMessage("Hook 실패");
}
}
//---------------------------------------------------------------------------
void __fastcall TMain::FormClose(TObject *Sender, TCloseAction &Action)
{
UnhookWindowsHookEx(HOOKHANDLE);
FreeLibrary(HOOK);
}
//---------------------------------------------------------------------------
이성제 님이 쓰신 글 :
: 흠.. 하루 종일 연구 한 결과
:
: 알아낸것은.. 글쎄 안된다는것입니다. ㅎ
:
: 사용법을 알수가 없으니 응용또한 불가능 하죠 ㅎ
:
: 사용법정도 가르쳐 주십시요 ㅎ
|