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

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

lx dll load fix (addref call missing)

File size: 5.2 KB
Line 
1/* $Id: windlllx.cpp,v 1.3 1999-10-21 12:18:47 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 *
12 * Project Odin Software License can be found in LICENSE.TXT
13 *
14 */
15#define INCL_DOSFILEMGR /* File Manager values */
16#define INCL_DOSERRORS /* DOS Error values */
17#define INCL_DOSPROCESS /* DOS Process values */
18#define INCL_DOSMODULEMGR
19#define INCL_DOSMISC /* DOS Miscellanous values */
20#define INCL_WIN
21#include <os2wrap.h> //Odin32 OS/2 api wrappers
22#include <stdio.h>
23#include <string.h>
24#include <stdlib.h>
25#include <iostream.h>
26#include <fstream.h>
27#include <misc.h>
28#include <win32type.h>
29#include <windllbase.h>
30#include <windlllx.h>
31#include <odinlx.h>
32#include "oslibmisc.h"
33
34//******************************************************************************
35//Create LX Dll object and send process attach message
36//System dlls set EntryPoint to 0
37//******************************************************************************
38BOOL WIN32API RegisterLxDll(HINSTANCE hInstance, WIN32DLLENTRY EntryPoint,
39 PVOID pResData)
40{
41 Win32LxDll *windll;
42
43 windll = (Win32LxDll *)Win32DllBase::findModule(hInstance);
44 if(windll) {
45 char *name = OSLibGetDllName(hInstance);
46 dprintf(("RegisterLxDll: Register existing dll %x %s", hInstance, name));
47 return FALSE;
48 }
49 windll = new Win32LxDll(hInstance, EntryPoint, pResData);
50 if(windll == NULL) {
51 dprintf(("RegisterLxDll: windll == NULL!!!"));
52 return FALSE;
53 }
54 windll->AddRef();
55 return windll->attachProcess();
56}
57//******************************************************************************
58//Destroy LX Dll object
59//******************************************************************************
60BOOL WIN32API UnregisterLxDll(HINSTANCE hInstance)
61{
62#if 1
63 return TRUE;
64#else
65 Win32LxDll *windll;
66
67 windll = (Win32LxDll *)Win32DllBase::findModule(hInstance);
68 if(!windll) {
69 dprintf(("UnregisterLxDll: Can't find dll with handle %x!!!", hInstance));
70 return FALSE;
71 }
72 windll->detachProcess();
73 delete windll;
74 return TRUE;
75#endif
76}
77//******************************************************************************
78//******************************************************************************
79Win32LxDll::Win32LxDll(HINSTANCE hInstance, WIN32DLLENTRY EntryPoint, PVOID pResData)
80 : Win32ImageBase(hInstance),
81 Win32LxImage(hInstance, pResData),
82 Win32DllBase(hInstance, EntryPoint)
83{
84 if(EntryPoint == NULL) {
85 fSkipEntryCalls = TRUE;
86 fAttachedToProcess = TRUE;
87 }
88}
89//******************************************************************************
90//******************************************************************************
91Win32LxDll::~Win32LxDll()
92{
93 dprintf(("Win32LxDll::~Win32LxDll %s", szModule));
94}
95//******************************************************************************
96//ASSUMPTION: called by FreeLibrary
97//******************************************************************************
98ULONG Win32LxDll::Release()
99{
100 ULONG ret = --referenced;
101
102 if(ret == 0) {
103 dprintf(("Win32LxDll::Release, referenced == 0\n"));
104 //DosFreeModule sends a termination message to the dll.
105 //The LX dll informs us when it's removed (UnregisterDll call)
106 DosFreeModule(hinstance);
107 }
108 return(ret);
109}
110//******************************************************************************
111//******************************************************************************
112ULONG Win32LxDll::getApi(char *name)
113{
114 APIRET rc;
115 ULONG apiaddr;
116
117 rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&apiaddr);
118 if(rc)
119 {
120 if(rc == ERROR_INVALID_HANDLE)
121 {//handle invalid for some silly reason, so load module again (initterm entrypoint not called twice)
122 char szErrName[CCHMAXPATH];
123
124 rc = DosLoadModule(szErrName, sizeof(szErrName), szFileName, &hinstance);
125 if(!rc)
126 rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&apiaddr);
127 }
128 if(rc) return(0);
129 }
130 return(apiaddr);
131}
132//******************************************************************************
133//******************************************************************************
134ULONG Win32LxDll::getApi(int ordinal)
135{
136 APIRET rc;
137 ULONG apiaddr;
138
139 rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&apiaddr);
140 if(rc) {
141 if(rc == ERROR_INVALID_HANDLE)
142 {//handle invalid for some silly reason, so load module again (initterm entrypoint not called twice)
143 char szErrName[CCHMAXPATH];
144
145 rc = DosLoadModule(szErrName, sizeof(szErrName), szFileName, &hinstance);
146 if(!rc)
147 rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&apiaddr);
148 }
149 if(rc) return(0);
150 }
151 return(apiaddr);
152}
153//******************************************************************************
154//******************************************************************************
155BOOL Win32LxDll::isLxDll()
156{
157 return TRUE;
158}
159//******************************************************************************
160//******************************************************************************
Note: See TracBrowser for help on using the repository browser.