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

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

Rewrite for new win32 image classes

File size: 5.1 KB
Line 
1/* $Id: windlllx.cpp,v 1.1 1999-09-15 23:39:07 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, PVOID unused)
39{
40 Win32LxDll *windll;
41
42 windll = (Win32LxDll *)Win32DllBase::findModule(hInstance);
43 if(windll) {
44 char *name = OSLibGetDllName(hInstance);
45 dprintf(("RegisterLxDll: Register existing dll %x %s", hInstance, name));
46 return FALSE;
47 }
48 windll = new Win32LxDll(hInstance, EntryPoint);
49 if(windll == NULL) {
50 dprintf(("RegisterLxDll: windll == NULL!!!"));
51 return FALSE;
52 }
53 return windll->attachProcess();
54}
55//******************************************************************************
56//Destroy LX Dll object
57//******************************************************************************
58BOOL WIN32API UnregisterLxDll(HINSTANCE hInstance)
59{
60 Win32LxDll *windll;
61
62 windll = (Win32LxDll *)Win32DllBase::findModule(hInstance);
63 if(!windll) {
64 dprintf(("UnregisterLxDll: Can't find dll with handle %x!!!", hInstance));
65 return FALSE;
66 }
67 windll->detachProcess();
68 delete windll;
69 return TRUE;
70}
71//******************************************************************************
72//******************************************************************************
73Win32LxDll::Win32LxDll(HINSTANCE hInstance, WIN32DLLENTRY EntryPoint)
74 : Win32ImageBase(hInstance),
75 Win32LxImage(hInstance),
76 Win32DllBase(hInstance, EntryPoint)
77{
78 if(EntryPoint == NULL) {
79 fSkipEntryCalls = TRUE;
80 fAttachedToProcess = TRUE;
81 }
82}
83//******************************************************************************
84//******************************************************************************
85Win32LxDll::~Win32LxDll()
86{
87 dprintf(("Win32LxDll::~Win32LxDll %s", szModule));
88}
89//******************************************************************************
90//ASSUMPTION: called by FreeLibrary
91//******************************************************************************
92ULONG Win32LxDll::Release()
93{
94 ULONG ret = --referenced;
95
96 if(ret == 0) {
97 dprintf(("Win32LxDll::Release, referenced == 0\n"));
98 //DosFreeModule sends a termination message to the dll.
99 //The LX dll informs us when it's removed (UnregisterDll call)
100 DosFreeModule(hinstance);
101 }
102 return(ret);
103}
104//******************************************************************************
105//******************************************************************************
106ULONG Win32LxDll::getApi(char *name)
107{
108 APIRET rc;
109 ULONG apiaddr;
110
111 rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&apiaddr);
112 if(rc)
113 {
114 if(rc == ERROR_INVALID_HANDLE)
115 {//handle invalid for some silly reason, so load module again (initterm entrypoint not called twice)
116 char szErrName[CCHMAXPATH];
117
118 rc = DosLoadModule(szErrName, sizeof(szErrName), szFileName, &hinstance);
119 if(!rc)
120 rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&apiaddr);
121 }
122 if(rc) return(0);
123 }
124 return(apiaddr);
125}
126//******************************************************************************
127//******************************************************************************
128ULONG Win32LxDll::getApi(int ordinal)
129{
130 APIRET rc;
131 ULONG apiaddr;
132
133 rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&apiaddr);
134 if(rc) {
135 if(rc == ERROR_INVALID_HANDLE)
136 {//handle invalid for some silly reason, so load module again (initterm entrypoint not called twice)
137 char szErrName[CCHMAXPATH];
138
139 rc = DosLoadModule(szErrName, sizeof(szErrName), szFileName, &hinstance);
140 if(!rc)
141 rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&apiaddr);
142 }
143 if(rc) return(0);
144 }
145 return(apiaddr);
146}
147//******************************************************************************
148//******************************************************************************
149BOOL Win32LxDll::isLxDll()
150{
151 return TRUE;
152}
153//******************************************************************************
154//******************************************************************************
Note: See TracBrowser for help on using the repository browser.