| 1 | /* $Id: windlllx.cpp,v 1.6 1999-12-13 21:07:40 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 | //******************************************************************************
|
|---|
| 42 | DWORD 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 | //******************************************************************************
|
|---|
| 67 | BOOL 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 | //******************************************************************************
|
|---|
| 86 | Win32LxDll::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 | //******************************************************************************
|
|---|
| 98 | Win32LxDll::~Win32LxDll()
|
|---|
| 99 | {
|
|---|
| 100 | dprintf(("Win32LxDll::~Win32LxDll %s", szModule));
|
|---|
| 101 | }
|
|---|
| 102 | //******************************************************************************
|
|---|
| 103 | //ASSUMPTION: called by FreeLibrary
|
|---|
| 104 | //******************************************************************************
|
|---|
| 105 | ULONG Win32LxDll::Release()
|
|---|
| 106 | {
|
|---|
| 107 | ULONG ret = --referenced;
|
|---|
| 108 |
|
|---|
| 109 | if(ret == 0) {
|
|---|
| 110 | dprintf(("Win32LxDll::Release, referenced == 0\n"));
|
|---|
| 111 | //DosFreeModule sends a termination message to the dll.
|
|---|
| 112 | //The LX dll informs us when it's removed (UnregisterDll call)
|
|---|
| 113 | DosFreeModule(hinstance);
|
|---|
| 114 | }
|
|---|
| 115 | return(ret);
|
|---|
| 116 | }
|
|---|
| 117 | //******************************************************************************
|
|---|
| 118 | //******************************************************************************
|
|---|
| 119 | BOOL Win32LxDll::isLxDll()
|
|---|
| 120 | {
|
|---|
| 121 | return TRUE;
|
|---|
| 122 | }
|
|---|
| 123 | //******************************************************************************
|
|---|
| 124 | //******************************************************************************
|
|---|