OLD | NEW |
(Empty) | |
| 1 /** |
| 2 * \file abp_ca.cpp Top-level source for custom actions. Includes DLL initializa
tion. |
| 3 */ |
| 4 #include "DLL.h" |
| 5 #include <stdexcept> |
| 6 |
| 7 /** |
| 8 * DllMain is the standard entry point call when the DLL is loaded or unloaded. |
| 9 * |
| 10 * \param[in] module_handle |
| 11 * Handle for this instance of the DLL; same as the module handle. |
| 12 * This handle allows us to get the DLL file name for logging. |
| 13 * \param[in] reason |
| 14 * The point in the DLL life cycle at which this call is made. Called "reason
code" by Microsoft. |
| 15 * \param[in] reserved |
| 16 * No longer reserved, since it contains a point in the thread life cycle. |
| 17 * We aren't using it, though. |
| 18 |
| 19 * \sa { http://msdn.microsoft.com/en-us/library/windows/desktop/ms682583%28v=vs
.85%29.aspx } |
| 20 * Documentation on DLL entry points in Windows. |
| 21 */ |
| 22 extern "C" BOOL WINAPI DllMain( |
| 23 IN HINSTANCE module_handle, |
| 24 IN ULONG reason, |
| 25 IN LPVOID reserved ) |
| 26 { |
| 27 /* |
| 28 * Because this is an external API, we must ensure that there is a catch-all b
lock for each execution path. There are two of these below. |
| 29 */ |
| 30 switch ( reason ) |
| 31 { |
| 32 case DLL_PROCESS_ATTACH: |
| 33 try |
| 34 { |
| 35 DLL_Module::attach( module_handle ); |
| 36 return TRUE; |
| 37 } |
| 38 catch(...) |
| 39 { |
| 40 // We can't log to the installation log yet, and this couldn't shouldn't b
e executed except in rare cases such as out-of-memory. |
| 41 // Since it's a lot of code to do something useful (such as logging to the
Windows system event log), we don't do anything but return a failure. |
| 42 return FALSE; |
| 43 } |
| 44 break; |
| 45 |
| 46 case DLL_PROCESS_DETACH: |
| 47 try |
| 48 { |
| 49 DLL_Module::detach(); |
| 50 return TRUE; |
| 51 } |
| 52 catch(...) |
| 53 { |
| 54 // See comment above in parallel catch-block. |
| 55 return FALSE; |
| 56 } |
| 57 break; |
| 58 |
| 59 /* |
| 60 * This entry point is called for each thread after the first in a process wit
h this DLL loaded. Note "after the first". |
| 61 * The process life cycle is always called, and we do our global initializatio
n there. So even though this DLL |
| 62 * doesn't support asynchronous operation, this entry point gets called anyway
. We need to ignore these calls. |
| 63 */ |
| 64 case DLL_THREAD_ATTACH: |
| 65 case DLL_THREAD_DETACH: |
| 66 return TRUE; |
| 67 |
| 68 default: |
| 69 return FALSE; |
| 70 } |
| 71 } |
OLD | NEW |