티스토리 뷰

IT/프로그래밍

DisableThreadLibraryCalls

NineKY 2010. 1. 18. 11:15
BOOL WINAPI DisableThreadLibraryCalls (
  __in  HMODULE hModule
);

오늘 이 함수를 처음봐서 간단히 노트를 한다.

[ Parameters ]

  hModule [in] A handle to the DLL module for which the DLL_THREAD_ATTACH and DLL_THREAD_DETACH notifications are to be disabled. The LoadLibrary, LoadLibraryEx, or GetModuleHandle function returns this handle. Note that you cannot call GetModuleHandle with NULL because this returns the base address of the executable image, not the DLL image.

이 함수를 호출하게되면 DLL_THREAD_ATTACH and DLL_THREAD_DETACH 알림이 Disable 된다는 말이다.
일반적인 DLL 파일에서는 로드 시점에 두 Notification 을 제공하는데,
이 DLL의 경우 더이상 메모리에 로드되어도 Notification이 없다는 말이다.


[ Return Value ]
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. The DisableThreadLibraryCalls function fails if the DLL specified by hModule has active static thread local storage, or if hModule is an invalid module handle. To get extended error information, call GetLastError.

[ Remarks ]
The DisableThreadLibraryCalls function lets a DLL disable the DLL_THREAD_ATTACH and DLL_THREAD_DETACH notification calls. This can be a useful optimization for multithreaded applications that have many DLLs, frequently create and delete threads, and whose DLLs do not need these thread-level notifications of attachment/detachment. A remote procedure call (RPC) server application is an example of such an application. In these sorts of applications, DLL initialization routines often remain in memory to service DLL_THREAD_ATTACH and DLL_THREAD_DETACH notifications. By disabling the notifications, the DLL initialization code is not paged in because a thread is created or deleted, thus reducing the size of the application's working code set. To implement the optimization, modify a DLL's DLL_PROCESS_ATTACH code to call DisableThreadLibraryCalls.

음... 내가 이해한 기능하고 설명하고 약간 다른 듯...

어떤 DLL 들은 로드(Load) 시점, 언로드(Unload) 시점에 특별한 작업을 해줘야 하는 경우가 있다.
이를 위해 있는 것이 DLL_THREAD_ATTACH 와 DLL_THREAD_DETAC Notification 이다.
특히, DLL_THREAD_ATTACH 의 경우 특정 프로세스에 DLL 이 로드되는 시점에 Notification이 발생하게 되는데,
여기에 초기화 관련 코드가 들어갈 수 있다.

그런데, 만약 다중으로 실행되어 DLL_THREAD_ATTACH 이 다중으로 호출될 경우 문제가 발생할 수 있는 경우에
이 함수를 이용할 수 있다.

즉, DLL_THARED_ATTACH 부분에 문제가 될만한 코드가 있는 경우에 중복 실행을 막기 위해 이용가능할 것 같다.

Do not call this function from a DLL that is linked to the static C run-time library (CRT). The static CRT requires DLL_THREAD_ATTACH and DLL_THREAD_DETATCH notifications to function properly.

'IT > 프로그래밍' 카테고리의 다른 글

[Python] INT32 값을 구하는 방법  (0) 2010.03.03
파이썬(Python) 디버깅(Debugging)  (0) 2010.02.25
PathRemoveArgs  (0) 2010.01.18
[Python] 파이썬의 기본 인코딩 문제  (0) 2010.01.13
[VB] DllFunctionCall  (0) 2009.12.18
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함