source: trunk/src/kernel32/windllpe2lx.cpp@ 956

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

Rewrite for new win32 image classes

File size: 4.9 KB
Line 
1/* $Id: windllpe2lx.cpp,v 1.1 1999-09-15 23:39:07 sandervl Exp $ */
2
3/*
4 * Win32 PE2LX Dll class
5 *
6 * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12#define INCL_DOSFILEMGR /* File Manager values */
13#define INCL_DOSERRORS /* DOS Error values */
14#define INCL_DOSPROCESS /* DOS Process values */
15#define INCL_DOSMODULEMGR
16#define INCL_DOSMISC /* DOS Miscellanous values */
17#define INCL_WIN
18#include <os2wrap.h> //Odin32 OS/2 api wrappers
19#include <stdio.h>
20#include <string.h>
21#include <stdlib.h>
22#include <iostream.h>
23#include <fstream.h>
24#include <misc.h>
25#include <win32type.h>
26#include <pefile.h>
27#include <windllpe2lx.h>
28#include <wprocess.h>
29#include "cio.h"
30#include "oslibmisc.h"
31#include "oslibdos.h"
32
33#include "conwin.h" // Windows Header for console only
34#include "console.h"
35
36//******************************************************************************
37//******************************************************************************
38ULONG WIN32API RegisterPe2LxDll(WIN32DLLENTRY pfnDllEntry, PIMAGE_TLS_CALLBACK *TlsCallbackAddr,
39 LPDWORD TlsIndexAddr, ULONG TlsInitSize,
40 ULONG TlsTotalSize, LPVOID TlsAddress,
41 LONG Win32TableId, LONG NameTableId, LONG VersionResId,
42 LONG Pe2lxVersion, HINSTANCE hinstance, ULONG dwAttachType)
43{
44 char *name;
45
46 Win32Pe2LxDll *winmod = (Win32Pe2LxDll *)Win32DllBase::findModule(hinstance);
47 if(dwAttachType == 0)
48 { //Process attach
49 if(getenv("WIN32_IOPL2")) {
50 io_init1();
51 }
52 name = OSLibGetDllName(hinstance);
53 CheckVersion(Pe2lxVersion, name);
54
55 dprintf(("RegisterDll %X %s reason %d\n", hinstance, name, dwAttachType));
56 dprintf(("RegisterDll Win32TableId = %x", Win32TableId));
57 dprintf(("RegisterDll NameTableId = %x", NameTableId));
58 dprintf(("RegisterDll VersionResId = %x", VersionResId));
59 dprintf(("RegisterDll Pe2lxVersion = %x", Pe2lxVersion));
60
61 //converted win32 dll loaded by OS/2 loader
62 winmod = new Win32Pe2LxDll(hinstance, NameTableId, Win32TableId, pfnDllEntry);
63 if(winmod == NULL) {
64 eprintf(("Failed to allocate module object!\n"));
65 DebugInt3();
66 return 0; //fail dll load
67 }
68 winmod->setTLSAddress(TlsAddress);
69 winmod->setTLSInitSize(TlsInitSize);
70 winmod->setTLSTotalSize(TlsTotalSize);
71 winmod->setTLSIndexAddr(TlsIndexAddr);
72 winmod->setTLSCallBackAddr(TlsCallbackAddr);
73
74 /* @@@PH 1998/03/17 console devices initialization */
75 iConsoleDevicesRegister();
76
77 //SvL: 19-8-'98
78 winmod->AddRef();
79 winmod->setVersionId(VersionResId);
80
81 winmod->attachProcess();
82 }
83 else {//process detach
84 if(winmod != NULL && !fFreeLibrary) {
85 return 0; //don't unload (OS/2 dll unload bug)
86 }
87 //Runtime environment could already be gone, so don't do this
88 // dprintf(("KERNEL32: Dll Removed by FreeLibrary or ExitProcess\n"));
89 }
90 return 1; //success
91}
92//******************************************************************************
93//******************************************************************************
94Win32Pe2LxDll::Win32Pe2LxDll(HINSTANCE hinstance, int NameTableId, int Win32TableId,
95 WIN32DLLENTRY DllEntryPoint) :
96 Win32ImageBase(hinstance),
97 Win32DllBase(hinstance, DllEntryPoint),
98 Win32Pe2LxImage(hinstance, NameTableId, Win32TableId)
99{
100 dprintf(("Win32Pe2LxDll::Win32Pe2LxDll %s", szModule));
101}
102//******************************************************************************
103//******************************************************************************
104Win32Pe2LxDll::~Win32Pe2LxDll()
105{
106 dprintf(("Win32Pe2LxDll::~Win32Pe2LxDll %s", szModule));
107}
108//******************************************************************************
109//******************************************************************************
110ULONG Win32Pe2LxDll::getApi(char *name)
111{
112 APIRET rc;
113 ULONG apiaddr;
114
115 rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&apiaddr);
116 if(rc)
117 {
118 return(0);
119 }
120 return(apiaddr);
121}
122//******************************************************************************
123//******************************************************************************
124ULONG Win32Pe2LxDll::getApi(int ordinal)
125{
126 APIRET rc;
127 ULONG apiaddr;
128
129 rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&apiaddr);
130 if(rc) return(0);
131 else return(apiaddr);
132}
133//******************************************************************************
134//******************************************************************************
135BOOL Win32Pe2LxDll::isLxDll()
136{
137 return FALSE;
138}
139//******************************************************************************
140//******************************************************************************
Note: See TracBrowser for help on using the repository browser.