Windows는 아래 4가지 상황에서 DllMain 함수를 호출함.
1. 프로세스가 DLL에 접근
2. 쓰레드가 DLL에 접근
3. 쓰레드가 DLL에서 떨어져 나감(-_-)
4. 프로세스가 DLL에서 떨어져 나감
델파이에서는 DLL의 entry point가 호출될 때 사용하는 DLLProc이라는 특수 프로시져가 존재.
파라메터는 integer값 하나 (호출이유: attach, detach)
procedure DllMain(dwReason: DWORD);
begin
case dwReason of
// process attaches = 1
DLL_PROCESS_ATTACH: begin
OutputDebugString('Process Attach!');
end;
// thread attaches = 2
DLL_THREAD_ATTACH: begin
OutputDebugString('Thread Attach');
end;
// thread detaches = 3
DLL_THREAD_DETACH: begin
OutputDebugString('Thread Detach');
end;
// process detaches = 0
DLL_PROCESS_DETACH: begin
OutputDebugString('Detach!');
end;
end;
end;
begin
DLLProc:=@DllMain;
DLLProc(DLL_PROCESS_ATTACH);
end.
begin
case dwReason of
// process attaches = 1
DLL_PROCESS_ATTACH: begin
OutputDebugString('Process Attach!');
end;
// thread attaches = 2
DLL_THREAD_ATTACH: begin
OutputDebugString('Thread Attach');
end;
// thread detaches = 3
DLL_THREAD_DETACH: begin
OutputDebugString('Thread Detach');
end;
// process detaches = 0
DLL_PROCESS_DETACH: begin
OutputDebugString('Detach!');
end;
end;
end;
begin
DLLProc:=@DllMain;
DLLProc(DLL_PROCESS_ATTACH);
end.
'Delphi' 카테고리의 다른 글
[Delphi] 프로세스 실행시킨 후 해당 프로세스 종료시 같이 종료하기 (0) | 2010.04.26 |
---|---|
[Delphi] 프로세스ID로 핸들, ThreadID 알아내기 (0) | 2010.04.26 |
[Delphi] 특정 프로세스 키보드 후킹 (2) | 2010.04.22 |
랜덤 문자열 생성 (0) | 2009.10.10 |
[Delphi] PuTTY의 마지막 라인 가져오기 (0) | 2009.09.05 |