| 1 | /* $Id: initterm.cpp,v 1.19 2001-09-05 12:50:39 bird Exp $
|
|---|
| 2 | *
|
|---|
| 3 | * DLL entry point
|
|---|
| 4 | *
|
|---|
| 5 | * Copyright 1998 Sander van Leeuwen
|
|---|
| 6 | * Copyright 1998 Peter Fitzsimmons
|
|---|
| 7 | *
|
|---|
| 8 | *
|
|---|
| 9 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 10 | *
|
|---|
| 11 | */
|
|---|
| 12 |
|
|---|
| 13 | /*-------------------------------------------------------------*/
|
|---|
| 14 | /* INITERM.C -- Source for a custom dynamic link library */
|
|---|
| 15 | /* initialization and termination (_DLL_InitTerm) */
|
|---|
| 16 | /* function. */
|
|---|
| 17 | /* */
|
|---|
| 18 | /* When called to perform initialization, this sample function */
|
|---|
| 19 | /* gets storage for an array of integers, and initializes its */
|
|---|
| 20 | /* elements with random integers. At termination time, it */
|
|---|
| 21 | /* frees the array. Substitute your own special processing. */
|
|---|
| 22 | /*-------------------------------------------------------------*/
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 | /* Include files */
|
|---|
| 26 | #define INCL_DOSMODULEMGR
|
|---|
| 27 | #define INCL_DOSPROCESS
|
|---|
| 28 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
|---|
| 29 | #include <stdlib.h>
|
|---|
| 30 | #include <stdio.h>
|
|---|
| 31 | #include <string.h>
|
|---|
| 32 | #include <odin.h>
|
|---|
| 33 | #include <win32type.h>
|
|---|
| 34 | #include <winconst.h>
|
|---|
| 35 | #include <odinlx.h>
|
|---|
| 36 | #include <exitlist.h>
|
|---|
| 37 | #include <misc.h> /*PLF Wed 98-03-18 23:18:15*/
|
|---|
| 38 | #include <initdll.h>
|
|---|
| 39 | #include "os2fsdd.h" // For RestorePM()
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 | extern "C" {
|
|---|
| 43 | //Win32 resource table (produced by wrc)
|
|---|
| 44 | extern DWORD _Resource_PEResTab;
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | char ddrawPath[CCHMAXPATH] = "";
|
|---|
| 48 | static HMODULE dllHandle = 0;
|
|---|
| 49 |
|
|---|
| 50 | static void APIENTRY cleanup(ULONG ulReason);
|
|---|
| 51 |
|
|---|
| 52 | //******************************************************************************
|
|---|
| 53 | //******************************************************************************
|
|---|
| 54 | BOOL WINAPI LibMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
|
|---|
| 55 | {
|
|---|
| 56 | switch (fdwReason)
|
|---|
| 57 | {
|
|---|
| 58 | case DLL_PROCESS_ATTACH:
|
|---|
| 59 | return TRUE;
|
|---|
| 60 |
|
|---|
| 61 | case DLL_THREAD_ATTACH:
|
|---|
| 62 | case DLL_THREAD_DETACH:
|
|---|
| 63 | return TRUE;
|
|---|
| 64 |
|
|---|
| 65 | case DLL_PROCESS_DETACH:
|
|---|
| 66 | #ifdef __IBMCPP__
|
|---|
| 67 | ctordtorTerm();
|
|---|
| 68 | #endif
|
|---|
| 69 | return TRUE;
|
|---|
| 70 | }
|
|---|
| 71 | return FALSE;
|
|---|
| 72 | }
|
|---|
| 73 | /****************************************************************************/
|
|---|
| 74 | /* _DLL_InitTerm is the function that gets called by the operating system */
|
|---|
| 75 | /* loader when it loads and frees this DLL for each process that accesses */
|
|---|
| 76 | /* this DLL. However, it only gets called the first time the DLL is loaded */
|
|---|
| 77 | /* and the last time it is freed for a particular process. The system */
|
|---|
| 78 | /* linkage convention MUST be used because the operating system loader is */
|
|---|
| 79 | /* calling this function. */
|
|---|
| 80 | /****************************************************************************/
|
|---|
| 81 | unsigned long SYSTEM _DLL_InitTerm(unsigned long hModule, unsigned long
|
|---|
| 82 | ulFlag)
|
|---|
| 83 | {
|
|---|
| 84 |
|
|---|
| 85 | /*-------------------------------------------------------------------------*/
|
|---|
| 86 | /* If ulFlag is zero then the DLL is being loaded so initialization should */
|
|---|
| 87 | /* be performed. If ulFlag is 1 then the DLL is being freed so */
|
|---|
| 88 | /* termination should be performed. */
|
|---|
| 89 | /*-------------------------------------------------------------------------*/
|
|---|
| 90 |
|
|---|
| 91 | switch (ulFlag) {
|
|---|
| 92 | case 0 :
|
|---|
| 93 | {
|
|---|
| 94 | APIRET rc;
|
|---|
| 95 |
|
|---|
| 96 | #ifdef __IBMCPP__
|
|---|
| 97 | ctordtorInit();
|
|---|
| 98 | #endif
|
|---|
| 99 | DosQueryModuleName(hModule, CCHMAXPATH, ddrawPath);
|
|---|
| 100 | char *endofpath = strrchr(ddrawPath, '\\');
|
|---|
| 101 | if (endofpath)
|
|---|
| 102 | *(endofpath+1) = '\0';
|
|---|
| 103 |
|
|---|
| 104 | CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed 98-03-18 05:28:48*/
|
|---|
| 105 |
|
|---|
| 106 | dllHandle = RegisterLxDll(hModule, LibMain, (PVOID)&_Resource_PEResTab,
|
|---|
| 107 | DDRAW_MAJORIMAGE_VERSION, DDRAW_MINORIMAGE_VERSION,
|
|---|
| 108 | IMAGE_SUBSYSTEM_WINDOWS_GUI);
|
|---|
| 109 | if (dllHandle == 0)
|
|---|
| 110 | return 0UL;
|
|---|
| 111 |
|
|---|
| 112 | rc = DosExitList(EXITLIST_NONCOREDLL | EXLST_ADD, cleanup);
|
|---|
| 113 | if (rc)
|
|---|
| 114 | return 0UL;
|
|---|
| 115 |
|
|---|
| 116 | break;
|
|---|
| 117 | }
|
|---|
| 118 | case 1 :
|
|---|
| 119 | if(dllHandle) {
|
|---|
| 120 | UnregisterLxDll(dllHandle);
|
|---|
| 121 | }
|
|---|
| 122 | break;
|
|---|
| 123 | default :
|
|---|
| 124 | return 0UL;
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | /***********************************************************/
|
|---|
| 128 | /* A non-zero value must be returned to indicate success. */
|
|---|
| 129 | /***********************************************************/
|
|---|
| 130 | return 1UL;
|
|---|
| 131 | }
|
|---|
| 132 | //******************************************************************************
|
|---|
| 133 | //******************************************************************************
|
|---|
| 134 |
|
|---|
| 135 | static void APIENTRY cleanup(ULONG ulReason)
|
|---|
| 136 | {
|
|---|
| 137 | dprintf(("DDRAW processing exitlist"));
|
|---|
| 138 | RestorePM();
|
|---|
| 139 | dprintf(("DDRAW exitlist done"));
|
|---|
| 140 |
|
|---|
| 141 | DosExitList(EXLST_EXIT, cleanup);
|
|---|
| 142 | }
|
|---|
| 143 | //******************************************************************************
|
|---|
| 144 | //******************************************************************************
|
|---|