| 1 | /* $Id: dllmain-win.cpp 3609 2007-10-29 01:11:39Z bird $ */ | 
|---|
| 2 | /** @file | 
|---|
| 3 | * kProfiler Mark 2 - The Windows DllMain for the profiler DLL. | 
|---|
| 4 | */ | 
|---|
| 5 |  | 
|---|
| 6 | /* | 
|---|
| 7 | * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net> | 
|---|
| 8 | * | 
|---|
| 9 | * This file is part of kProfile. | 
|---|
| 10 | * | 
|---|
| 11 | * kProfile is free software; you can redistribute it and/or | 
|---|
| 12 | * modify it under the terms of the GNU Lesser General Public | 
|---|
| 13 | * License as published by the Free Software Foundation; either | 
|---|
| 14 | * version 2.1 of the License, or (at your option) any later version. | 
|---|
| 15 | * | 
|---|
| 16 | * kProfile is distributed in the hope that it will be useful, | 
|---|
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
|---|
| 19 | * Lesser General Public License for more details. | 
|---|
| 20 | * | 
|---|
| 21 | * You should have received a copy of the GNU Lesser General Public | 
|---|
| 22 | * License along with kProfile; if not, write to the Free Software | 
|---|
| 23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA | 
|---|
| 24 | * | 
|---|
| 25 | */ | 
|---|
| 26 |  | 
|---|
| 27 |  | 
|---|
| 28 | /******************************************************************************* | 
|---|
| 29 | *   Header Files                                                               * | 
|---|
| 30 | *******************************************************************************/ | 
|---|
| 31 | #include <Windows.h> | 
|---|
| 32 | #include "kProfileR3.h" | 
|---|
| 33 |  | 
|---|
| 34 |  | 
|---|
| 35 | /** | 
|---|
| 36 | * The DLL Main for the kPrf DLL. | 
|---|
| 37 | * | 
|---|
| 38 | * This is required because we need to initialize the profiler at some point | 
|---|
| 39 | * and because we need to know when threads terminate. (We don't care about | 
|---|
| 40 | * when threads get created, we simply pick them up when we see them the | 
|---|
| 41 | * first time.) | 
|---|
| 42 | * | 
|---|
| 43 | * @returns Success indicator. | 
|---|
| 44 | * @param   hInstDll        The instance handle of the DLL. (i.e. the module handle) | 
|---|
| 45 | * @param   fdwReason       The reason why we're here. This is a 'flag' for reasons of | 
|---|
| 46 | *                          tradition, it's really a kind of enum. | 
|---|
| 47 | * @param   pReserved       Reserved / undocumented something. | 
|---|
| 48 | */ | 
|---|
| 49 | BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, PVOID pReserved) | 
|---|
| 50 | { | 
|---|
| 51 | switch (fdwReason) | 
|---|
| 52 | { | 
|---|
| 53 | case DLL_PROCESS_ATTACH: | 
|---|
| 54 | if (kPrfInitialize()) | 
|---|
| 55 | return FALSE; | 
|---|
| 56 | break; | 
|---|
| 57 |  | 
|---|
| 58 | case DLL_PROCESS_DETACH: | 
|---|
| 59 | kPrfTerminate(); | 
|---|
| 60 | break; | 
|---|
| 61 |  | 
|---|
| 62 | case DLL_THREAD_ATTACH: | 
|---|
| 63 | break; | 
|---|
| 64 |  | 
|---|
| 65 | case DLL_THREAD_DETACH: | 
|---|
| 66 | kPrfTerminateThread(); | 
|---|
| 67 | break; | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|
| 70 | return TRUE; | 
|---|
| 71 | } | 
|---|
| 72 |  | 
|---|