source: trunk/src/imm32/initterm.cpp

Last change on this file was 21978, checked in by dmik, 14 years ago

imm32: Initialize kernel32 on DLL init.

IM32Init may trigger using of the shared memory through
the use of critical sections (in the debug version) so it
should be already initialized by that time.

This fixes loading of javac.exe which turns to import IMM32 before
KERNEL32.

File size: 1.8 KB
Line 
1/*
2 * IMM32OS2 DLL entry point
3 *
4 * Copyright 1998 Sander van Leeuwen
5 * Copyright 1998 Peter Fitzsimmons
6 *
7 * Project Odin Software License can be found in LICENSE.TXT
8 */
9
10#define INCL_DOSMODULEMGR
11#define INCL_DOSPROCESS
12#include <os2wrap.h> //Odin32 OS/2 api wrappers
13#include <stdlib.h>
14#include <stdio.h>
15#include <string.h>
16#include <odin.h>
17#include <win32type.h>
18#include <winconst.h>
19#include <odinlx.h>
20#include <initdll.h>
21#include <exitlist.h>
22#include <dbglog.h>
23
24#include "im32.h"
25
26// Win32 resource table (produced by wrc)
27extern DWORD imm32os2_PEResTab;
28
29static HMODULE dllHandle = 0;
30
31BOOL WINAPI ImmLibMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
32{
33 switch (fdwReason)
34 {
35 case DLL_PROCESS_ATTACH:
36 return TRUE;
37
38 case DLL_THREAD_ATTACH:
39 case DLL_THREAD_DETACH:
40 return TRUE;
41
42 case DLL_PROCESS_DETACH:
43 return TRUE;
44 }
45 return FALSE;
46}
47
48ULONG SYSTEM DLL_InitImm32(ULONG hModule)
49{
50 if (!InitializeKernel32())
51 return -1;
52
53 if (!IM32Init())
54 dprintf(("IM32Init failed"));
55
56 CheckVersionFromHMOD(PE2LX_VERSION, hModule);
57 dllHandle = RegisterLxDll(hModule, ImmLibMain, (PVOID)&imm32os2_PEResTab,
58 IMM32_MAJORIMAGE_VERSION, IMM32_MINORIMAGE_VERSION,
59 IMAGE_SUBSYSTEM_WINDOWS_GUI);
60 if (dllHandle == 0)
61 return -1;
62
63 dprintf(("imm32 init %s %s (%x)", __DATE__, __TIME__, DLL_InitImm32));
64
65 return EXITLIST_NONCRITDLL;
66}
67
68void SYSTEM DLL_TermImm32(ULONG hModule)
69{
70 dprintf(("imm32 exit"));
71
72 if(dllHandle)
73 UnregisterLxDll(dllHandle);
74}
75
76ULONG SYSTEM DLL_Init(ULONG hModule)
77{
78 if (DLL_InitDefault(hModule) == -1)
79 return -1;
80 return DLL_InitImm32(hModule);
81}
82
83void SYSTEM DLL_Term(ULONG hModule)
84{
85 DLL_TermImm32(hModule);
86 DLL_TermDefault(hModule);
87}
Note: See TracBrowser for help on using the repository browser.