source: trunk/src/kernel32/windlllx.cpp@ 2792

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

Fixed lx dll release method

File size: 4.2 KB
Line 
1/* $Id: windlllx.cpp,v 1.7 2000-02-15 14:37:43 sandervl Exp $ */
2
3/*
4 * Win32 LX Dll class (compiled in OS/2 using Odin32 api)
5 *
6 * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 *
9 * TODO: Unloading of dlls probably needs to be fixed due to OS/2 bug
10 * (wrong unload order of dlls)
11 * TODO: Unloading of system dlls is not correct for the PE loader
12 * (they're always put at the head of the list even though there
13 * might be a dependency with a win32 dll)
14 *
15 * Project Odin Software License can be found in LICENSE.TXT
16 *
17 */
18#define INCL_DOSFILEMGR /* File Manager values */
19#define INCL_DOSERRORS /* DOS Error values */
20#define INCL_DOSPROCESS /* DOS Process values */
21#define INCL_DOSMODULEMGR
22#define INCL_DOSMISC /* DOS Miscellanous values */
23#define INCL_WIN
24#include <os2wrap.h> //Odin32 OS/2 api wrappers
25#include <stdio.h>
26#include <string.h>
27#include <stdlib.h>
28#include <iostream.h>
29#include <fstream.h>
30#include <misc.h>
31#include <win32type.h>
32#include <windllbase.h>
33#include <windlllx.h>
34#include <odinlx.h>
35#include "oslibmisc.h"
36
37//******************************************************************************
38//Create LX Dll object and send process attach message
39//System dlls set EntryPoint to 0
40//Returns: Odin32 module handle
41//******************************************************************************
42DWORD WIN32API RegisterLxDll(HINSTANCE hInstance, WIN32DLLENTRY EntryPoint,
43 PVOID pResData)
44{
45 Win32LxDll *windll;
46
47 windll = (Win32LxDll *)Win32DllBase::findModule(hInstance);
48 if(windll) {
49 char *name = OSLibGetDllName(hInstance);
50 dprintf(("RegisterLxDll: Register existing dll %x %s", hInstance, name));
51 return FALSE;
52 }
53 windll = new Win32LxDll(hInstance, EntryPoint, pResData);
54 if(windll == NULL) {
55 dprintf(("RegisterLxDll: windll == NULL!!!"));
56 return FALSE;
57 }
58 windll->AddRef();
59 if(windll->attachProcess() == 0)
60 return 0;
61
62 return windll->getInstanceHandle();
63}
64//******************************************************************************
65//Destroy LX Dll object
66//******************************************************************************
67BOOL WIN32API UnregisterLxDll(HINSTANCE hInstance)
68{
69#if 1
70 return TRUE;
71#else
72 Win32LxDll *windll;
73
74 windll = (Win32LxDll *)Win32DllBase::findModule(hInstance);
75 if(!windll) {
76 dprintf(("UnregisterLxDll: Can't find dll with handle %x!!!", hInstance));
77 return FALSE;
78 }
79 windll->detachProcess();
80 delete windll;
81 return TRUE;
82#endif
83}
84//******************************************************************************
85//******************************************************************************
86Win32LxDll::Win32LxDll(HINSTANCE hInstance, WIN32DLLENTRY EntryPoint, PVOID pResData)
87 : Win32ImageBase(hInstance),
88 Win32LxImage(hInstance, pResData),
89 Win32DllBase(hInstance, EntryPoint)
90{
91 if(EntryPoint == NULL) {
92 fSkipEntryCalls = TRUE;
93 fAttachedToProcess = TRUE;
94 }
95}
96//******************************************************************************
97//******************************************************************************
98Win32LxDll::~Win32LxDll()
99{
100 dprintf(("Win32LxDll::~Win32LxDll %s", szModule));
101}
102//******************************************************************************
103//ASSUMPTION: called by FreeLibrary
104//******************************************************************************
105ULONG Win32LxDll::Release()
106{
107 ULONG ret = --referenced;
108 HINSTANCE hinst;
109
110 if(ret == 0) {
111 dprintf(("Win32LxDll::Release, referenced == 0\n"));
112 //DosFreeModule sends a termination message to the dll.
113 //The LX dll informs us when it's removed (UnregisterDll call)
114 hinst = hinstance;
115 delete this;
116 DosFreeModule(hinst);
117 }
118 return(ret);
119}
120//******************************************************************************
121//******************************************************************************
122BOOL Win32LxDll::isLxDll()
123{
124 return TRUE;
125}
126//******************************************************************************
127//******************************************************************************
Note: See TracBrowser for help on using the repository browser.