| 1 | /* $Id: wprocess.cpp,v 1.53 1999-11-30 19:40:27 sandervl Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * Win32 process functions
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
|
|---|
| 7 | *
|
|---|
| 8 | *
|
|---|
| 9 | * NOTE: Even though Odin32 OS/2 apps don't switch FS selectors,
|
|---|
| 10 | * we still allocate a TEB to store misc information.
|
|---|
| 11 | *
|
|---|
| 12 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 13 | *
|
|---|
| 14 | */
|
|---|
| 15 | #include <odin.h>
|
|---|
| 16 | #include <odinwrap.h>
|
|---|
| 17 | #include <os2win.h>
|
|---|
| 18 | #include <stdio.h>
|
|---|
| 19 | #include <stdlib.h>
|
|---|
| 20 | #include <string.h>
|
|---|
| 21 |
|
|---|
| 22 | #include <unicode.h>
|
|---|
| 23 | #include <windllbase.h>
|
|---|
| 24 | #include <winexebase.h>
|
|---|
| 25 | #include <windllpeldr.h>
|
|---|
| 26 | #include <winfakepeldr.h>
|
|---|
| 27 |
|
|---|
| 28 | #ifdef __IBMCPP__
|
|---|
| 29 | #include <builtin.h>
|
|---|
| 30 | #endif
|
|---|
| 31 |
|
|---|
| 32 | #include "exceptutil.h"
|
|---|
| 33 | #include "oslibmisc.h"
|
|---|
| 34 |
|
|---|
| 35 | #include "console.h"
|
|---|
| 36 | #include "cio.h"
|
|---|
| 37 | #include "versionos2.h" /*PLF Wed 98-03-18 02:36:51*/
|
|---|
| 38 | #include <wprocess.h>
|
|---|
| 39 | #include "mmap.h"
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 | ODINDEBUGCHANNEL(KERNEL32-WPROCESS)
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 | //******************************************************************************
|
|---|
| 46 | //******************************************************************************
|
|---|
| 47 | BOOL fFreeLibrary = FALSE;
|
|---|
| 48 | BOOL fIsOS2Image = FALSE; //TRUE -> Odin32 OS/2 application (not converted!)
|
|---|
| 49 | //FALSE -> otherwise
|
|---|
| 50 | //Process database
|
|---|
| 51 | PDB ProcessPDB = {0};
|
|---|
| 52 | USHORT ProcessTIBSel = 0;
|
|---|
| 53 | DWORD *TIBFlatPtr = 0;
|
|---|
| 54 |
|
|---|
| 55 | //******************************************************************************
|
|---|
| 56 | //******************************************************************************
|
|---|
| 57 | TEB *WIN32API GetThreadTEB()
|
|---|
| 58 | {
|
|---|
| 59 | if(TIBFlatPtr == NULL)
|
|---|
| 60 | return 0;
|
|---|
| 61 |
|
|---|
| 62 | return (TEB *)*TIBFlatPtr;
|
|---|
| 63 | }
|
|---|
| 64 | //******************************************************************************
|
|---|
| 65 | //******************************************************************************
|
|---|
| 66 | THDB *WIN32API GetThreadTHDB()
|
|---|
| 67 | {
|
|---|
| 68 | TEB *winteb;
|
|---|
| 69 | THDB *thdb;
|
|---|
| 70 |
|
|---|
| 71 | if(TIBFlatPtr == NULL)
|
|---|
| 72 | return 0;
|
|---|
| 73 |
|
|---|
| 74 | winteb = (TEB *)*TIBFlatPtr;
|
|---|
| 75 | if(winteb == NULL) {
|
|---|
| 76 | return NULL;
|
|---|
| 77 | }
|
|---|
| 78 | thdb = (THDB *)(winteb+1);
|
|---|
| 79 |
|
|---|
| 80 | return thdb;
|
|---|
| 81 | }
|
|---|
| 82 | //******************************************************************************
|
|---|
| 83 | // Set up the TIB selector and memory for the current thread
|
|---|
| 84 | //******************************************************************************
|
|---|
| 85 | TEB *InitializeTIB(BOOL fMainThread)
|
|---|
| 86 | {
|
|---|
| 87 | TEB *winteb;
|
|---|
| 88 | THDB *thdb;
|
|---|
| 89 |
|
|---|
| 90 | USHORT tibsel;
|
|---|
| 91 |
|
|---|
| 92 | //Allocate one dword to store the flat address of our TEB
|
|---|
| 93 | if(fMainThread) {
|
|---|
| 94 | TIBFlatPtr = (DWORD *)OSLibAllocThreadLocalMemory(1);
|
|---|
| 95 | if(TIBFlatPtr == 0) {
|
|---|
| 96 | dprintf(("InitializeTIB: local thread memory alloc failed!!"));
|
|---|
| 97 | DebugInt3();
|
|---|
| 98 | return NULL;
|
|---|
| 99 | }
|
|---|
| 100 | }
|
|---|
| 101 | if(OSLibAllocSel(PAGE_SIZE, &tibsel) == FALSE)
|
|---|
| 102 | {
|
|---|
| 103 | dprintf(("InitializeTIB: selector alloc failed!!"));
|
|---|
| 104 | DebugInt3();
|
|---|
| 105 | return NULL;
|
|---|
| 106 | }
|
|---|
| 107 | winteb = (TEB *)OSLibSelToFlat(tibsel);
|
|---|
| 108 | if(winteb == NULL)
|
|---|
| 109 | {
|
|---|
| 110 | dprintf(("InitializeTIB: DosSelToFlat failed!!"));
|
|---|
| 111 | DebugInt3();
|
|---|
| 112 | return NULL;
|
|---|
| 113 | }
|
|---|
| 114 | memset(winteb, 0, PAGE_SIZE);
|
|---|
| 115 | thdb = (THDB *)(winteb+1);
|
|---|
| 116 | *TIBFlatPtr = (DWORD)winteb;
|
|---|
| 117 |
|
|---|
| 118 | winteb->except = (PVOID)-1; /* 00 Head of exception handling chain */
|
|---|
| 119 | winteb->stack_top = (PVOID)OSLibGetTIB(TIB_STACKTOP); /* 04 Top of thread stack */
|
|---|
| 120 | winteb->stack_low = (PVOID)OSLibGetTIB(TIB_STACKLOW); /* 08 Stack low-water mark */
|
|---|
| 121 | winteb->htask16 = (USHORT)OSLibGetPIB(PIB_TASKHNDL); /* 0c Win16 task handle */
|
|---|
| 122 | winteb->stack_sel = getSS(); /* 0e 16-bit stack selector */
|
|---|
| 123 | winteb->self = winteb; /* 18 Pointer to this structure */
|
|---|
| 124 | winteb->flags = TEBF_WIN32; /* 1c Flags */
|
|---|
| 125 | winteb->queue = 0; /* 28 Message queue */
|
|---|
| 126 | winteb->tls_ptr = &thdb->tls_array[0]; /* 2c Pointer to TLS array */
|
|---|
| 127 | winteb->process = &ProcessPDB; /* 30 owning process (used by NT3.51 applets)*/
|
|---|
| 128 |
|
|---|
| 129 | memcpy(&thdb->teb, winteb, sizeof(TEB));
|
|---|
| 130 | thdb->process = &ProcessPDB;
|
|---|
| 131 | thdb->exit_code = 0x103; /* STILL_ACTIVE */
|
|---|
| 132 | thdb->teb_sel = tibsel;
|
|---|
| 133 | thdb->OrgTIBSel = GetFS();
|
|---|
| 134 | thdb->pWsockData = NULL;
|
|---|
| 135 |
|
|---|
| 136 | if(OSLibGetPIB(PIB_TASKTYPE) == TASKTYPE_PM)
|
|---|
| 137 | {
|
|---|
| 138 | thdb->flags = 0; //todo gui
|
|---|
| 139 | }
|
|---|
| 140 | else thdb->flags = 0; //todo textmode
|
|---|
| 141 |
|
|---|
| 142 | if(fMainThread)
|
|---|
| 143 | {
|
|---|
| 144 | //todo initialize PDB during process creation
|
|---|
| 145 | //todo: initialize TLS array if required
|
|---|
| 146 | //TLS in executable always TLS index 0?
|
|---|
| 147 | ProcessTIBSel = tibsel;
|
|---|
| 148 | ProcessPDB.exit_code = 0x103; /* STILL_ACTIVE */
|
|---|
| 149 | ProcessPDB.threads = 1;
|
|---|
| 150 | ProcessPDB.running_threads = 1;
|
|---|
| 151 | ProcessPDB.ring0_threads = 1;
|
|---|
| 152 | ProcessPDB.system_heap = GetProcessHeap();
|
|---|
| 153 | ProcessPDB.parent = 0;
|
|---|
| 154 | ProcessPDB.group = &ProcessPDB;
|
|---|
| 155 | ProcessPDB.priority = 8; /* Normal */
|
|---|
| 156 | ProcessPDB.heap = ProcessPDB.system_heap; /* will be changed later on */
|
|---|
| 157 | ProcessPDB.next = NULL;
|
|---|
| 158 | ProcessPDB.winver = 0xffff; /* to be determined */
|
|---|
| 159 | ProcessPDB.server_pid = (void *)GetCurrentProcessId();
|
|---|
| 160 |
|
|---|
| 161 | /* Initialize the critical section */
|
|---|
| 162 | InitializeCriticalSection( &ProcessPDB.crit_section );
|
|---|
| 163 | }
|
|---|
| 164 | dprintf(("InitializeTIB setup TEB with selector %x", tibsel));
|
|---|
| 165 | dprintf(("InitializeTIB: FS(%x):[0] = %x", GetFS(), QueryExceptionChain()));
|
|---|
| 166 | return winteb;
|
|---|
| 167 | }
|
|---|
| 168 | //******************************************************************************
|
|---|
| 169 | // Destroy the TIB selector and memory for the current thread
|
|---|
| 170 | //******************************************************************************
|
|---|
| 171 | void DestroyTIB()
|
|---|
| 172 | {
|
|---|
| 173 | SHORT orgtibsel;
|
|---|
| 174 | TEB *winteb;
|
|---|
| 175 | THDB *thdb;
|
|---|
| 176 |
|
|---|
| 177 | dprintf(("DestroyTIB: FS = %x", GetFS()));
|
|---|
| 178 | dprintf(("DestroyTIB: FS:[0] = %x", QueryExceptionChain()));
|
|---|
| 179 |
|
|---|
| 180 | winteb = (TEB *)*TIBFlatPtr;
|
|---|
| 181 | if(winteb) {
|
|---|
| 182 | thdb = (THDB *)(winteb+1);
|
|---|
| 183 | orgtibsel = thdb->OrgTIBSel;
|
|---|
| 184 |
|
|---|
| 185 | //Restore our original FS selector
|
|---|
| 186 | SetFS(orgtibsel);
|
|---|
| 187 |
|
|---|
| 188 | //And free our own
|
|---|
| 189 | OSLibFreeSel(thdb->teb_sel);
|
|---|
| 190 | }
|
|---|
| 191 | else dprintf(("Already destroyed TIB"));
|
|---|
| 192 |
|
|---|
| 193 | dprintf(("DestroyTIB: FS(%x):[0] = %x", GetFS(), QueryExceptionChain()));
|
|---|
| 194 | *TIBFlatPtr = 0;
|
|---|
| 195 | return;
|
|---|
| 196 | }
|
|---|
| 197 | /******************************************************************************/
|
|---|
| 198 | /******************************************************************************/
|
|---|
| 199 | void SetPDBInstance(HINSTANCE hInstance)
|
|---|
| 200 | {
|
|---|
| 201 | ProcessPDB.hInstance = hInstance;
|
|---|
| 202 | }
|
|---|
| 203 | /******************************************************************************/
|
|---|
| 204 | /******************************************************************************/
|
|---|
| 205 | void WIN32API RestoreOS2TIB()
|
|---|
| 206 | {
|
|---|
| 207 | SHORT orgtibsel;
|
|---|
| 208 | TEB *winteb;
|
|---|
| 209 | THDB *thdb;
|
|---|
| 210 |
|
|---|
| 211 | //If we're running an Odin32 OS/2 application (not converted!), then we
|
|---|
| 212 | //we don't switch FS selectors
|
|---|
| 213 | if(fIsOS2Image) {
|
|---|
| 214 | return;
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 | winteb = (TEB *)*TIBFlatPtr;
|
|---|
| 218 | if(winteb) {
|
|---|
| 219 | thdb = (THDB *)(winteb+1);
|
|---|
| 220 | orgtibsel = thdb->OrgTIBSel;
|
|---|
| 221 |
|
|---|
| 222 | //Restore our original FS selector
|
|---|
| 223 | SetFS(orgtibsel);
|
|---|
| 224 | }
|
|---|
| 225 | }
|
|---|
| 226 | /******************************************************************************/
|
|---|
| 227 | /******************************************************************************/
|
|---|
| 228 | USHORT WIN32API SetWin32TIB()
|
|---|
| 229 | {
|
|---|
| 230 | SHORT win32tibsel;
|
|---|
| 231 | TEB *winteb;
|
|---|
| 232 | THDB *thdb;
|
|---|
| 233 |
|
|---|
| 234 | //If we're running an Odin32 OS/2 application (not converted!), then we
|
|---|
| 235 | //we don't switch FS selectors
|
|---|
| 236 | if(fIsOS2Image) {
|
|---|
| 237 | return GetFS();
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | winteb = (TEB *)*TIBFlatPtr;
|
|---|
| 241 | if(winteb) {
|
|---|
| 242 | thdb = (THDB *)(winteb+1);
|
|---|
| 243 | win32tibsel = thdb->teb_sel;
|
|---|
| 244 |
|
|---|
| 245 | //Restore our win32 FS selector
|
|---|
| 246 | return SetReturnFS(win32tibsel);
|
|---|
| 247 | }
|
|---|
| 248 | else {
|
|---|
| 249 | //we didn't create this thread, so allocate a selector now
|
|---|
| 250 | //NOTE: Possible memory leak (i.e. DART threads in WINMM)
|
|---|
| 251 | winteb = InitializeTIB();
|
|---|
| 252 | if(winteb == NULL) {
|
|---|
| 253 | DebugInt3();
|
|---|
| 254 | return GetFS();
|
|---|
| 255 | }
|
|---|
| 256 | thdb = (THDB *)(winteb+1);
|
|---|
| 257 | win32tibsel = thdb->teb_sel;
|
|---|
| 258 |
|
|---|
| 259 | //Restore our win32 FS selector
|
|---|
| 260 | return SetReturnFS(win32tibsel);
|
|---|
| 261 | }
|
|---|
| 262 | // nested calls are OK, OS2ToWinCallback for instance
|
|---|
| 263 | //else DebugInt3();
|
|---|
| 264 |
|
|---|
| 265 | return GetFS();
|
|---|
| 266 | }
|
|---|
| 267 | //******************************************************************************
|
|---|
| 268 | //******************************************************************************
|
|---|
| 269 | void _System Win32DllExitList(ULONG reason)
|
|---|
| 270 | {
|
|---|
| 271 | dprintf(("Win32DllExitList %d\n", reason));
|
|---|
| 272 |
|
|---|
| 273 | if(WinExe) {
|
|---|
| 274 | delete(WinExe);
|
|---|
| 275 | WinExe = NULL;
|
|---|
| 276 | }
|
|---|
| 277 | return;
|
|---|
| 278 | }
|
|---|
| 279 | //******************************************************************************
|
|---|
| 280 | //******************************************************************************
|
|---|
| 281 | VOID WIN32API ExitProcess(DWORD exitcode)
|
|---|
| 282 | {
|
|---|
| 283 | dprintf(("KERNEL32: ExitProcess %d\n", exitcode));
|
|---|
| 284 | dprintf(("KERNEL32: ExitProcess FS = %x\n", GetFS()));
|
|---|
| 285 |
|
|---|
| 286 | SetOS2ExceptionChain(-1);
|
|---|
| 287 |
|
|---|
| 288 | Win32DllExitList(0);
|
|---|
| 289 |
|
|---|
| 290 | //Note: Needs to be done after Win32DllExitList (destruction of exe + dll objects)
|
|---|
| 291 | //Flush and delete all open memory mapped files
|
|---|
| 292 | Win32MemMap::deleteAll();
|
|---|
| 293 |
|
|---|
| 294 | //Restore original OS/2 TIB selector
|
|---|
| 295 | DestroyTIB();
|
|---|
| 296 | SetExceptionChain((ULONG)-1);
|
|---|
| 297 |
|
|---|
| 298 | //avoid crashes since win32 & OS/2 exception handler aren't identical
|
|---|
| 299 | //(terminate process generates two exceptions)
|
|---|
| 300 | /* @@@PH 1998/02/12 Added Console Support */
|
|---|
| 301 | if (iConsoleIsActive())
|
|---|
| 302 | iConsoleWaitClose();
|
|---|
| 303 |
|
|---|
| 304 | O32_ExitProcess(exitcode);
|
|---|
| 305 | }
|
|---|
| 306 | //******************************************************************************
|
|---|
| 307 | //******************************************************************************
|
|---|
| 308 | BOOL WIN32API FreeLibrary(HINSTANCE hinstance)
|
|---|
| 309 | {
|
|---|
| 310 | Win32DllBase *winmod;
|
|---|
| 311 | BOOL rc;
|
|---|
| 312 |
|
|---|
| 313 | dprintf(("FreeLibrary"));
|
|---|
| 314 | winmod = Win32DllBase::findModule(hinstance);
|
|---|
| 315 | if(winmod) {
|
|---|
| 316 | winmod->Release();
|
|---|
| 317 | return(TRUE);
|
|---|
| 318 | }
|
|---|
| 319 | dprintf(("KERNEL32: FreeLibrary %s %X\n", OSLibGetDllName(hinstance), hinstance));
|
|---|
| 320 |
|
|---|
| 321 | //TODO: Not thread safe
|
|---|
| 322 | fFreeLibrary = TRUE; //ditch dll
|
|---|
| 323 | rc = O32_FreeLibrary(hinstance);
|
|---|
| 324 | fFreeLibrary = FALSE;
|
|---|
| 325 | dprintf(("FreeLibrary returned %X\n", rc));
|
|---|
| 326 | return(TRUE);
|
|---|
| 327 | }
|
|---|
| 328 | /******************************************************************************/
|
|---|
| 329 | /******************************************************************************/
|
|---|
| 330 | static HINSTANCE iLoadLibraryA(LPCTSTR lpszLibFile, DWORD dwFlags)
|
|---|
| 331 | {
|
|---|
| 332 | char modname[CCHMAXPATH];
|
|---|
| 333 | HINSTANCE hDll;
|
|---|
| 334 | Win32DllBase *module;
|
|---|
| 335 |
|
|---|
| 336 | module = Win32DllBase::findModule((LPSTR)lpszLibFile);
|
|---|
| 337 | if(module) {
|
|---|
| 338 | module->AddRef();
|
|---|
| 339 | return module->getInstanceHandle();
|
|---|
| 340 | }
|
|---|
| 341 |
|
|---|
| 342 | strcpy(modname, lpszLibFile);
|
|---|
| 343 | strupr(modname);
|
|---|
| 344 | //rename dll if necessary (i.e. OLE32 -> OLE32OS2)
|
|---|
| 345 | Win32DllBase::renameDll(modname);
|
|---|
| 346 |
|
|---|
| 347 | hDll = O32_LoadLibrary(modname);
|
|---|
| 348 | dprintf(("KERNEL32: iLoadLibraryA %s returned %X (%d)\n",
|
|---|
| 349 | lpszLibFile,
|
|---|
| 350 | hDll,
|
|---|
| 351 | GetLastError()));
|
|---|
| 352 | if(hDll)
|
|---|
| 353 | {
|
|---|
| 354 | return hDll; //converted dll or win32k took care of it
|
|---|
| 355 | }
|
|---|
| 356 |
|
|---|
| 357 | if(!strstr(modname, ".")) {
|
|---|
| 358 | strcat(modname,".DLL");
|
|---|
| 359 | }
|
|---|
| 360 |
|
|---|
| 361 | if(Win32ImageBase::isPEImage((char *)modname))
|
|---|
| 362 | {
|
|---|
| 363 | module = Win32DllBase::findModule((char *)modname);
|
|---|
| 364 | if(module) {//don't load it again
|
|---|
| 365 | module->AddRef();
|
|---|
| 366 | return module->getInstanceHandle();
|
|---|
| 367 | }
|
|---|
| 368 |
|
|---|
| 369 | Win32PeLdrDll *peldrDll = new Win32PeLdrDll((char *)modname);
|
|---|
| 370 | if(peldrDll == NULL)
|
|---|
| 371 | return(0);
|
|---|
| 372 |
|
|---|
| 373 | peldrDll->init(0);
|
|---|
| 374 | if(peldrDll->getError() != NO_ERROR) {
|
|---|
| 375 | dprintf(("LoadLibary %s failed (::init)\n", lpszLibFile));
|
|---|
| 376 | delete(peldrDll);
|
|---|
| 377 | return(0);
|
|---|
| 378 | }
|
|---|
| 379 | if(dwFlags & DONT_RESOLVE_DLL_REFERENCES) {
|
|---|
| 380 | peldrDll->setNoEntryCalls();
|
|---|
| 381 | }
|
|---|
| 382 |
|
|---|
| 383 | if(peldrDll->attachProcess() == FALSE) {
|
|---|
| 384 | dprintf(("LoadLibary %s failed (::attachProcess)\n", lpszLibFile));
|
|---|
| 385 | delete(peldrDll);
|
|---|
| 386 | return(0);
|
|---|
| 387 | }
|
|---|
| 388 | peldrDll->AddRef();
|
|---|
| 389 | return peldrDll->getInstanceHandle();
|
|---|
| 390 | }
|
|---|
| 391 | else return(0);
|
|---|
| 392 | }
|
|---|
| 393 | //******************************************************************************
|
|---|
| 394 | //******************************************************************************
|
|---|
| 395 | HINSTANCE WIN32API LoadLibraryA(LPCTSTR lpszLibFile)
|
|---|
| 396 | {
|
|---|
| 397 | HINSTANCE hDll;
|
|---|
| 398 |
|
|---|
| 399 | dprintf(("KERNEL32: LoadLibraryA(%s)\n",
|
|---|
| 400 | lpszLibFile));
|
|---|
| 401 | dprintf(("KERNEL32: LoadLibrary %x FS = %x\n", GetCurrentThreadId(), GetFS()));
|
|---|
| 402 |
|
|---|
| 403 | hDll = iLoadLibraryA(lpszLibFile, 0);
|
|---|
| 404 | if (hDll == 0)
|
|---|
| 405 | {
|
|---|
| 406 | char * pszName;
|
|---|
| 407 |
|
|---|
| 408 | // remove path from the image name
|
|---|
| 409 | pszName = strrchr((char *)lpszLibFile,
|
|---|
| 410 | '\\');
|
|---|
| 411 | if (pszName != NULL)
|
|---|
| 412 | {
|
|---|
| 413 | pszName++; // skip backslash
|
|---|
| 414 |
|
|---|
| 415 | // now try again without fully qualified path
|
|---|
| 416 | hDll = iLoadLibraryA(pszName, 0);
|
|---|
| 417 | }
|
|---|
| 418 | }
|
|---|
| 419 |
|
|---|
| 420 | return hDll;
|
|---|
| 421 | }
|
|---|
| 422 | //******************************************************************************
|
|---|
| 423 | //******************************************************************************
|
|---|
| 424 | HINSTANCE WIN32API LoadLibraryExA(LPCTSTR lpszLibFile, HANDLE hFile, DWORD dwFlags)
|
|---|
| 425 | {
|
|---|
| 426 | HINSTANCE hDll;
|
|---|
| 427 |
|
|---|
| 428 | dprintf(("KERNEL32: LoadLibraryExA %s (%X)\n", lpszLibFile, dwFlags));
|
|---|
| 429 | hDll = iLoadLibraryA(lpszLibFile, dwFlags);
|
|---|
| 430 | if (hDll == 0)
|
|---|
| 431 | {
|
|---|
| 432 | char * pszName;
|
|---|
| 433 |
|
|---|
| 434 | // remove path from the image name
|
|---|
| 435 | pszName = strrchr((char *)lpszLibFile,
|
|---|
| 436 | '\\');
|
|---|
| 437 | if (pszName != NULL)
|
|---|
| 438 | {
|
|---|
| 439 | pszName++; // skip backslash
|
|---|
| 440 |
|
|---|
| 441 | // now try again without fully qualified path
|
|---|
| 442 | hDll = iLoadLibraryA(pszName, dwFlags);
|
|---|
| 443 | }
|
|---|
| 444 | }
|
|---|
| 445 |
|
|---|
| 446 | return hDll;
|
|---|
| 447 | }
|
|---|
| 448 | //******************************************************************************
|
|---|
| 449 | //******************************************************************************
|
|---|
| 450 | HINSTANCE WIN32API LoadLibraryW(LPCWSTR lpModule)
|
|---|
| 451 | {
|
|---|
| 452 | char *asciimodule;
|
|---|
| 453 | HINSTANCE rc;
|
|---|
| 454 |
|
|---|
| 455 | asciimodule = UnicodeToAsciiString((LPWSTR)lpModule);
|
|---|
| 456 | dprintf(("KERNEL32: OS2LoadLibraryW %s\n", asciimodule));
|
|---|
| 457 | rc = LoadLibraryA(asciimodule);
|
|---|
| 458 | free(asciimodule);
|
|---|
| 459 | return(rc);
|
|---|
| 460 | }
|
|---|
| 461 | //******************************************************************************
|
|---|
| 462 | //******************************************************************************
|
|---|
| 463 | HINSTANCE WIN32API LoadLibraryExW(LPCWSTR lpModule, HANDLE hFile, DWORD dwFlags)
|
|---|
| 464 | {
|
|---|
| 465 | char *asciimodule;
|
|---|
| 466 | HINSTANCE rc;
|
|---|
| 467 |
|
|---|
| 468 | asciimodule = UnicodeToAsciiString((LPWSTR)lpModule);
|
|---|
| 469 | dprintf(("KERNEL32: OS2LoadLibraryExW %s (%d)\n", asciimodule, dwFlags));
|
|---|
| 470 | rc = LoadLibraryExA(asciimodule, hFile, dwFlags);
|
|---|
| 471 | free(asciimodule);
|
|---|
| 472 | return(rc);
|
|---|
| 473 | }
|
|---|
| 474 | //******************************************************************************
|
|---|
| 475 | //******************************************************************************
|
|---|
| 476 | LPCSTR WIN32API GetCommandLineA()
|
|---|
| 477 | {
|
|---|
| 478 | LPTSTR cmdline = NULL;
|
|---|
| 479 |
|
|---|
| 480 | if(WinExe) {
|
|---|
| 481 | cmdline = WinExe->getCommandLine();
|
|---|
| 482 | }
|
|---|
| 483 | if(cmdline == NULL) //not used for converted exes
|
|---|
| 484 | cmdline = O32_GetCommandLine();
|
|---|
| 485 |
|
|---|
| 486 | dprintf(("KERNEL32: GetCommandLine %s\n", cmdline));
|
|---|
| 487 | dprintf(("KERNEL32: FS = %x\n", GetFS()));
|
|---|
| 488 | return(cmdline);
|
|---|
| 489 | }
|
|---|
| 490 | //******************************************************************************
|
|---|
| 491 | //******************************************************************************
|
|---|
| 492 | LPCWSTR WIN32API GetCommandLineW(void)
|
|---|
| 493 | {
|
|---|
| 494 | static WCHAR *UnicodeCmdLine = NULL;
|
|---|
| 495 | char *asciicmdline = NULL;
|
|---|
| 496 |
|
|---|
| 497 | dprintf(("KERNEL32: FS = %x\n", GetFS()));
|
|---|
| 498 |
|
|---|
| 499 | if(UnicodeCmdLine)
|
|---|
| 500 | return(UnicodeCmdLine); //already called before
|
|---|
| 501 |
|
|---|
| 502 | if(WinExe) {
|
|---|
| 503 | asciicmdline = WinExe->getCommandLine();
|
|---|
| 504 | }
|
|---|
| 505 | if(asciicmdline == NULL) //not used for converted exes
|
|---|
| 506 | asciicmdline = O32_GetCommandLine();
|
|---|
| 507 |
|
|---|
| 508 | if(asciicmdline) {
|
|---|
| 509 | UnicodeCmdLine = (WCHAR *)malloc(strlen(asciicmdline)*2 + 2);
|
|---|
| 510 | AsciiToUnicode(asciicmdline, UnicodeCmdLine);
|
|---|
| 511 | dprintf(("KERNEL32: OS2GetCommandLineW: %s\n", asciicmdline));
|
|---|
| 512 | return(UnicodeCmdLine);
|
|---|
| 513 | }
|
|---|
| 514 | dprintf(("KERNEL32: OS2GetCommandLineW: asciicmdline == NULL\n"));
|
|---|
| 515 | return NULL;
|
|---|
| 516 | }
|
|---|
| 517 | //******************************************************************************
|
|---|
| 518 | //******************************************************************************
|
|---|
| 519 | DWORD WIN32API GetModuleFileNameA(HMODULE hinstModule, LPTSTR lpszPath, DWORD cchPath)
|
|---|
| 520 | {
|
|---|
| 521 | DWORD rc;
|
|---|
| 522 | Win32ImageBase *module;
|
|---|
| 523 | char *fpath = NULL;
|
|---|
| 524 |
|
|---|
| 525 | dprintf(("GetModuleFileName %X", hinstModule));
|
|---|
| 526 | if(hinstModule == 0 || hinstModule == -1 || (WinExe && hinstModule == WinExe->getInstanceHandle())) {
|
|---|
| 527 | module = (Win32ImageBase *)WinExe;
|
|---|
| 528 | }
|
|---|
| 529 | else {
|
|---|
| 530 | module = (Win32ImageBase *)Win32DllBase::findModule(hinstModule);
|
|---|
| 531 | }
|
|---|
| 532 |
|
|---|
| 533 | if(module) {
|
|---|
| 534 | fpath = module->getFullPath();
|
|---|
| 535 | }
|
|---|
| 536 | if(fpath) {
|
|---|
| 537 | //SvL: 13-9-98: +1
|
|---|
| 538 | rc = min(strlen(fpath)+1, cchPath);
|
|---|
| 539 | strncpy(lpszPath, fpath, rc);
|
|---|
| 540 | }
|
|---|
| 541 | else rc = O32_GetModuleFileName(hinstModule, lpszPath, cchPath);
|
|---|
| 542 |
|
|---|
| 543 | if(rc) {
|
|---|
| 544 | dprintf(("KERNEL32: GetModuleFileName %s %d\n", lpszPath, hinstModule));
|
|---|
| 545 | }
|
|---|
| 546 | return(rc);
|
|---|
| 547 | }
|
|---|
| 548 | //******************************************************************************
|
|---|
| 549 | //******************************************************************************
|
|---|
| 550 | DWORD WIN32API GetModuleFileNameW(HMODULE hModule, LPWSTR lpFileName, DWORD nSize)
|
|---|
| 551 | {
|
|---|
| 552 | char *asciifilename = (char *)malloc(nSize+1);
|
|---|
| 553 | DWORD rc;
|
|---|
| 554 |
|
|---|
| 555 | dprintf(("KERNEL32: OSLibGetModuleFileNameW\n"));
|
|---|
| 556 | rc = GetModuleFileNameA(hModule, asciifilename, nSize);
|
|---|
| 557 | if(rc) AsciiToUnicode(asciifilename, lpFileName);
|
|---|
| 558 | free(asciifilename);
|
|---|
| 559 | return(rc);
|
|---|
| 560 | }
|
|---|
| 561 | //******************************************************************************
|
|---|
| 562 | //NOTE: GetModuleHandleA does NOT support files with multiple dots (i.e.
|
|---|
| 563 | // very.weird.exe)
|
|---|
| 564 | //******************************************************************************
|
|---|
| 565 | HANDLE WIN32API GetModuleHandleA(LPCTSTR lpszModule)
|
|---|
| 566 | {
|
|---|
| 567 | HANDLE hMod;
|
|---|
| 568 | Win32DllBase *windll;
|
|---|
| 569 | char szModule[CCHMAXPATH];
|
|---|
| 570 | BOOL fDllModule = FALSE;
|
|---|
| 571 |
|
|---|
| 572 | if(lpszModule == NULL) {
|
|---|
| 573 | if(WinExe)
|
|---|
| 574 | hMod = WinExe->getInstanceHandle();
|
|---|
| 575 | else hMod = -1;
|
|---|
| 576 | }
|
|---|
| 577 | else {
|
|---|
| 578 | strcpy(szModule, OSLibStripPath((char *)lpszModule));
|
|---|
| 579 | strupr(szModule);
|
|---|
| 580 | if(strstr(szModule, ".DLL")) {
|
|---|
| 581 | fDllModule = TRUE;
|
|---|
| 582 | }
|
|---|
| 583 | else {
|
|---|
| 584 | if(!strstr(szModule, ".")) {
|
|---|
| 585 | //if there's no extension or trainling dot, we
|
|---|
| 586 | //assume it's a dll (see Win32 SDK docs)
|
|---|
| 587 | fDllModule = TRUE;
|
|---|
| 588 | }
|
|---|
| 589 | }
|
|---|
| 590 | char *dot = strstr(szModule, ".");
|
|---|
| 591 | if(dot)
|
|---|
| 592 | *dot = 0;
|
|---|
| 593 |
|
|---|
| 594 | if(!fDllModule && WinExe && !strcmpi(szModule, WinExe->getModuleName())) {
|
|---|
| 595 | hMod = WinExe->getInstanceHandle();
|
|---|
| 596 | }
|
|---|
| 597 | else {
|
|---|
| 598 | windll = Win32DllBase::findModule(szModule);
|
|---|
| 599 | if(windll) {
|
|---|
| 600 | hMod = windll->getInstanceHandle();
|
|---|
| 601 | }
|
|---|
| 602 | else hMod = OSLibiGetModuleHandleA((char *)lpszModule);
|
|---|
| 603 | }
|
|---|
| 604 | }
|
|---|
| 605 |
|
|---|
| 606 | eprintf(("KERNEL32: GetModuleHandle %s returned %X\n", lpszModule, hMod));
|
|---|
| 607 | return(hMod);
|
|---|
| 608 | }
|
|---|
| 609 | //******************************************************************************
|
|---|
| 610 | //******************************************************************************
|
|---|
| 611 | HMODULE WIN32API GetModuleHandleW(LPCWSTR arg1)
|
|---|
| 612 | {
|
|---|
| 613 | HMODULE rc;
|
|---|
| 614 | char *astring;
|
|---|
| 615 |
|
|---|
| 616 | astring = UnicodeToAsciiString((LPWSTR)arg1);
|
|---|
| 617 | rc = GetModuleHandleA(astring);
|
|---|
| 618 | dprintf(("KERNEL32: OS2GetModuleHandleW %s returned %X\n", astring, rc));
|
|---|
| 619 | FreeAsciiString(astring);
|
|---|
| 620 | return(rc);
|
|---|
| 621 | }
|
|---|
| 622 | //******************************************************************************
|
|---|
| 623 | //******************************************************************************
|
|---|
| 624 | BOOL WIN32API CreateProcessA(LPCSTR lpszImageName, LPSTR lpszCommandLine,
|
|---|
| 625 | PSECURITY_ATTRIBUTES arg3,
|
|---|
| 626 | PSECURITY_ATTRIBUTES arg4, BOOL arg5, DWORD arg6,
|
|---|
| 627 | PVOID arg7, LPCSTR arg8, LPSTARTUPINFOA arg9,
|
|---|
| 628 | LPPROCESS_INFORMATION arg10)
|
|---|
| 629 | {
|
|---|
| 630 | BOOL rc;
|
|---|
| 631 | char *cmdline;
|
|---|
| 632 | BOOL fAllocStr = FALSE;
|
|---|
| 633 |
|
|---|
| 634 | if(O32_CreateProcess(lpszImageName, lpszCommandLine, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) == TRUE)
|
|---|
| 635 | return(TRUE);
|
|---|
| 636 |
|
|---|
| 637 | //probably a win32 exe, so run it in the pe loader
|
|---|
| 638 | if(lpszImageName) {
|
|---|
| 639 | if(lpszCommandLine) {
|
|---|
| 640 | cmdline = (char *)malloc(strlen(lpszImageName)+strlen(lpszCommandLine) + 16);
|
|---|
| 641 | sprintf(cmdline, "PE.EXE %s %s", lpszImageName, lpszCommandLine);
|
|---|
| 642 | fAllocStr = TRUE;
|
|---|
| 643 | }
|
|---|
| 644 | else {
|
|---|
| 645 | cmdline = (char *)malloc(strlen(lpszImageName) + 16);
|
|---|
| 646 | sprintf(cmdline, "PE.EXE %s", lpszImageName);
|
|---|
| 647 | fAllocStr = TRUE;
|
|---|
| 648 | }
|
|---|
| 649 | }
|
|---|
| 650 | else {
|
|---|
| 651 | cmdline = (char *)malloc(strlen(lpszCommandLine) + 16);
|
|---|
| 652 | sprintf(cmdline, "PE.EXE %s", lpszCommandLine);
|
|---|
| 653 | fAllocStr = TRUE;
|
|---|
| 654 | }
|
|---|
| 655 | dprintf(("KERNEL32: CreateProcess %s\n", cmdline));
|
|---|
| 656 | rc = O32_CreateProcess("PE.EXE", (LPCSTR)cmdline, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
|
|---|
| 657 | if(fAllocStr)
|
|---|
| 658 | free(cmdline);
|
|---|
| 659 |
|
|---|
| 660 | dprintf(("KERNEL32: CreateProcess returned %d\n", rc));
|
|---|
| 661 | return(rc);
|
|---|
| 662 | }
|
|---|
| 663 | //******************************************************************************
|
|---|
| 664 | //******************************************************************************
|
|---|
| 665 | BOOL WIN32API CreateProcessW(LPCWSTR arg1, LPWSTR arg2,
|
|---|
| 666 | PSECURITY_ATTRIBUTES arg3,
|
|---|
| 667 | PSECURITY_ATTRIBUTES arg4,
|
|---|
| 668 | BOOL arg5, DWORD arg6, PVOID arg7,
|
|---|
| 669 | LPCWSTR arg8, LPSTARTUPINFOW arg9,
|
|---|
| 670 | LPPROCESS_INFORMATION arg10)
|
|---|
| 671 | {
|
|---|
| 672 | BOOL rc;
|
|---|
| 673 | char *astring1, *astring2, *astring3;
|
|---|
| 674 |
|
|---|
| 675 | dprintf(("KERNEL32: OS2CreateProcessW DOESN't WORK"));
|
|---|
| 676 | astring1 = UnicodeToAsciiString((LPWSTR)arg1);
|
|---|
| 677 | astring2 = UnicodeToAsciiString(arg2);
|
|---|
| 678 | astring3 = UnicodeToAsciiString((LPWSTR)arg8);
|
|---|
| 679 | // NOTE: This will not work as is (needs UNICODE support)
|
|---|
| 680 | rc = CreateProcessA(astring1, astring2, arg3, arg4, arg5, arg6, arg7,
|
|---|
| 681 | astring3, (LPSTARTUPINFOA)arg9, arg10);
|
|---|
| 682 | FreeAsciiString(astring3);
|
|---|
| 683 | FreeAsciiString(astring2);
|
|---|
| 684 | FreeAsciiString(astring1);
|
|---|
| 685 | return(rc);
|
|---|
| 686 | }
|
|---|
| 687 | //******************************************************************************
|
|---|
| 688 | //******************************************************************************
|
|---|
| 689 | HINSTANCE WIN32API WinExec(LPCSTR lpCmdLine, UINT nCmdShow)
|
|---|
| 690 | {
|
|---|
| 691 | STARTUPINFOA startinfo = {0};
|
|---|
| 692 | PROCESS_INFORMATION procinfo;
|
|---|
| 693 |
|
|---|
| 694 | dprintf(("KERNEL32: WinExec %s\n", lpCmdLine));
|
|---|
| 695 | startinfo.dwFlags = nCmdShow;
|
|---|
| 696 | if(CreateProcessA(NULL, (LPSTR)lpCmdLine, NULL, NULL, FALSE, 0, NULL, NULL,
|
|---|
| 697 | &startinfo, &procinfo) == FALSE)
|
|---|
| 698 | {
|
|---|
| 699 | return 0;
|
|---|
| 700 | }
|
|---|
| 701 | return procinfo.hProcess; //correct?
|
|---|
| 702 | }
|
|---|
| 703 | //******************************************************************************
|
|---|
| 704 | //******************************************************************************
|
|---|
| 705 | FARPROC WIN32API GetProcAddress(HMODULE hModule, LPCSTR lpszProc)
|
|---|
| 706 | {
|
|---|
| 707 | Win32ImageBase *winmod;
|
|---|
| 708 | FARPROC proc;
|
|---|
| 709 | ULONG ulAPIOrdinal;
|
|---|
| 710 |
|
|---|
| 711 | if(hModule == 0 || hModule == -1 || (WinExe && hModule == WinExe->getInstanceHandle())) {
|
|---|
| 712 | winmod = WinExe;
|
|---|
| 713 | }
|
|---|
| 714 | else winmod = (Win32ImageBase *)Win32DllBase::findModule((HINSTANCE)hModule);
|
|---|
| 715 |
|
|---|
| 716 | if(winmod) {
|
|---|
| 717 | ulAPIOrdinal = (ULONG)lpszProc;
|
|---|
| 718 | if (ulAPIOrdinal <= 0x0000FFFF) {
|
|---|
| 719 | proc = (FARPROC)winmod->getApi((int)ulAPIOrdinal);
|
|---|
| 720 | }
|
|---|
| 721 | else proc = (FARPROC)winmod->getApi((char *)lpszProc);
|
|---|
| 722 | if(proc == 0) {
|
|---|
| 723 | SetLastError(ERROR_PROC_NOT_FOUND);
|
|---|
| 724 | }
|
|---|
| 725 | return proc;
|
|---|
| 726 | }
|
|---|
| 727 | proc = O32_GetProcAddress(hModule, lpszProc);
|
|---|
| 728 | if(HIWORD(lpszProc))
|
|---|
| 729 | dprintf(("KERNEL32: GetProcAddress %s from %X returned %X\n", lpszProc, hModule, proc));
|
|---|
| 730 | else dprintf(("KERNEL32: GetProcAddress %x from %X returned %X\n", lpszProc, hModule, proc));
|
|---|
| 731 | return(proc);
|
|---|
| 732 | }
|
|---|
| 733 | //******************************************************************************
|
|---|
| 734 | //Retrieve the version
|
|---|
| 735 | //******************************************************************************
|
|---|
| 736 | BOOL SYSTEM GetVersionStruct(char *lpszModName, char *verstruct, ULONG bufLength)
|
|---|
| 737 | {
|
|---|
| 738 | Win32ImageBase *winimage;
|
|---|
| 739 | Win32PeLdrRsrcImg *rsrcimg;
|
|---|
| 740 |
|
|---|
| 741 | dprintf(("GetVersionStruct of module %s", lpszModName));
|
|---|
| 742 | if(WinExe && !stricmp(WinExe->getFullPath(), lpszModName)) {
|
|---|
| 743 | winimage = (Win32ImageBase *)WinExe;
|
|---|
| 744 | }
|
|---|
| 745 | else {
|
|---|
| 746 | winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName);
|
|---|
| 747 | if(winimage == NULL)
|
|---|
| 748 | {
|
|---|
| 749 | char modname[CCHMAXPATH];
|
|---|
| 750 |
|
|---|
| 751 | strcpy(modname, lpszModName);
|
|---|
| 752 | //rename dll if necessary (i.e. OLE32 -> OLE32OS2)
|
|---|
| 753 | Win32DllBase::renameDll(modname);
|
|---|
| 754 |
|
|---|
| 755 | if(Win32ImageBase::isPEImage(modname) == FALSE)
|
|---|
| 756 | {
|
|---|
| 757 | HINSTANCE hInstance;
|
|---|
| 758 |
|
|---|
| 759 | //must be an LX dll, just load it (app will probably load it anyway)
|
|---|
| 760 | hInstance = LoadLibraryA(modname);
|
|---|
| 761 | if(hInstance == 0)
|
|---|
| 762 | return 0;
|
|---|
| 763 | winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance);
|
|---|
| 764 | if(winimage) {
|
|---|
| 765 | return winimage->getVersionStruct(verstruct, bufLength);
|
|---|
| 766 | }
|
|---|
| 767 | return 0;
|
|---|
| 768 | }
|
|---|
| 769 | //SvL: Try to load it
|
|---|
| 770 | rsrcimg = new Win32PeLdrRsrcImg(modname);
|
|---|
| 771 | if(rsrcimg == NULL)
|
|---|
| 772 | return 0;
|
|---|
| 773 |
|
|---|
| 774 | rsrcimg->init(0);
|
|---|
| 775 | if(rsrcimg->getError() != NO_ERROR)
|
|---|
| 776 | {
|
|---|
| 777 | dprintf(("GetVersionStruct can't load %s\n", modname));
|
|---|
| 778 | delete rsrcimg;
|
|---|
| 779 | return(FALSE);
|
|---|
| 780 | }
|
|---|
| 781 | BOOL rc = rsrcimg->getVersionStruct(verstruct, bufLength);
|
|---|
| 782 | delete rsrcimg;
|
|---|
| 783 | return rc;
|
|---|
| 784 | }
|
|---|
| 785 | }
|
|---|
| 786 | return winimage->getVersionStruct(verstruct, bufLength);
|
|---|
| 787 | }
|
|---|
| 788 | //******************************************************************************
|
|---|
| 789 | //******************************************************************************
|
|---|
| 790 | ULONG SYSTEM GetVersionSize(char *lpszModName)
|
|---|
| 791 | {
|
|---|
| 792 | Win32ImageBase *winimage;
|
|---|
| 793 | Win32PeLdrRsrcImg *rsrcimg;
|
|---|
| 794 |
|
|---|
| 795 | dprintf(("GetVersionSize of %s\n", lpszModName));
|
|---|
| 796 |
|
|---|
| 797 | if(WinExe && !stricmp(WinExe->getFullPath(), lpszModName)) {
|
|---|
| 798 | winimage = (Win32ImageBase *)WinExe;
|
|---|
| 799 | }
|
|---|
| 800 | else {
|
|---|
| 801 | winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName);
|
|---|
| 802 | if(winimage == NULL)
|
|---|
| 803 | {
|
|---|
| 804 | char modname[CCHMAXPATH];
|
|---|
| 805 |
|
|---|
| 806 | strcpy(modname, lpszModName);
|
|---|
| 807 | //rename dll if necessary (i.e. OLE32 -> OLE32OS2)
|
|---|
| 808 | Win32DllBase::renameDll(modname);
|
|---|
| 809 |
|
|---|
| 810 | if(Win32ImageBase::isPEImage(modname) == FALSE)
|
|---|
| 811 | {
|
|---|
| 812 | HINSTANCE hInstance;
|
|---|
| 813 |
|
|---|
| 814 | //must be an LX dll, just load it (app will probably load it anyway)
|
|---|
| 815 | hInstance = LoadLibraryA(modname);
|
|---|
| 816 | if(hInstance == 0)
|
|---|
| 817 | return 0;
|
|---|
| 818 | winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance);
|
|---|
| 819 | if(winimage) {
|
|---|
| 820 | return winimage->getVersionSize();
|
|---|
| 821 | }
|
|---|
| 822 | return 0;
|
|---|
| 823 | }
|
|---|
| 824 |
|
|---|
| 825 | //SvL: Try to load it
|
|---|
| 826 | rsrcimg = new Win32PeLdrRsrcImg(modname);
|
|---|
| 827 | if(rsrcimg == NULL)
|
|---|
| 828 | return 0;
|
|---|
| 829 |
|
|---|
| 830 | rsrcimg->init(0);
|
|---|
| 831 | if(rsrcimg->getError() != NO_ERROR)
|
|---|
| 832 | {
|
|---|
| 833 | dprintf(("GetVersionSize can't load %s\n", modname));
|
|---|
| 834 | delete rsrcimg;
|
|---|
| 835 | return(FALSE);
|
|---|
| 836 | }
|
|---|
| 837 | int size = rsrcimg->getVersionSize();
|
|---|
| 838 | delete rsrcimg;
|
|---|
| 839 | return size;
|
|---|
| 840 | }
|
|---|
| 841 | }
|
|---|
| 842 | return winimage->getVersionSize();
|
|---|
| 843 | }
|
|---|
| 844 | //******************************************************************************
|
|---|
| 845 | //TODO:What does this do exactly??
|
|---|
| 846 | //******************************************************************************
|
|---|
| 847 | ODINFUNCTION1(BOOL,DisableThreadLibraryCalls,HMODULE,hModule)
|
|---|
| 848 | {
|
|---|
| 849 | Win32DllBase *winmod;
|
|---|
| 850 | FARPROC proc;
|
|---|
| 851 | ULONG ulAPIOrdinal;
|
|---|
| 852 |
|
|---|
| 853 | winmod = Win32DllBase::findModule((HINSTANCE)hModule);
|
|---|
| 854 | if(winmod)
|
|---|
| 855 | {
|
|---|
| 856 | // don't call ATTACH/DETACH thread functions in DLL
|
|---|
| 857 | winmod->setThreadLibraryCalls(FALSE);
|
|---|
| 858 | return TRUE;
|
|---|
| 859 | }
|
|---|
| 860 | else
|
|---|
| 861 | {
|
|---|
| 862 | // raise error condition
|
|---|
| 863 | SetLastError(ERROR_INVALID_HANDLE);
|
|---|
| 864 | return FALSE;
|
|---|
| 865 | }
|
|---|
| 866 | }
|
|---|
| 867 | //******************************************************************************
|
|---|
| 868 | //******************************************************************************
|
|---|