Changeset 3993 for trunk/src/kernel32/windlllx.cpp
- Timestamp:
- Aug 11, 2000, 12:56:27 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/windlllx.cpp
r3854 r3993 1 /* $Id: windlllx.cpp,v 1.1 1 2000-07-18 18:37:29sandervl Exp $ */1 /* $Id: windlllx.cpp,v 1.12 2000-08-11 10:56:18 sandervl Exp $ */ 2 2 3 3 /* … … 42 42 //Create LX Dll object and send process attach message 43 43 //System dlls set EntryPoint to 0 44 //Parameters: 45 // HINSTANCE hInstance - OS/2 module handle 46 // WIN32DLLENTRY EntryPoint - Win32 dll entrypoint address 47 // PVOID pResData - pointer to win32 resource data 48 // DWORD MajorImageVersion - major image/os version (for fake win32 header) 49 // DWORD MinorImageVersion - minor image/os version (for fake win32 header) 50 // DWORD Subsystem - subsystem type (for fake win32 header) 51 // (IMAGE_SUBSYSTEM_WINDOWS_CUI/IMAGE_SUBSYSTEM_WINDOWS_GUI) 52 // 44 53 //Returns: Odin32 module handle 45 54 //****************************************************************************** 46 55 DWORD WIN32API RegisterLxDll(HINSTANCE hInstance, WIN32DLLENTRY EntryPoint, 47 PVOID pResData) 48 { 49 Win32LxDll *windll; 56 PVOID pResData, 57 DWORD MajorImageVersion, 58 DWORD MinorImageVersion, 59 DWORD Subsystem) 60 { 61 APIRET rc; 62 Win32LxDll *windll; 50 63 Win32DllBase *windlldep; 51 52 windll = (Win32LxDll *)Win32DllBase::findModule(hInstance); 53 if(windll) { 54 char *name = OSLibGetDllName(hInstance); 55 dprintf(("RegisterLxDll: Register existing dll %x %s", hInstance, name)); 56 return FALSE; 57 } 58 windll = new Win32LxDll(hInstance, EntryPoint, pResData); 64 char szFileName[CCHMAXPATH], szErrName[CCHMAXPATH]; 65 66 if(OSLibGetDllName(hInstance, szFileName, sizeof(szFileName)) == FALSE) { 67 dprintf(("ERROR: RegisterLxDll: OSLibGetDllName %x failed!!", hInstance)); 68 return 0; 69 } 70 //Make sure DosLoadModule is called at least 71 //once for a dll (to make sure OS/2 doesn't unload the dll when it's 72 //still needed) 73 rc = DosLoadModule(szErrName, sizeof(szErrName), szFileName, &hInstance); 74 if(rc != 0) { 75 dprintf(("ERROR: RegisterLxDll: DosLoadModule %s failed (rc=%d)!!", szFileName, rc)); 76 return 0; 77 } 78 windll = new Win32LxDll(hInstance, EntryPoint, pResData, MajorImageVersion, 79 MinorImageVersion, Subsystem); 59 80 if(windll == NULL) { 60 81 dprintf(("RegisterLxDll: windll == NULL!!!")); 61 return FALSE;82 return 0; 62 83 } 63 84 if(!fPeLoader) { … … 74 95 char modulename[CCHMAXPATH]; 75 96 char modsize; 76 APIRET rc;77 97 int i; 78 98 … … 118 138 BOOL WIN32API UnregisterLxDll(HINSTANCE hInstance) 119 139 { 120 Win32 LxDll*windll;140 Win32DllBase *windll; 121 141 122 142 //Don't proceed for pe2lx/win32k (os/2 dll unload dependency bug) … … 125 145 return TRUE; 126 146 127 windll = (Win32LxDll *)Win32DllBase::findModule(hInstance);147 windll = Win32DllBase::findModule(hInstance); 128 148 if(!windll) { 129 149 dprintf(("UnregisterLxDll: Can't find dll with handle %x (already deleted)", hInstance)); … … 137 157 //****************************************************************************** 138 158 //****************************************************************************** 139 Win32LxDll::Win32LxDll(HINSTANCE hInstance, WIN32DLLENTRY EntryPoint, PVOID pResData) 159 Win32LxDll::Win32LxDll(HINSTANCE hInstance, WIN32DLLENTRY EntryPoint, PVOID pResData, 160 DWORD MajorImageVersion, DWORD MinorImageVersion, 161 DWORD Subsystem) 140 162 : Win32ImageBase(hInstance), 141 163 Win32LxImage(hInstance, pResData), … … 146 168 fAttachedToProcess = TRUE; 147 169 } 170 hinstanceOS2 = hInstance; 171 //new win32 instance handle must be pointer to PE header 172 hinstance = (HINSTANCE)buildHeader(MajorImageVersion, MinorImageVersion, 173 Subsystem); 148 174 } 149 175 //****************************************************************************** … … 151 177 Win32LxDll::~Win32LxDll() 152 178 { 153 }154 //******************************************************************************155 //Load it again so OS/2 takes care of the reference count (to make sure156 //a dll isn't unloaded when the win32 app still needs it)157 //******************************************************************************158 void Win32LxDll::loadLibrary()159 {160 char szModuleFailure[CCHMAXPATH] = "";161 ULONG hInstanceNewDll;162 APIRET rc;163 164 if(fLoadLibrary) {165 DebugInt3();166 return;167 }168 169 dprintf(("Win32LxDll::loadLibrary %s", getModuleName()));170 rc = DosLoadModule(szModuleFailure, sizeof(szModuleFailure), getFullPath(), (HMODULE *)&hInstanceNewDll);171 if(rc) {172 dprintf(("DosLoadModule returned %X for %s\n", rc, szModuleFailure));173 DebugInt3(); //should NEVER happen174 return;175 }176 //only do this once, so set the fLoadLibrary flag to true177 setLoadLibrary();178 179 } 179 180 //****************************************************************************** … … 227 228 ULONG ret; 228 229 APIRET rc; 229 BOOL fLoadLib = fLoadLibrary; 230 231 if(fDisableUnload) {//only set for kernel32.dll 232 fLoadLib = FALSE; 233 } 234 hinst = hinstance; 230 231 hinst = hinstanceOS2; 235 232 ret = Win32DllBase::Release(); 236 if(ret == 0 && fLoadLib) {233 if(ret == 0 && !fDisableUnload) {//only set for kernel32.dll (fDisableUnload) 237 234 //DosFreeModule sends a termination message to the dll. 238 235 //The LX dll informs us when it's removed (UnregisterDll call) … … 252 249 //****************************************************************************** 253 250 //****************************************************************************** 251 void Win32LxDll::setDllHandleOS2(HINSTANCE hInstanceOS2) 252 { 253 //Loaded with LoadLibrary(Ex); no need for a 2nd DosLoadModule 254 //Dlls that are indirectly loaded (i.e. GDI32->KERNEL32 dependancy) need 255 //this additional DosLoadModule (and setDllHandleOS2 isn't called for those) 256 if(this->hinstanceOS2) { 257 DosFreeModule(this->hinstanceOS2); 258 } 259 this->hinstanceOS2 = hInstanceOS2; 260 } 261 //****************************************************************************** 262 //****************************************************************************** 263 Win32LxDll *Win32LxDll::findModuleByOS2Handle(HINSTANCE hinstance) 264 { 265 dlllistmutex.enter(); 266 267 Win32LxDll *mod = (Win32LxDll*)Win32DllBase::head; 268 while(mod != NULL) { 269 dbgCheckObj(mod); 270 if(mod->isLxDll() && mod->hinstanceOS2 == hinstance) { 271 dlllistmutex.leave(); 272 return(mod); 273 } 274 mod = (Win32LxDll*)mod->next; 275 } 276 dlllistmutex.leave(); 277 return(NULL); 278 } 279 //****************************************************************************** 280 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.