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

Last change on this file since 2803 was 2649, checked in by sandervl, 26 years ago

Rewrote dll entrypoint

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