source: trunk/src/user32/initterm.cpp@ 5280

Last change on this file since 5280 was 5135, checked in by sandervl, 25 years ago

VAC 3.6.5 bug workaround

File size: 5.2 KB
Line 
1/*
2 * USER32 DLL entry point
3 *
4 * Copyright 1998 Sander van Leeuwen
5 * Copyright 1998 Peter Fitzsimmons
6 *
7 *
8 * Project Odin Software License can be found in LICENSE.TXT
9 *
10 */
11
12/*-------------------------------------------------------------*/
13/* INITERM.C -- Source for a custom dynamic link library */
14/* initialization and termination (_DLL_InitTerm) */
15/* function. */
16/* */
17/* When called to perform initialization, this sample function */
18/* gets storage for an array of integers, and initializes its */
19/* elements with random integers. At termination time, it */
20/* frees the array. Substitute your own special processing. */
21/*-------------------------------------------------------------*/
22
23
24/* Include files */
25#define INCL_DOSMODULEMGR
26#define INCL_DOSPROCESS
27#define INCL_DOSSEMAPHORES
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 <misc.h> /*PLF Wed 98-03-18 23:18:29*/
34#include <win32type.h>
35#include <winconst.h>
36#include <odinlx.h>
37#include <spy.h>
38#include <monitor.h>
39#include "pmwindow.h"
40#include "win32wdesktop.h"
41#include "syscolor.h"
42#include "initterm.h"
43#include <exitlist.h>
44#include <initdll.h>
45
46#define DBG_LOCALLOG DBG_initterm
47#include "dbglocal.h"
48
49/*-------------------------------------------------------------------*/
50/* A clean up routine registered with DosExitList must be used if */
51/* runtime calls are required and the runtime is dynamically linked. */
52/* This will guarantee that this clean up routine is run before the */
53/* library DLL is terminated. */
54/*-------------------------------------------------------------------*/
55static void APIENTRY cleanup(ULONG reason);
56
57extern "C" {
58 //Win32 resource table (produced by wrc)
59 extern DWORD _Resource_PEResTab;
60}
61DWORD hInstanceUser32 = 0;
62
63/****************************************************************************/
64/* _DLL_InitTerm is the function that gets called by the operating system */
65/* loader when it loads and frees this DLL for each process that accesses */
66/* this DLL. However, it only gets called the first time the DLL is loaded */
67/* and the last time it is freed for a particular process. The system */
68/* linkage convention MUST be used because the operating system loader is */
69/* calling this function. */
70/****************************************************************************/
71unsigned long SYSTEM _DLL_InitTerm(unsigned long hModule, unsigned long
72 ulFlag)
73{
74 size_t i;
75 APIRET rc;
76
77 /*-------------------------------------------------------------------------*/
78 /* If ulFlag is zero then the DLL is being loaded so initialization should */
79 /* be performed. If ulFlag is 1 then the DLL is being freed so */
80 /* termination should be performed. */
81 /*-------------------------------------------------------------------------*/
82
83 switch (ulFlag) {
84 case 0 :
85 ctordtorInit();
86 ParseLogStatus();
87
88 CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed 98-03-18 05:28:48*/
89
90 hInstanceUser32 = RegisterLxDll(hModule, 0, (PVOID)&_Resource_PEResTab,
91 USER32_MAJORIMAGE_VERSION, USER32_MINORIMAGE_VERSION,
92 IMAGE_SUBSYSTEM_WINDOWS_GUI);
93 if(hInstanceUser32 == 0)
94 return 0UL;
95
96 /*******************************************************************/
97 /* A DosExitList routine must be used to clean up if runtime calls */
98 /* are required and the runtime is dynamically linked. */
99 /*******************************************************************/
100
101 rc = DosExitList(EXITLIST_USER32|EXLST_ADD, cleanup);
102 if(rc)
103 return 0UL;
104
105 //SvL: Try to start communication with our message spy queue server
106 InitSpyQueue();
107
108 //SvL: Init win32 PM classes
109 if(InitPM() == FALSE) {
110 return 0UL;
111 }
112
113 //SvL: 18-7-'98, Register system window classes (button, listbox etc etc)
114 //CB: register internal classes
115 RegisterSystemClasses(hModule);
116
117 //CB: initialize PM monitor driver
118 MONITOR_Initialize(&MONITOR_PrimaryMonitor);
119
120 break;
121 case 1 :
122 if(hInstanceUser32) {
123 UnregisterLxDll(hInstanceUser32);
124 }
125 break;
126 default :
127 return 0UL;
128 }
129
130 /***********************************************************/
131 /* A non-zero value must be returned to indicate success. */
132 /***********************************************************/
133 return 1UL;
134}
135
136static void APIENTRY cleanup(ULONG ulReason)
137{
138 dprintf(("user32 exit\n"));
139 DestroyDesktopWindow();
140 Win32BaseWindow::DestroyAll();
141 UnregisterSystemClasses();
142 Win32WndClass::DestroyAll();
143 MONITOR_Finalize(&MONITOR_PrimaryMonitor);
144 SYSCOLOR_Save();
145 CloseSpyQueue();
146 ctordtorTerm();
147 dprintf(("user32 exit done\n"));
148
149 DosExitList(EXLST_EXIT, cleanup);
150}
151
Note: See TracBrowser for help on using the repository browser.