4 * Copyright 1995 Alexandre Julliard
13 #include "wine/winbase16.h"
27 #include "builtin16.h"
28 #include "stackframe.h"
29 #include "debugtools.h"
30 #include "loadorder.h"
33 DEFAULT_DEBUG_CHANNEL(module)
35 #define hFirstModule (pThhook->hExeHead)
37 static NE_MODULE *pCachedModule = 0; /* Module cached by NE_OpenFile */
39 static HINSTANCE16 NE_LoadModule( LPCSTR name, BOOL lib_only );
40 static BOOL16 NE_FreeModule( HMODULE16 hModule, BOOL call_wep );
42 static HINSTANCE16 MODULE_LoadModule16( LPCSTR libname, BOOL implicit, BOOL lib_only );
44 static HMODULE16 NE_GetModuleByFilename( LPCSTR name );
46 /***********************************************************************
49 NE_MODULE *NE_GetPtr( HMODULE16 hModule )
51 return (NE_MODULE *)GlobalLock16( GetExePtr(hModule) );
55 /***********************************************************************
58 void NE_DumpModule( HMODULE16 hModule )
68 if (!(pModule = NE_GetPtr( hModule )))
70 MESSAGE( "**** %04x is not a module handle\n", hModule );
74 /* Dump the module info */
76 DPRINTF( "Module %04x:\n", hModule );
77 DPRINTF( "count=%d flags=%04x heap=%d stack=%d\n",
78 pModule->count, pModule->flags,
79 pModule->heap_size, pModule->stack_size );
80 DPRINTF( "cs:ip=%04x:%04x ss:sp=%04x:%04x ds=%04x nb seg=%d modrefs=%d\n",
81 pModule->cs, pModule->ip, pModule->ss, pModule->sp, pModule->dgroup,
82 pModule->seg_count, pModule->modref_count );
83 DPRINTF( "os_flags=%d swap_area=%d version=%04x\n",
84 pModule->os_flags, pModule->min_swap_area,
85 pModule->expected_version );
86 if (pModule->flags & NE_FFLAGS_WIN32)
87 DPRINTF( "PE module=%08x\n", pModule->module32 );
89 /* Dump the file info */
91 DPRINTF( "Filename: '%s'\n", NE_MODULE_NAME(pModule) );
93 /* Dump the segment table */
95 DPRINTF( "Segment table:\n" );
96 pSeg = NE_SEG_TABLE( pModule );
97 for (i = 0; i < pModule->seg_count; i++, pSeg++)
98 DPRINTF( "%02x: pos=%d size=%d flags=%04x minsize=%d hSeg=%04x\n",
99 i + 1, pSeg->filepos, pSeg->size, pSeg->flags,
100 pSeg->minsize, pSeg->hSeg );
102 /* Dump the resource table */
104 DPRINTF( "Resource table:\n" );
105 if (pModule->res_table)
107 pword = (WORD *)((BYTE *)pModule + pModule->res_table);
108 DPRINTF( "Alignment: %d\n", *pword++ );
111 struct resource_typeinfo_s *ptr = (struct resource_typeinfo_s *)pword;
112 struct resource_nameinfo_s *pname = (struct resource_nameinfo_s *)(ptr + 1);
113 DPRINTF( "id=%04x count=%d\n", ptr->type_id, ptr->count );
114 for (i = 0; i < ptr->count; i++, pname++)
115 DPRINTF( "offset=%d len=%d id=%04x\n",
116 pname->offset, pname->length, pname->id );
117 pword = (WORD *)pname;
120 else DPRINTF( "None\n" );
122 /* Dump the resident name table */
124 DPRINTF( "Resident-name table:\n" );
125 pstr = (char *)pModule + pModule->name_table;
128 DPRINTF( "%*.*s: %d\n", *pstr, *pstr, pstr + 1,
129 *(WORD *)(pstr + *pstr + 1) );
130 pstr += *pstr + 1 + sizeof(WORD);
133 /* Dump the module reference table */
135 DPRINTF( "Module ref table:\n" );
136 if (pModule->modref_table)
138 pword = (WORD *)((BYTE *)pModule + pModule->modref_table);
139 for (i = 0; i < pModule->modref_count; i++, pword++)
142 GetModuleName16( *pword, name, sizeof(name) );
143 DPRINTF( "%d: %04x -> '%s'\n", i, *pword, name );
146 else DPRINTF( "None\n" );
148 /* Dump the entry table */
150 DPRINTF( "Entry table:\n" );
151 bundle = (ET_BUNDLE *)((BYTE *)pModule+pModule->entry_table);
153 entry = (ET_ENTRY *)((BYTE *)bundle+6);
154 DPRINTF( "Bundle %d-%d: %02x\n", bundle->first, bundle->last, entry->type);
155 ordinal = bundle->first;
156 while (ordinal < bundle->last)
158 if (entry->type == 0xff)
159 DPRINTF("%d: %02x:%04x (moveable)\n", ordinal++, entry->segnum, entry->offs);
161 DPRINTF("%d: %02x:%04x (fixed)\n", ordinal++, entry->segnum, entry->offs);
164 } while ( (bundle->next)
165 && (bundle = ((ET_BUNDLE *)((BYTE *)pModule + bundle->next))) );
167 /* Dump the non-resident names table */
169 DPRINTF( "Non-resident names table:\n" );
170 if (pModule->nrname_handle)
172 pstr = (char *)GlobalLock16( pModule->nrname_handle );
175 DPRINTF( "%*.*s: %d\n", *pstr, *pstr, pstr + 1,
176 *(WORD *)(pstr + *pstr + 1) );
177 pstr += *pstr + 1 + sizeof(WORD);
184 /***********************************************************************
187 * Walk the module list and print the modules.
189 void NE_WalkModules(void)
191 HMODULE16 hModule = hFirstModule;
192 MESSAGE( "Module Flags Name\n" );
195 NE_MODULE *pModule = NE_GetPtr( hModule );
198 MESSAGE( "Bad module %04x in list\n", hModule );
201 MESSAGE( " %04x %04x %.*s\n", hModule, pModule->flags,
202 *((char *)pModule + pModule->name_table),
203 (char *)pModule + pModule->name_table + 1 );
204 hModule = pModule->next;
209 /**********************************************************************
212 void NE_RegisterModule( NE_MODULE *pModule )
214 pModule->next = hFirstModule;
215 hFirstModule = pModule->self;
219 /***********************************************************************
222 * Lookup the ordinal for a given name.
224 WORD NE_GetOrdinal( HMODULE16 hModule, const char *name )
226 unsigned char buffer[256], *cpnt;
230 if (!(pModule = NE_GetPtr( hModule ))) return 0;
231 assert( !(pModule->flags & NE_FFLAGS_WIN32) );
233 TRACE("(%04x,'%s')\n", hModule, name );
235 /* First handle names of the form '#xxxx' */
237 if (name[0] == '#') return atoi( name + 1 );
239 /* Now copy and uppercase the string */
241 strcpy( buffer, name );
242 CharUpperA( buffer );
243 len = strlen( buffer );
245 /* First search the resident names */
247 cpnt = (char *)pModule + pModule->name_table;
249 /* Skip the first entry (module name) */
250 cpnt += *cpnt + 1 + sizeof(WORD);
253 if (((BYTE)*cpnt == len) && !memcmp( cpnt+1, buffer, len ))
255 TRACE(" Found: ordinal=%d\n",
256 *(WORD *)(cpnt + *cpnt + 1) );
257 return *(WORD *)(cpnt + *cpnt + 1);
259 cpnt += *cpnt + 1 + sizeof(WORD);
262 /* Now search the non-resident names table */
264 if (!pModule->nrname_handle) return 0; /* No non-resident table */
265 cpnt = (char *)GlobalLock16( pModule->nrname_handle );
267 /* Skip the first entry (module description string) */
268 cpnt += *cpnt + 1 + sizeof(WORD);
271 if (((BYTE)*cpnt == len) && !memcmp( cpnt+1, buffer, len ))
273 TRACE(" Found: ordinal=%d\n",
274 *(WORD *)(cpnt + *cpnt + 1) );
275 return *(WORD *)(cpnt + *cpnt + 1);
277 cpnt += *cpnt + 1 + sizeof(WORD);
283 /***********************************************************************
284 * NE_GetEntryPoint (WPROCS.27)
286 * Return the entry point for a given ordinal.
288 FARPROC16 WINAPI WIN16_NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal )
290 FARPROC16 ret = NE_GetEntryPointEx( hModule, ordinal, TRUE );
291 CURRENT_STACK16->ecx = hModule; /* FIXME: might be incorrect value */
294 FARPROC16 WINAPI NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal )
296 return NE_GetEntryPointEx( hModule, ordinal, TRUE );
298 FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, BOOL16 snoop )
306 if (!(pModule = NE_GetPtr( hModule ))) return 0;
307 assert( !(pModule->flags & NE_FFLAGS_WIN32) );
309 bundle = (ET_BUNDLE *)((BYTE *)pModule + pModule->entry_table);
310 while ((ordinal < bundle->first + 1) || (ordinal > bundle->last))
314 bundle = (ET_BUNDLE *)((BYTE *)pModule + bundle->next);
317 entry = (ET_ENTRY *)((BYTE *)bundle+6);
318 for (i=0; i < (ordinal - bundle->first - 1); i++)
322 offset = entry->offs;
324 if (sel == 0xfe) sel = 0xffff; /* constant entry */
325 else sel = GlobalHandleToSel16(NE_SEG_TABLE(pModule)[sel-1].hSeg);
327 return (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( sel, offset );
329 return (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( sel, offset );
331 return (FARPROC16)SNOOP16_GetProcAddress16(hModule,ordinal,(FARPROC16)PTR_SEG_OFF_TO_SEGPTR( sel, offset ));
335 /***********************************************************************
338 * Change the value of an entry point. Use with caution!
339 * It can only change the offset value, not the selector.
341 BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset )
348 if (!(pModule = NE_GetPtr( hModule ))) return FALSE;
349 assert( !(pModule->flags & NE_FFLAGS_WIN32) );
351 bundle = (ET_BUNDLE *)((BYTE *)pModule + pModule->entry_table);
352 while ((ordinal < bundle->first + 1) || (ordinal > bundle->last))
354 bundle = (ET_BUNDLE *)((BYTE *)pModule + bundle->next);
359 entry = (ET_ENTRY *)((BYTE *)bundle+6);
360 for (i=0; i < (ordinal - bundle->first - 1); i++)
363 entry->offs = offset;
368 /***********************************************************************
371 HANDLE NE_OpenFile( NE_MODULE *pModule )
375 static HANDLE cachedfd = -1;
377 TRACE("(%p) cache: mod=%p fd=%d\n",
378 pModule, pCachedModule, cachedfd );
379 if (pCachedModule == pModule) return cachedfd;
380 CloseHandle( cachedfd );
381 pCachedModule = pModule;
382 name = NE_MODULE_NAME( pModule );
383 if ((cachedfd = CreateFileA( name, GENERIC_READ, FILE_SHARE_READ,
384 NULL, OPEN_EXISTING, 0, -1 )) == -1)
385 MESSAGE( "Can't open file '%s' for module %04x\n", name, pModule->self );
387 /* FIXME: should not be necessary */
388 cachedfd = ConvertToGlobalHandle(cachedfd);
389 TRACE("opened '%s' -> %d\n",
395 /***********************************************************************
398 static HMODULE16 NE_LoadExeHeader( LPCSTR filename )
400 IMAGE_DOS_HEADER mz_header;
401 IMAGE_OS2_HEADER ne_header;
405 BYTE *pData, *pTempEntryTable;
406 char *buffer, *fastload = NULL;
407 int fastload_offset = 0, fastload_length = 0;
409 ET_BUNDLE *bundle, *oldbundle;
414 if ((hFile = OpenFile16( filename, &ofs, OF_READ )) == HFILE_ERROR16)
415 return (HMODULE16)2; /* File not found */
417 /* Read a block from either the file or the fast-load area. */
418 #define READ(offset,size,buffer) \
419 ((fastload && ((offset) >= fastload_offset) && \
420 ((offset)+(size) <= fastload_offset+fastload_length)) ? \
421 (memcpy( buffer, fastload+(offset)-fastload_offset, (size) ), TRUE) : \
422 (_llseek16( hFile, (offset), SEEK_SET), \
423 _hread16( hFile, (buffer), (size) ) == (size)))
425 _llseek16( hFile, 0, SEEK_SET );
426 if ((_hread16(hFile,&mz_header,sizeof(mz_header)) != sizeof(mz_header)) ||
427 (mz_header.e_magic != IMAGE_DOS_SIGNATURE))
430 return (HMODULE16)11; /* invalid exe */
433 _llseek16( hFile, mz_header.e_lfanew, SEEK_SET );
434 if (_hread16( hFile, &ne_header, sizeof(ne_header) ) != sizeof(ne_header))
437 return (HMODULE16)11; /* invalid exe */
440 if (ne_header.ne_magic == IMAGE_NT_SIGNATURE) return (HMODULE16)21; /* win32 exe */
441 if (ne_header.ne_magic != IMAGE_OS2_SIGNATURE) return (HMODULE16)11; /* invalid exe */
443 if (ne_header.ne_magic == IMAGE_OS2_SIGNATURE_LX) {
444 MESSAGE("Sorry, this is an OS/2 linear executable (LX) file !\n");
446 return (HMODULE16)12;
449 /* We now have a valid NE header */
451 size = sizeof(NE_MODULE) +
453 ne_header.n_segment_tab * sizeof(SEGTABLEENTRY) +
455 ne_header.rname_tab_offset - ne_header.resource_tab_offset +
456 /* resident names table */
457 ne_header.moduleref_tab_offset - ne_header.rname_tab_offset +
458 /* module ref table */
459 ne_header.n_mod_ref_tab * sizeof(WORD) +
460 /* imported names table */
461 ne_header.entry_tab_offset - ne_header.iname_tab_offset +
462 /* entry table length */
463 ne_header.entry_tab_length +
464 /* entry table extra conversion space */
466 2 * (ne_header.entry_tab_length - ne_header.n_mov_entry_points*6) +
467 /* loaded file info */
468 sizeof(OFSTRUCT)-sizeof(ofs.szPathName)+strlen(ofs.szPathName)+1;
470 hModule = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT, size );
474 return (HMODULE16)11; /* invalid exe */
477 FarSetOwner16( hModule, hModule );
478 pModule = (NE_MODULE *)GlobalLock16( hModule );
479 memcpy( pModule, &ne_header, sizeof(ne_header) );
481 /* check *programs* for default minimal stack size */
482 if ( (!(pModule->flags & NE_FFLAGS_LIBMODULE))
483 && (pModule->stack_size < 0x1400) )
484 pModule->stack_size = 0x1400;
485 pModule->module32 = 0;
486 pModule->self = hModule;
487 pModule->self_loading_sel = 0;
488 pData = (BYTE *)(pModule + 1);
490 /* Clear internal Wine flags in case they are set in the EXE file */
492 pModule->flags &= ~(NE_FFLAGS_BUILTIN | NE_FFLAGS_WIN32);
494 /* Read the fast-load area */
496 if (ne_header.additional_flags & NE_AFLAGS_FASTLOAD)
498 fastload_offset=ne_header.fastload_offset<<ne_header.align_shift_count;
499 fastload_length=ne_header.fastload_length<<ne_header.align_shift_count;
500 TRACE("Using fast-load area offset=%x len=%d\n",
501 fastload_offset, fastload_length );
502 if ((fastload = HeapAlloc( GetProcessHeap(), 0, fastload_length )) != NULL)
504 _llseek16( hFile, fastload_offset, SEEK_SET);
505 if (_hread16(hFile, fastload, fastload_length) != fastload_length)
507 HeapFree( GetProcessHeap(), 0, fastload );
508 WARN("Error reading fast-load area!\n");
514 /* Get the segment table */
516 pModule->seg_table = (int)pData - (int)pModule;
517 buffer = HeapAlloc( GetProcessHeap(), 0, ne_header.n_segment_tab *
518 sizeof(struct ne_segment_table_entry_s));
522 struct ne_segment_table_entry_s *pSeg;
524 if (!READ( mz_header.e_lfanew + ne_header.segment_tab_offset,
525 ne_header.n_segment_tab * sizeof(struct ne_segment_table_entry_s),
528 HeapFree( GetProcessHeap(), 0, buffer );
530 HeapFree( GetProcessHeap(), 0, fastload );
531 GlobalFree16( hModule );
533 return (HMODULE16)11; /* invalid exe */
535 pSeg = (struct ne_segment_table_entry_s *)buffer;
536 for (i = ne_header.n_segment_tab; i > 0; i--, pSeg++)
538 memcpy( pData, pSeg, sizeof(*pSeg) );
539 pData += sizeof(SEGTABLEENTRY);
541 HeapFree( GetProcessHeap(), 0, buffer );
546 HeapFree( GetProcessHeap(), 0, fastload );
547 GlobalFree16( hModule );
549 return (HMODULE16)11; /* invalid exe */
552 /* Get the resource table */
554 if (ne_header.resource_tab_offset < ne_header.rname_tab_offset)
556 pModule->res_table = (int)pData - (int)pModule;
557 if (!READ(mz_header.e_lfanew + ne_header.resource_tab_offset,
558 ne_header.rname_tab_offset - ne_header.resource_tab_offset,
562 return (HMODULE16)11; /* invalid exe */
564 pData += ne_header.rname_tab_offset - ne_header.resource_tab_offset;
565 NE_InitResourceHandler( hModule );
567 else pModule->res_table = 0; /* No resource table */
569 /* Get the resident names table */
571 pModule->name_table = (int)pData - (int)pModule;
572 if (!READ( mz_header.e_lfanew + ne_header.rname_tab_offset,
573 ne_header.moduleref_tab_offset - ne_header.rname_tab_offset,
577 HeapFree( GetProcessHeap(), 0, fastload );
578 GlobalFree16( hModule );
580 return (HMODULE16)11; /* invalid exe */
582 pData += ne_header.moduleref_tab_offset - ne_header.rname_tab_offset;
584 /* Get the module references table */
586 if (ne_header.n_mod_ref_tab > 0)
588 pModule->modref_table = (int)pData - (int)pModule;
589 if (!READ( mz_header.e_lfanew + ne_header.moduleref_tab_offset,
590 ne_header.n_mod_ref_tab * sizeof(WORD),
594 HeapFree( GetProcessHeap(), 0, fastload );
595 GlobalFree16( hModule );
597 return (HMODULE16)11; /* invalid exe */
599 pData += ne_header.n_mod_ref_tab * sizeof(WORD);
601 else pModule->modref_table = 0; /* No module references */
603 /* Get the imported names table */
605 pModule->import_table = (int)pData - (int)pModule;
606 if (!READ( mz_header.e_lfanew + ne_header.iname_tab_offset,
607 ne_header.entry_tab_offset - ne_header.iname_tab_offset,
611 HeapFree( GetProcessHeap(), 0, fastload );
612 GlobalFree16( hModule );
614 return (HMODULE16)11; /* invalid exe */
616 pData += ne_header.entry_tab_offset - ne_header.iname_tab_offset;
618 /* Load entry table, convert it to the optimized version used by Windows */
620 if ((pTempEntryTable = HeapAlloc( GetProcessHeap(), 0, ne_header.entry_tab_length)) != NULL)
622 BYTE nr_entries, type, *s;
624 TRACE("Converting entry table.\n");
625 pModule->entry_table = (int)pData - (int)pModule;
626 if (!READ( mz_header.e_lfanew + ne_header.entry_tab_offset,
627 ne_header.entry_tab_length, pTempEntryTable ))
629 HeapFree( GetProcessHeap(), 0, pTempEntryTable );
631 HeapFree( GetProcessHeap(), 0, fastload );
632 GlobalFree16( hModule );
634 return (HMODULE16)11; /* invalid exe */
638 TRACE("entry table: offs %04x, len %04x, entries %d\n", ne_header.entry_tab_offset, ne_header.entry_tab_length, *s);
640 bundle = (ET_BUNDLE *)pData;
641 TRACE("first bundle: %p\n", bundle);
642 memset(bundle, 0, sizeof(ET_BUNDLE)); /* in case no entry table exists */
643 entry = (ET_ENTRY *)((BYTE *)bundle+6);
645 while ((nr_entries = *s++))
649 bundle->last += nr_entries;
656 entry->segnum = *s++;
657 entry->offs = *(WORD *)s; s += 2;
658 /*TRACE(module, "entry: %p, type: %d, flags: %d, segnum: %d, offs: %04x\n", entry, entry->type, entry->flags, entry->segnum, entry->offs);*/
666 entry->segnum = type;
667 entry->offs = *(WORD *)s; s += 2;
668 /*TRACE(module, "entry: %p, type: %d, flags: %d, segnum: %d, offs: %04x\n", entry, entry->type, entry->flags, entry->segnum, entry->offs);*/
674 if (bundle->first == bundle->last)
676 bundle->first += nr_entries;
677 bundle->last += nr_entries;
682 oldbundle->next = ((int)entry - (int)pModule);
683 bundle = (ET_BUNDLE *)entry;
684 TRACE("new bundle: %p\n", bundle);
685 bundle->first = bundle->last =
686 oldbundle->last + nr_entries;
688 (BYTE *)entry += sizeof(ET_BUNDLE);
692 HeapFree( GetProcessHeap(), 0, pTempEntryTable );
697 HeapFree( GetProcessHeap(), 0, fastload );
698 GlobalFree16( hModule );
700 return (HMODULE16)11; /* invalid exe */
703 pData += ne_header.entry_tab_length + sizeof(ET_BUNDLE) +
704 2 * (ne_header.entry_tab_length - ne_header.n_mov_entry_points*6);
706 if ((DWORD)entry > (DWORD)pData)
707 ERR("converted entry table bigger than reserved space !!!\nentry: %p, pData: %p. Please report !\n", entry, pData);
709 /* Store the filename information */
711 pModule->fileinfo = (int)pData - (int)pModule;
712 size = sizeof(OFSTRUCT)-sizeof(ofs.szPathName)+strlen(ofs.szPathName)+1;
713 ofs.cBytes = size - 1;
714 memcpy( pData, &ofs, size );
717 /* Free the fast-load area */
721 HeapFree( GetProcessHeap(), 0, fastload );
723 /* Get the non-resident names table */
725 if (ne_header.nrname_tab_length)
727 pModule->nrname_handle = GLOBAL_Alloc( 0, ne_header.nrname_tab_length,
728 hModule, FALSE, FALSE, FALSE );
729 if (!pModule->nrname_handle)
731 GlobalFree16( hModule );
733 return (HMODULE16)11; /* invalid exe */
735 buffer = GlobalLock16( pModule->nrname_handle );
736 _llseek16( hFile, ne_header.nrname_tab_offset, SEEK_SET );
737 if (_hread16( hFile, buffer, ne_header.nrname_tab_length )
738 != ne_header.nrname_tab_length)
740 GlobalFree16( pModule->nrname_handle );
741 GlobalFree16( hModule );
743 return (HMODULE16)11; /* invalid exe */
746 else pModule->nrname_handle = 0;
748 /* Allocate a segment for the implicitly-loaded DLLs */
750 if (pModule->modref_count)
752 pModule->dlls_to_init = GLOBAL_Alloc(GMEM_ZEROINIT,
753 (pModule->modref_count+1)*sizeof(HMODULE16),
754 hModule, FALSE, FALSE, FALSE );
755 if (!pModule->dlls_to_init)
757 if (pModule->nrname_handle) GlobalFree16( pModule->nrname_handle );
758 GlobalFree16( hModule );
760 return (HMODULE16)11; /* invalid exe */
763 else pModule->dlls_to_init = 0;
765 NE_RegisterModule( pModule );
766 SNOOP16_RegisterDLL(pModule,ofs.szPathName);
773 /***********************************************************************
776 * Load all DLLs implicitly linked to a module.
778 static BOOL NE_LoadDLLs( NE_MODULE *pModule )
781 WORD *pModRef = (WORD *)((char *)pModule + pModule->modref_table);
782 WORD *pDLLs = (WORD *)GlobalLock16( pModule->dlls_to_init );
784 for (i = 0; i < pModule->modref_count; i++, pModRef++)
786 char buffer[260], *p;
787 BYTE *pstr = (BYTE *)pModule + pModule->import_table + *pModRef;
788 memcpy( buffer, pstr + 1, *pstr );
789 *(buffer + *pstr) = 0; /* terminate it */
791 TRACE("Loading '%s'\n", buffer );
792 if (!(*pModRef = GetModuleHandle16( buffer )))
794 /* If the DLL is not loaded yet, load it and store */
795 /* its handle in the list of DLLs to initialize. */
798 /* Append .DLL to name if no extension present */
799 if (!(p = strrchr( buffer, '.')) || strchr( p, '/' ) || strchr( p, '\\'))
800 strcat( buffer, ".DLL" );
802 if ((hDLL = MODULE_LoadModule16( buffer, TRUE, TRUE )) < 32)
804 /* FIXME: cleanup what was done */
806 MESSAGE( "Could not load '%s' required by '%.*s', error=%d\n",
807 buffer, *((BYTE*)pModule + pModule->name_table),
808 (char *)pModule + pModule->name_table + 1, hDLL );
811 *pModRef = GetExePtr( hDLL );
814 else /* Increment the reference count of the DLL */
818 pOldDLL = NE_GetPtr( *pModRef );
819 if (pOldDLL) pOldDLL->count++;
826 /**********************************************************************
829 * Load first instance of NE module from file.
831 * pModule must point to a module structure prepared by NE_LoadExeHeader.
832 * This routine must never be called twice on a module.
835 static HINSTANCE16 NE_DoLoadModule( NE_MODULE *pModule )
837 /* Allocate the segments for this module */
839 if (!NE_CreateAllSegments( pModule ))
840 return ERROR_NOT_ENOUGH_MEMORY; /* 8 */
842 /* Load the referenced DLLs */
844 if (!NE_LoadDLLs( pModule ))
845 return ERROR_FILE_NOT_FOUND; /* 2 */
847 /* Load the segments */
849 NE_LoadAllSegments( pModule );
851 /* Make sure the usage count is 1 on the first loading of */
852 /* the module, even if it contains circular DLL references */
856 return NE_GetInstance( pModule );
859 /**********************************************************************
862 * Load first instance of NE module. (Note: caller is responsible for
863 * ensuring the module isn't already loaded!)
865 * If the module turns out to be an executable module, only a
866 * handle to a module stub is returned; this needs to be initialized
867 * by calling NE_DoLoadModule later, in the context of the newly
870 * If lib_only is TRUE, however, the module is perforce treated
871 * like a DLL module, even if it is an executable module.
874 static HINSTANCE16 NE_LoadModule( LPCSTR name, BOOL lib_only )
878 HINSTANCE16 hInstance;
880 hModule = NE_LoadExeHeader( name );
881 if (hModule < 32) return hModule;
883 pModule = NE_GetPtr( hModule );
884 if ( !pModule ) return hModule;
886 if ( !lib_only && !( pModule->flags & NE_FFLAGS_LIBMODULE ) )
889 hInstance = NE_DoLoadModule( pModule );
890 if ( hInstance < 32 )
893 NE_FreeModule( hModule, 0 );
900 /**********************************************************************
901 * MODULE_LoadModule16
903 * Load a NE module in the order of the loadorder specification.
904 * The caller is responsible that the module is not loaded already.
907 static HINSTANCE16 MODULE_LoadModule16( LPCSTR libname, BOOL implicit, BOOL lib_only )
911 module_loadorder_t *plo;
913 plo = MODULE_GetLoadOrder(libname);
915 for(i = 0; i < MODULE_LOADORDER_NTYPES; i++)
917 switch(plo->loadorder[i])
919 case MODULE_LOADORDER_DLL:
920 TRACE("Trying native dll '%s'\n", libname);
921 hinst = NE_LoadModule(libname, lib_only);
924 case MODULE_LOADORDER_ELFDLL:
925 TRACE("Trying elfdll '%s'\n", libname);
926 hinst = ELFDLL_LoadModule16(libname);
929 case MODULE_LOADORDER_BI:
930 TRACE("Trying built-in '%s'\n", libname);
931 hinst = BUILTIN_LoadModule(libname);
935 ERR("Got invalid loadorder type %d (%s index %d)\n", plo->loadorder[i], plo->modulename, i);
938 case MODULE_LOADORDER_SO: /* This is not supported for NE modules */
939 case MODULE_LOADORDER_INVALID: /* We ignore this as it is an empty entry */
951 hModule = GetModuleHandle16(libname);
954 ERR("Serious trouble. Just loaded module '%s' (hinst=0x%04x), but can't get module handle\n",
956 return 6; /* ERROR_INVALID_HANDLE seems most appropriate */
959 pModule = NE_GetPtr(hModule);
962 ERR("Serious trouble. Just loaded module '%s' (hinst=0x%04x), but can't get NE_MODULE pointer\n",
964 return 6; /* ERROR_INVALID_HANDLE seems most appropriate */
967 TRACE("Loaded module '%s' at 0x%04x, \n", libname, hinst);
970 * Call initialization routines for all loaded DLLs. Note that
971 * when we load implicitly linked DLLs this will be done by InitTask().
973 if(pModule->flags & NE_FFLAGS_LIBMODULE)
975 NE_InitializeDLLs(hModule);
976 NE_DllProcessAttach(hModule);
984 /* We quit searching when we get another error than 'File not found' */
988 return hinst; /* The last error that occured */
992 /**********************************************************************
993 * LoadModule16 (KERNEL.45)
995 HINSTANCE16 WINAPI LoadModule16( LPCSTR name, LPVOID paramBlock )
997 BOOL lib_only = !paramBlock || (paramBlock == (LPVOID)-1);
998 LOADPARAMS16 *params;
999 LPSTR cmd_line, new_cmd_line;
1001 STARTUPINFOA startup;
1002 PROCESS_INFORMATION info;
1009 if ( (hModule = NE_GetModuleByFilename(name) ) != 0 )
1011 /* Special case: second instance of an already loaded NE module */
1013 if ( !( pModule = NE_GetPtr( hModule ) ) ) return (HINSTANCE16)11;
1014 if ( pModule->module32 ) return (HINSTANCE16)21;
1016 /* Increment refcount */
1022 /* Main case: load first instance of NE module */
1024 if ( (hModule = MODULE_LoadModule16( name, FALSE, lib_only )) < 32 )
1027 if ( !(pModule = NE_GetPtr( hModule )) )
1028 return (HINSTANCE16)11;
1031 /* If library module, we just retrieve the instance handle */
1033 if ( ( pModule->flags & NE_FFLAGS_LIBMODULE ) || lib_only )
1034 return NE_GetInstance( pModule );
1037 * At this point, we need to create a new process.
1039 * pModule points either to an already loaded module, whose refcount
1040 * has already been incremented (to avoid having the module vanish
1041 * in the meantime), or else to a stub module which contains only header
1044 * All remaining initialization (really loading the module in the second
1045 * case, and creating the new instance in both cases) are to be done in
1046 * the context of the new process. This happens in the NE_InitProcess
1047 * routine, which will be called from the 32-bit process initialization.
1051 params = (LOADPARAMS16 *)paramBlock;
1052 cmd_line = (LPSTR)PTR_SEG_TO_LIN( params->cmdLine );
1053 if (!cmd_line) cmd_line = "";
1054 else if (*cmd_line) cmd_line++; /* skip the length byte */
1056 if (!(new_cmd_line = HeapAlloc( GetProcessHeap(), 0,
1057 strlen(cmd_line)+strlen(name)+2 )))
1059 strcpy( new_cmd_line, name );
1060 strcat( new_cmd_line, " " );
1061 strcat( new_cmd_line, cmd_line );
1063 if (params->hEnvironment) env = GlobalLock16( params->hEnvironment );
1065 memset( &info, '\0', sizeof(info) );
1066 memset( &startup, '\0', sizeof(startup) );
1067 startup.cb = sizeof(startup);
1068 if (params->showCmd)
1070 startup.dwFlags = STARTF_USESHOWWINDOW;
1071 startup.wShowWindow = ((UINT16 *)PTR_SEG_TO_LIN(params->showCmd))[1];
1074 SYSLEVEL_ReleaseWin16Lock();
1075 pdb = PROCESS_Create( pModule, -1, new_cmd_line, env,
1076 NULL, NULL, TRUE, 0, &startup, &info );
1077 SYSLEVEL_RestoreWin16Lock();
1079 CloseHandle( info.hThread );
1080 CloseHandle( info.hProcess );
1082 if (params->hEnvironment) GlobalUnlock16( params->hEnvironment );
1083 HeapFree( GetProcessHeap(), 0, new_cmd_line );
1085 return GetProcessDword( info.dwProcessId, GPD_HINSTANCE16 );
1088 /**********************************************************************
1091 BOOL NE_CreateProcess( HANDLE hFile, LPCSTR filename, LPCSTR cmd_line, LPCSTR env,
1092 LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
1093 BOOL inherit, DWORD flags, LPSTARTUPINFOA startup,
1094 LPPROCESS_INFORMATION info )
1099 SYSLEVEL_EnterWin16Lock();
1101 /* Special case: second instance of an already loaded NE module */
1103 if ( ( hModule = NE_GetModuleByFilename( filename ) ) != 0 )
1105 if ( !( pModule = NE_GetPtr( hModule) )
1106 || ( pModule->flags & NE_FFLAGS_LIBMODULE )
1107 || pModule->module32 )
1109 SetLastError( ERROR_BAD_FORMAT );
1116 /* Main case: load first instance of NE module */
1121 hModule = NE_LoadExeHeader( filename );
1124 SetLastError( hModule );
1128 if ( !( pModule = NE_GetPtr( hModule ) )
1129 || ( pModule->flags & NE_FFLAGS_LIBMODULE) )
1131 GlobalFreeAll16( hModule );
1132 SetLastError( ERROR_BAD_FORMAT );
1137 SYSLEVEL_LeaveWin16Lock();
1139 if ( !PROCESS_Create( pModule, hFile, cmd_line, env,
1140 psa, tsa, inherit, flags, startup, info ) )
1146 SYSLEVEL_LeaveWin16Lock();
1150 /**********************************************************************
1153 BOOL NE_InitProcess( NE_MODULE *pModule )
1155 HINSTANCE16 hInstance, hPrevInstance;
1158 SEGTABLEENTRY *pSegTable = NE_SEG_TABLE( pModule );
1162 SYSLEVEL_EnterWin16Lock();
1164 if ( pModule->count > 0 )
1166 /* Second instance of an already loaded NE module */
1167 /* Note that the refcount was already incremented by the parent */
1169 hPrevInstance = NE_GetInstance( pModule );
1171 if ( pModule->dgroup )
1172 if ( NE_CreateSegment( pModule, pModule->dgroup ) )
1173 NE_LoadSegment( pModule, pModule->dgroup );
1175 hInstance = NE_GetInstance( pModule );
1179 /* Load first instance of NE module */
1181 pModule->flags |= NE_FFLAGS_GUI; /* FIXME: is this necessary? */
1183 hInstance = NE_DoLoadModule( pModule );
1187 if ( hInstance < 32 )
1189 SYSLEVEL_LeaveWin16Lock();
1191 SetLastError( hInstance );
1195 /* Enter instance handles into task struct */
1197 pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1198 pTask->hInstance = hInstance;
1199 pTask->hPrevInstance = hPrevInstance;
1201 /* Use DGROUP for 16-bit stack */
1203 if (!(sp = pModule->sp))
1204 sp = pSegTable[pModule->ss-1].minsize + pModule->stack_size;
1205 sp &= ~1; sp -= sizeof(STACK16FRAME);
1206 pTask->teb->cur_stack = PTR_SEG_OFF_TO_SEGPTR( hInstance, sp );
1208 SYSLEVEL_LeaveWin16Lock();
1213 /***********************************************************************
1214 * LoadLibrary16 (KERNEL.95)
1216 HINSTANCE16 WINAPI LoadLibrary16( LPCSTR libname )
1218 return LoadModule16(libname, (LPVOID)-1 );
1222 /**********************************************************************
1225 * Call a DLL's WEP, allowing it to shut down.
1226 * FIXME: we always pass the WEP WEP_FREE_DLL, never WEP_SYSTEM_EXIT
1228 static BOOL16 MODULE_CallWEP( HMODULE16 hModule )
1230 FARPROC16 WEP = (FARPROC16)0;
1231 WORD ordinal = NE_GetOrdinal( hModule, "WEP" );
1233 if (ordinal) WEP = NE_GetEntryPoint( hModule, ordinal );
1236 WARN("module %04x doesn't have a WEP\n", hModule );
1239 return Callbacks->CallWindowsExitProc( WEP, WEP_FREE_DLL );
1243 /**********************************************************************
1246 * Implementation of FreeModule16().
1248 static BOOL16 NE_FreeModule( HMODULE16 hModule, BOOL call_wep )
1250 HMODULE16 *hPrevModule;
1255 if (!(pModule = NE_GetPtr( hModule ))) return FALSE;
1256 hModule = pModule->self;
1258 TRACE("%04x count %d\n", hModule, pModule->count );
1260 if (((INT16)(--pModule->count)) > 0 ) return TRUE;
1261 else pModule->count = 0;
1263 if (pModule->flags & NE_FFLAGS_BUILTIN)
1264 return FALSE; /* Can't free built-in module */
1266 if (call_wep && !(pModule->flags & NE_FFLAGS_WIN32))
1268 if (pModule->flags & NE_FFLAGS_LIBMODULE)
1270 MODULE_CallWEP( hModule );
1272 /* Free the objects owned by the DLL module */
1273 TASK_CallTaskSignalProc( USIG16_DLL_UNLOAD, hModule );
1274 PROCESS_CallUserSignalProc( USIG_DLL_UNLOAD_WIN16, 0, hModule );
1277 call_wep = FALSE; /* We are freeing a task -> no more WEPs */
1281 /* Clear magic number just in case */
1283 pModule->magic = pModule->self = 0;
1285 /* Remove it from the linked list */
1287 hPrevModule = &hFirstModule;
1288 while (*hPrevModule && (*hPrevModule != hModule))
1290 hPrevModule = &(NE_GetPtr( *hPrevModule ))->next;
1292 if (*hPrevModule) *hPrevModule = pModule->next;
1294 /* Free the referenced modules */
1296 pModRef = (HMODULE16*)NE_MODULE_TABLE( pModule );
1297 for (i = 0; i < pModule->modref_count; i++, pModRef++)
1299 NE_FreeModule( *pModRef, call_wep );
1302 /* Free the module storage */
1304 GlobalFreeAll16( hModule );
1306 /* Remove module from cache */
1308 if (pCachedModule == pModule) pCachedModule = NULL;
1313 /**********************************************************************
1314 * FreeModule16 (KERNEL.46)
1316 BOOL16 WINAPI FreeModule16( HMODULE16 hModule )
1318 return NE_FreeModule( hModule, TRUE );
1322 /***********************************************************************
1323 * FreeLibrary16 (KERNEL.96)
1325 void WINAPI FreeLibrary16( HINSTANCE16 handle )
1327 TRACE("%04x\n", handle );
1328 FreeModule16( handle );
1332 /**********************************************************************
1333 * GetModuleName (KERNEL.27)
1335 BOOL16 WINAPI GetModuleName16( HINSTANCE16 hinst, LPSTR buf, INT16 count )
1340 if (!(pModule = NE_GetPtr( hinst ))) return FALSE;
1341 p = (BYTE *)pModule + pModule->name_table;
1342 if (count > *p) count = *p + 1;
1345 memcpy( buf, p + 1, count - 1 );
1346 buf[count-1] = '\0';
1352 /**********************************************************************
1353 * GetModuleUsage (KERNEL.48)
1355 INT16 WINAPI GetModuleUsage16( HINSTANCE16 hModule )
1357 NE_MODULE *pModule = NE_GetPtr( hModule );
1358 return pModule ? pModule->count : 0;
1362 /**********************************************************************
1363 * GetExpWinVer (KERNEL.167)
1365 WORD WINAPI GetExpWinVer16( HMODULE16 hModule )
1367 NE_MODULE *pModule = NE_GetPtr( hModule );
1368 if ( !pModule ) return 0;
1371 * For built-in modules, fake the expected version the module should
1372 * have according to the Windows version emulated by Wine
1374 if ( !pModule->expected_version )
1376 OSVERSIONINFOA versionInfo;
1377 versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
1379 if ( GetVersionExA( &versionInfo ) )
1380 pModule->expected_version =
1381 (versionInfo.dwMajorVersion & 0xff) << 8
1382 | (versionInfo.dwMinorVersion & 0xff);
1385 return pModule->expected_version;
1389 /**********************************************************************
1390 * GetModuleFileName16 (KERNEL.49)
1392 INT16 WINAPI GetModuleFileName16( HINSTANCE16 hModule, LPSTR lpFileName,
1397 if (!hModule) hModule = GetCurrentTask();
1398 if (!(pModule = NE_GetPtr( hModule ))) return 0;
1399 lstrcpynA( lpFileName, NE_MODULE_NAME(pModule), nSize );
1400 TRACE("%s\n", lpFileName );
1401 return strlen(lpFileName);
1405 /**********************************************************************
1406 * GetModuleHandle16 (KERNEL.47)
1408 * Find a module from a module name.
1410 * NOTE: The current implementation works the same way the Windows 95 one
1411 * does. Do not try to 'fix' it, fix the callers.
1412 * + It does not do ANY extension handling (except that strange .EXE bit)!
1413 * + It does not care about paths, just about basenames. (same as Windows)
1417 * the win16 module handle if found
1419 * HIWORD (undocumented, see "Undocumented Windows", chapter 5):
1420 * Always hFirstModule
1422 DWORD WINAPI WIN16_GetModuleHandle( SEGPTR name )
1424 if (HIWORD(name) == 0)
1425 return MAKELONG(GetExePtr( (HINSTANCE16)name), hFirstModule );
1426 return MAKELONG(GetModuleHandle16( PTR_SEG_TO_LIN(name)), hFirstModule );
1429 HMODULE16 WINAPI GetModuleHandle16( LPCSTR name )
1431 HMODULE16 hModule = hFirstModule;
1433 BYTE len, *name_table;
1434 char tmpstr[MAX_PATH];
1437 TRACE("(%s)\n", name);
1440 return GetExePtr(LOWORD(name));
1446 lstrcpynA(tmpstr, name, sizeof(tmpstr));
1448 /* If 'name' matches exactly the module name of a module:
1449 * Return its handle.
1451 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1453 pModule = NE_GetPtr( hModule );
1454 if (!pModule) break;
1455 if (pModule->flags & NE_FFLAGS_WIN32) continue;
1457 name_table = (BYTE *)pModule + pModule->name_table;
1458 if ((*name_table == len) && !strncmp(name, name_table+1, len))
1462 /* If uppercased 'name' matches exactly the module name of a module:
1465 for (s = tmpstr; *s; s++)
1468 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1470 pModule = NE_GetPtr( hModule );
1471 if (!pModule) break;
1472 if (pModule->flags & NE_FFLAGS_WIN32) continue;
1474 name_table = (BYTE *)pModule + pModule->name_table;
1475 /* FIXME: the lstrncmpiA is WRONG. It should not be case insensitive,
1476 * but case sensitive! (Unfortunately Winword 6 and subdlls have
1477 * lowercased module names, but try to load uppercase DLLs, so this
1478 * 'i' compare is just a quickfix until the loader handles that
1479 * correctly. -MM 990705
1481 if ((*name_table == len) && !lstrncmpiA(tmpstr, name_table+1, len))
1485 /* If the base filename of 'name' matches the base filename of the module
1486 * filename of some module (case-insensitive compare):
1487 * Return its handle.
1490 /* basename: search backwards in passed name to \ / or : */
1491 s = tmpstr + strlen(tmpstr);
1494 if (s[-1]=='/' || s[-1]=='\\' || s[-1]==':')
1499 /* search this in loaded filename list */
1500 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1505 pModule = NE_GetPtr( hModule );
1506 if (!pModule) break;
1507 if (!pModule->fileinfo) continue;
1508 if (pModule->flags & NE_FFLAGS_WIN32) continue;
1510 ofs = (OFSTRUCT*)((BYTE *)pModule + pModule->fileinfo);
1511 loadedfn = ((char*)ofs->szPathName) + strlen(ofs->szPathName);
1512 /* basename: search backwards in pathname to \ / or : */
1513 while (loadedfn > (char*)ofs->szPathName)
1515 if (loadedfn[-1]=='/' || loadedfn[-1]=='\\' || loadedfn[-1]==':')
1519 /* case insensitive compare ... */
1520 if (!lstrcmpiA(loadedfn, s))
1524 /* If the extension of 'name' is '.EXE' and the base filename of 'name'
1525 * matches the base filename of the module filename of some 32-bit module:
1526 * Return the corresponding 16-bit dummy module handle.
1528 if (len >= 4 && !strcasecmp(name+len-4, ".EXE"))
1530 HMODULE hModule = GetModuleHandleA( name );
1532 return MapHModuleLS( hModule );
1535 if (!strcmp(tmpstr,"MSDOS"))
1538 if (!strcmp(tmpstr,"TIMER"))
1540 FIXME("Eh... Should return caller's code segment, expect crash\n");
1547 /**********************************************************************
1548 * NE_GetModuleByFilename
1550 static HMODULE16 NE_GetModuleByFilename( LPCSTR name )
1554 BYTE len, *name_table;
1555 char tmpstr[MAX_PATH];
1558 lstrcpynA(tmpstr, name, sizeof(tmpstr));
1560 /* If the base filename of 'name' matches the base filename of the module
1561 * filename of some module (case-insensitive compare):
1562 * Return its handle.
1565 /* basename: search backwards in passed name to \ / or : */
1566 s = tmpstr + strlen(tmpstr);
1569 if (s[-1]=='/' || s[-1]=='\\' || s[-1]==':')
1574 /* search this in loaded filename list */
1575 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1580 pModule = NE_GetPtr( hModule );
1581 if (!pModule) break;
1582 if (!pModule->fileinfo) continue;
1583 if (pModule->flags & NE_FFLAGS_WIN32) continue;
1585 ofs = (OFSTRUCT*)((BYTE *)pModule + pModule->fileinfo);
1586 loadedfn = ((char*)ofs->szPathName) + strlen(ofs->szPathName);
1587 /* basename: search backwards in pathname to \ / or : */
1588 while (loadedfn > (char*)ofs->szPathName)
1590 if (loadedfn[-1]=='/' || loadedfn[-1]=='\\' || loadedfn[-1]==':')
1594 /* case insensitive compare ... */
1595 if (!lstrcmpiA(loadedfn, s))
1599 /* If basename (without ext) matches the module name of a module:
1600 * Return its handle.
1603 if ( (p = strrchr( s, '.' )) != NULL ) *p = '\0';
1606 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1608 pModule = NE_GetPtr( hModule );
1609 if (!pModule) break;
1610 if (pModule->flags & NE_FFLAGS_WIN32) continue;
1612 name_table = (BYTE *)pModule + pModule->name_table;
1613 if ((*name_table == len) && !lstrncmpiA(s, name_table+1, len))
1620 /**********************************************************************
1621 * ModuleFirst (TOOLHELP.59)
1623 BOOL16 WINAPI ModuleFirst16( MODULEENTRY *lpme )
1625 lpme->wNext = hFirstModule;
1626 return ModuleNext16( lpme );
1630 /**********************************************************************
1631 * ModuleNext (TOOLHELP.60)
1633 BOOL16 WINAPI ModuleNext16( MODULEENTRY *lpme )
1638 if (!lpme->wNext) return FALSE;
1639 if (!(pModule = NE_GetPtr( lpme->wNext ))) return FALSE;
1640 name = (char *)pModule + pModule->name_table;
1641 memcpy( lpme->szModule, name + 1, min(*name, MAX_MODULE_NAME) );
1642 lpme->szModule[min(*name, MAX_MODULE_NAME)] = '\0';
1643 lpme->hModule = lpme->wNext;
1644 lpme->wcUsage = pModule->count;
1645 lstrcpynA( lpme->szExePath, NE_MODULE_NAME(pModule), sizeof(lpme->szExePath) );
1646 lpme->wNext = pModule->next;
1651 /**********************************************************************
1652 * ModuleFindName (TOOLHELP.61)
1654 BOOL16 WINAPI ModuleFindName16( MODULEENTRY *lpme, LPCSTR name )
1656 lpme->wNext = GetModuleHandle16( name );
1657 return ModuleNext16( lpme );
1661 /**********************************************************************
1662 * ModuleFindHandle (TOOLHELP.62)
1664 BOOL16 WINAPI ModuleFindHandle16( MODULEENTRY *lpme, HMODULE16 hModule )
1666 hModule = GetExePtr( hModule );
1667 lpme->wNext = hModule;
1668 return ModuleNext16( lpme );
1672 /***************************************************************************
1673 * IsRomModule16 (KERNEL.323)
1675 BOOL16 WINAPI IsRomModule16( HMODULE16 unused )
1680 /***************************************************************************
1681 * IsRomFile16 (KERNEL.326)
1683 BOOL16 WINAPI IsRomFile16( HFILE16 unused )
1688 /***************************************************************************
1689 * MapHModuleLS (KERNEL32.520)
1691 HMODULE16 WINAPI MapHModuleLS(HMODULE hmod) {
1695 return ((TDB*)GlobalLock16(GetCurrentTask()))->hInstance;
1697 return hmod; /* we already have a 16 bit module handle */
1698 pModule = (NE_MODULE*)GlobalLock16(hFirstModule);
1700 if (pModule->module32 == hmod)
1701 return pModule->self;
1702 pModule = (NE_MODULE*)GlobalLock16(pModule->next);
1707 /***************************************************************************
1708 * MapHModuleSL (KERNEL32.521)
1710 HMODULE WINAPI MapHModuleSL(HMODULE16 hmod) {
1714 TDB *pTask = (TDB*)GlobalLock16(GetCurrentTask());
1716 hmod = pTask->hModule;
1718 pModule = (NE_MODULE*)GlobalLock16(hmod);
1719 if ( (pModule->magic!=IMAGE_OS2_SIGNATURE) ||
1720 !(pModule->flags & NE_FFLAGS_WIN32)
1723 return pModule->module32;
1726 /***************************************************************************
1727 * MapHInstLS (KERNEL32.516)(KERNEL.472)
1729 void WINAPI MapHInstLS( CONTEXT86 *context )
1731 EAX_reg(context) = MapHModuleLS(EAX_reg(context));
1734 /***************************************************************************
1735 * MapHInstSL (KERNEL32.518)(KERNEL.473)
1737 void WINAPI MapHInstSL( CONTEXT86 *context )
1739 EAX_reg(context) = MapHModuleSL(EAX_reg(context));
1742 /***************************************************************************
1743 * MapHInstLS_PN (KERNEL32.517)
1745 void WINAPI MapHInstLS_PN( CONTEXT86 *context )
1747 if (EAX_reg(context))
1748 EAX_reg(context) = MapHModuleLS(EAX_reg(context));
1751 /***************************************************************************
1752 * MapHInstSL_PN (KERNEL32.519)
1754 void WINAPI MapHInstSL_PN( CONTEXT86 *context )
1756 if (EAX_reg(context))
1757 EAX_reg(context) = MapHModuleSL(EAX_reg(context));