Posted By

kitoon on 03/04/08


Tagged

dll winapi


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

khouser


DllMain


 / Published in: C++
 

URL: http://www.coopknow.com/papers.asp?paper=5

A Windows 32-bit DLL does not require any special functions. If you want to initialize your DLL when it is loaded, you can have a function called DllMain and do your initialization, but it is not required. Windows calls the DllMain function of a DLL in four instances:

* When a process attaches the DLL
* When a thread attaches the DLL
* When a process detaches the DLL
* When a thrad detaches the DLL
  1. BOOL WINAPI DllMain(HINSTANCE hInstance,DWORD fwdReason, LPVOID lpvReserved)
  2. {
  3. switch(fwdReason)
  4. {
  5. case DLL_PROCESS_ATTACH:
  6. break;
  7. case DLL_THREAD_ATTACH:
  8. break;
  9. case DLL_PROCESS_DETACH:
  10. break;
  11. case DLL_THREAD_DETACH:
  12. break;
  13. }
  14. return(TRUE); // The initialization was successful, a FALSE will abort
  15. // the DLL attach
  16. }

Report this snippet  

You need to login to post a comment.