4 * Copyright 1995 Alexandre Julliard
13 #include "wine/winbase16.h"
28 #include "builtin16.h"
29 #include "stackframe.h"
30 #include "debugtools.h"
31 #include "loadorder.h"
34 DEFAULT_DEBUG_CHANNEL(module)
36 #define hFirstModule (pThhook->hExeHead)
38 static NE_MODULE *pCachedModule = 0; /* Module cached by NE_OpenFile */
40 static HINSTANCE16 NE_LoadModule( LPCSTR name, BOOL lib_only );
41 static BOOL16 NE_FreeModule( HMODULE16 hModule, BOOL call_wep );
43 static HINSTANCE16 MODULE_LoadModule16( LPCSTR libname, BOOL implicit, BOOL lib_only );
45 static HMODULE16 NE_GetModuleByFilename( LPCSTR name );
47 /***********************************************************************
50 NE_MODULE *NE_GetPtr( HMODULE16 hModule )
52 return (NE_MODULE *)GlobalLock16( GetExePtr(hModule) );
56 /***********************************************************************
59 void NE_DumpModule( HMODULE16 hModule )
69 if (!(pModule = NE_GetPtr( hModule )))
71 MESSAGE( "**** %04x is not a module handle\n", hModule );
75 /* Dump the module info */
77 DPRINTF( "Module %04x:\n", hModule );
78 DPRINTF( "count=%d flags=%04x heap=%d stack=%d\n",
79 pModule->count, pModule->flags,
80 pModule->heap_size, pModule->stack_size );
81 DPRINTF( "cs:ip=%04x:%04x ss:sp=%04x:%04x ds=%04x nb seg=%d modrefs=%d\n",
82 pModule->cs, pModule->ip, pModule->ss, pModule->sp, pModule->dgroup,
83 pModule->seg_count, pModule->modref_count );
84 DPRINTF( "os_flags=%d swap_area=%d version=%04x\n",
85 pModule->os_flags, pModule->min_swap_area,
86 pModule->expected_version );
87 if (pModule->flags & NE_FFLAGS_WIN32)
88 DPRINTF( "PE module=%08x\n", pModule->module32 );
90 /* Dump the file info */
92 DPRINTF( "Filename: '%s'\n", NE_MODULE_NAME(pModule) );
94 /* Dump the segment table */
96 DPRINTF( "Segment table:\n" );
97 pSeg = NE_SEG_TABLE( pModule );
98 for (i = 0; i < pModule->seg_count; i++, pSeg++)
99 DPRINTF( "%02x: pos=%d size=%d flags=%04x minsize=%d hSeg=%04x\n",
100 i + 1, pSeg->filepos, pSeg->size, pSeg->flags,
101 pSeg->minsize, pSeg->hSeg );
103 /* Dump the resource table */
105 DPRINTF( "Resource table:\n" );
106 if (pModule->res_table)
108 pword = (WORD *)((BYTE *)pModule + pModule->res_table);
109 DPRINTF( "Alignment: %d\n", *pword++ );
112 struct resource_typeinfo_s *ptr = (struct resource_typeinfo_s *)pword;
113 struct resource_nameinfo_s *pname = (struct resource_nameinfo_s *)(ptr + 1);
114 DPRINTF( "id=%04x count=%d\n", ptr->type_id, ptr->count );
115 for (i = 0; i < ptr->count; i++, pname++)
116 DPRINTF( "offset=%d len=%d id=%04x\n",
117 pname->offset, pname->length, pname->id );
118 pword = (WORD *)pname;
121 else DPRINTF( "None\n" );
123 /* Dump the resident name table */
125 DPRINTF( "Resident-name table:\n" );
126 pstr = (char *)pModule + pModule->name_table;
129 DPRINTF( "%*.*s: %d\n", *pstr, *pstr, pstr + 1,
130 *(WORD *)(pstr + *pstr + 1) );
131 pstr += *pstr + 1 + sizeof(WORD);
134 /* Dump the module reference table */
136 DPRINTF( "Module ref table:\n" );
137 if (pModule->modref_table)
139 pword = (WORD *)((BYTE *)pModule + pModule->modref_table);
140 for (i = 0; i < pModule->modref_count; i++, pword++)
143 GetModuleName16( *pword, name, sizeof(name) );
144 DPRINTF( "%d: %04x -> '%s'\n", i, *pword, name );
147 else DPRINTF( "None\n" );
149 /* Dump the entry table */
151 DPRINTF( "Entry table:\n" );
152 bundle = (ET_BUNDLE *)((BYTE *)pModule+pModule->entry_table);
154 entry = (ET_ENTRY *)((BYTE *)bundle+6);
155 DPRINTF( "Bundle %d-%d: %02x\n", bundle->first, bundle->last, entry->type);
156 ordinal = bundle->first;
157 while (ordinal < bundle->last)
159 if (entry->type == 0xff)
160 DPRINTF("%d: %02x:%04x (moveable)\n", ordinal++, entry->segnum, entry->offs);
162 DPRINTF("%d: %02x:%04x (fixed)\n", ordinal++, entry->segnum, entry->offs);
165 } while ( (bundle->next)
166 && (bundle = ((ET_BUNDLE *)((BYTE *)pModule + bundle->next))) );
168 /* Dump the non-resident names table */
170 DPRINTF( "Non-resident names table:\n" );
171 if (pModule->nrname_handle)
173 pstr = (char *)GlobalLock16( pModule->nrname_handle );
176 DPRINTF( "%*.*s: %d\n", *pstr, *pstr, pstr + 1,
177 *(WORD *)(pstr + *pstr + 1) );
178 pstr += *pstr + 1 + sizeof(WORD);
185 /***********************************************************************
188 * Walk the module list and print the modules.
190 void NE_WalkModules(void)
192 HMODULE16 hModule = hFirstModule;
193 MESSAGE( "Module Flags Name\n" );
196 NE_MODULE *pModule = NE_GetPtr( hModule );
199 MESSAGE( "Bad module %04x in list\n", hModule );
202 MESSAGE( " %04x %04x %.*s\n", hModule, pModule->flags,
203 *((char *)pModule + pModule->name_table),
204 (char *)pModule + pModule->name_table + 1 );
205 hModule = pModule->next;
210 /**********************************************************************
213 void NE_RegisterModule( NE_MODULE *pModule )
215 pModule->next = hFirstModule;
216 hFirstModule = pModule->self;
220 /***********************************************************************
223 * Lookup the ordinal for a given name.
225 WORD NE_GetOrdinal( HMODULE16 hModule, const char *name )
227 unsigned char buffer[256], *cpnt;
231 if (!(pModule = NE_GetPtr( hModule ))) return 0;
232 assert( !(pModule->flags & NE_FFLAGS_WIN32) );
234 TRACE("(%04x,'%s')\n", hModule, name );
236 /* First handle names of the form '#xxxx' */
238 if (name[0] == '#') return atoi( name + 1 );
240 /* Now copy and uppercase the string */
242 strcpy( buffer, name );
243 CharUpperA( buffer );
244 len = strlen( buffer );
246 /* First search the resident names */
248 cpnt = (char *)pModule + pModule->name_table;
250 /* Skip the first entry (module name) */
251 cpnt += *cpnt + 1 + sizeof(WORD);
254 if (((BYTE)*cpnt == len) && !memcmp( cpnt+1, buffer, len ))
256 TRACE(" Found: ordinal=%d\n",
257 *(WORD *)(cpnt + *cpnt + 1) );
258 return *(WORD *)(cpnt + *cpnt + 1);
260 cpnt += *cpnt + 1 + sizeof(WORD);
263 /* Now search the non-resident names table */
265 if (!pModule->nrname_handle) return 0; /* No non-resident table */
266 cpnt = (char *)GlobalLock16( pModule->nrname_handle );
268 /* Skip the first entry (module description string) */
269 cpnt += *cpnt + 1 + sizeof(WORD);
272 if (((BYTE)*cpnt == len) && !memcmp( cpnt+1, buffer, len ))
274 TRACE(" Found: ordinal=%d\n",
275 *(WORD *)(cpnt + *cpnt + 1) );
276 return *(WORD *)(cpnt + *cpnt + 1);
278 cpnt += *cpnt + 1 + sizeof(WORD);
284 /***********************************************************************
285 * NE_GetEntryPoint (WPROCS.27)
287 * Return the entry point for a given ordinal.
289 FARPROC16 WINAPI WIN16_NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal )
291 FARPROC16 ret = NE_GetEntryPointEx( hModule, ordinal, TRUE );
292 CURRENT_STACK16->ecx = hModule; /* FIXME: might be incorrect value */
295 FARPROC16 WINAPI NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal )
297 return NE_GetEntryPointEx( hModule, ordinal, TRUE );
299 FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, BOOL16 snoop )
307 if (!(pModule = NE_GetPtr( hModule ))) return 0;
308 assert( !(pModule->flags & NE_FFLAGS_WIN32) );
310 bundle = (ET_BUNDLE *)((BYTE *)pModule + pModule->entry_table);
311 while ((ordinal < bundle->first + 1) || (ordinal > bundle->last))
315 bundle = (ET_BUNDLE *)((BYTE *)pModule + bundle->next);
318 entry = (ET_ENTRY *)((BYTE *)bundle+6);
319 for (i=0; i < (ordinal - bundle->first - 1); i++)
323 offset = entry->offs;
325 if (sel == 0xfe) sel = 0xffff; /* constant entry */
326 else sel = GlobalHandleToSel16(NE_SEG_TABLE(pModule)[sel-1].hSeg);
328 return (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( sel, offset );
330 return (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( sel, offset );
332 return (FARPROC16)SNOOP16_GetProcAddress16(hModule,ordinal,(FARPROC16)PTR_SEG_OFF_TO_SEGPTR( sel, offset ));
336 /***********************************************************************
339 * Change the value of an entry point. Use with caution!
340 * It can only change the offset value, not the selector.
342 BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset )
349 if (!(pModule = NE_GetPtr( hModule ))) return FALSE;
350 assert( !(pModule->flags & NE_FFLAGS_WIN32) );
352 bundle = (ET_BUNDLE *)((BYTE *)pModule + pModule->entry_table);
353 while ((ordinal < bundle->first + 1) || (ordinal > bundle->last))
355 bundle = (ET_BUNDLE *)((BYTE *)pModule + bundle->next);
360 entry = (ET_ENTRY *)((BYTE *)bundle+6);
361 for (i=0; i < (ordinal - bundle->first - 1); i++)
364 entry->offs = offset;
369 /***********************************************************************
372 HANDLE NE_OpenFile( NE_MODULE *pModule )
376 static HANDLE cachedfd = -1;
378 TRACE("(%p) cache: mod=%p fd=%d\n",
379 pModule, pCachedModule, cachedfd );
380 if (pCachedModule == pModule) return cachedfd;
381 CloseHandle( cachedfd );
382 pCachedModule = pModule;
383 name = NE_MODULE_NAME( pModule );
384 if ((cachedfd = CreateFileA( name, GENERIC_READ, FILE_SHARE_READ,
385 NULL, OPEN_EXISTING, 0, -1 )) == -1)
386 MESSAGE( "Can't open file '%s' for module %04x\n", name, pModule->self );
387 TRACE("opened '%s' -> %d\n",
393 /***********************************************************************
396 static HMODULE16 NE_LoadExeHeader( LPCSTR filename )
398 IMAGE_DOS_HEADER mz_header;
399 IMAGE_OS2_HEADER ne_header;
403 BYTE *pData, *pTempEntryTable;
404 char *buffer, *fastload = NULL;
405 int fastload_offset = 0, fastload_length = 0;
407 ET_BUNDLE *bundle, *oldbundle;
412 if ((hFile = OpenFile16( filename, &ofs, OF_READ )) == HFILE_ERROR16)
413 return (HMODULE16)2; /* File not found */
415 /* Read a block from either the file or the fast-load area. */
416 #define READ(offset,size,buffer) \
417 ((fastload && ((offset) >= fastload_offset) && \
418 ((offset)+(size) <= fastload_offset+fastload_length)) ? \
419 (memcpy( buffer, fastload+(offset)-fastload_offset, (size) ), TRUE) : \
420 (_llseek16( hFile, (offset), SEEK_SET), \
421 _hread16( hFile, (buffer), (size) ) == (size)))
423 _llseek16( hFile, 0, SEEK_SET );
424 if ((_hread16(hFile,&mz_header,sizeof(mz_header)) != sizeof(mz_header)) ||
425 (mz_header.e_magic != IMAGE_DOS_SIGNATURE))
428 return (HMODULE16)11; /* invalid exe */
431 _llseek16( hFile, mz_header.e_lfanew, SEEK_SET );
432 if (_hread16( hFile, &ne_header, sizeof(ne_header) ) != sizeof(ne_header))
435 return (HMODULE16)11; /* invalid exe */
438 if (ne_header.ne_magic == IMAGE_NT_SIGNATURE) return (HMODULE16)21; /* win32 exe */
439 if (ne_header.ne_magic != IMAGE_OS2_SIGNATURE) return (HMODULE16)11; /* invalid exe */
441 if (ne_header.ne_magic == IMAGE_OS2_SIGNATURE_LX) {
442 MESSAGE("Sorry, this is an OS/2 linear executable (LX) file !\n");
444 return (HMODULE16)12;
447 /* We now have a valid NE header */
449 size = sizeof(NE_MODULE) +
451 ne_header.n_segment_tab * sizeof(SEGTABLEENTRY) +
453 ne_header.rname_tab_offset - ne_header.resource_tab_offset +
454 /* resident names table */
455 ne_header.moduleref_tab_offset - ne_header.rname_tab_offset +
456 /* module ref table */
457 ne_header.n_mod_ref_tab * sizeof(WORD) +
458 /* imported names table */
459 ne_header.entry_tab_offset - ne_header.iname_tab_offset +
460 /* entry table length */
461 ne_header.entry_tab_length +
462 /* entry table extra conversion space */
464 2 * (ne_header.entry_tab_length - ne_header.n_mov_entry_points*6) +
465 /* loaded file info */
466 sizeof(OFSTRUCT)-sizeof(ofs.szPathName)+strlen(ofs.szPathName)+1;
468 hModule = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT, size );
472 return (HMODULE16)11; /* invalid exe */
475 FarSetOwner16( hModule, hModule );
476 pModule = (NE_MODULE *)GlobalLock16( hModule );
477 memcpy( pModule, &ne_header, sizeof(ne_header) );
479 /* check *programs* for default minimal stack size */
480 if ( (!(pModule->flags & NE_FFLAGS_LIBMODULE))
481 && (pModule->stack_size < 0x1400) )
482 pModule->stack_size = 0x1400;
483 pModule->module32 = 0;
484 pModule->self = hModule;
485 pModule->self_loading_sel = 0;
486 pData = (BYTE *)(pModule + 1);
488 /* Clear internal Wine flags in case they are set in the EXE file */
490 pModule->flags &= ~(NE_FFLAGS_BUILTIN | NE_FFLAGS_WIN32);
492 /* Read the fast-load area */
494 if (ne_header.additional_flags & NE_AFLAGS_FASTLOAD)
496 fastload_offset=ne_header.fastload_offset<<ne_header.align_shift_count;
497 fastload_length=ne_header.fastload_length<<ne_header.align_shift_count;
498 TRACE("Using fast-load area offset=%x len=%d\n",
499 fastload_offset, fastload_length );
500 if ((fastload = HeapAlloc( GetProcessHeap(), 0, fastload_length )) != NULL)
502 _llseek16( hFile, fastload_offset, SEEK_SET);
503 if (_hread16(hFile, fastload, fastload_length) != fastload_length)
505 HeapFree( GetProcessHeap(), 0, fastload );
506 WARN("Error reading fast-load area!\n");
512 /* Get the segment table */
514 pModule->seg_table = (int)pData - (int)pModule;
515 buffer = HeapAlloc( GetProcessHeap(), 0, ne_header.n_segment_tab *
516 sizeof(struct ne_segment_table_entry_s));
520 struct ne_segment_table_entry_s *pSeg;
522 if (!READ( mz_header.e_lfanew + ne_header.segment_tab_offset,
523 ne_header.n_segment_tab * sizeof(struct ne_segment_table_entry_s),
526 HeapFree( GetProcessHeap(), 0, buffer );
528 HeapFree( GetProcessHeap(), 0, fastload );
529 GlobalFree16( hModule );
531 return (HMODULE16)11; /* invalid exe */
533 pSeg = (struct ne_segment_table_entry_s *)buffer;
534 for (i = ne_header.n_segment_tab; i > 0; i--, pSeg++)
536 memcpy( pData, pSeg, sizeof(*pSeg) );
537 pData += sizeof(SEGTABLEENTRY);
539 HeapFree( GetProcessHeap(), 0, buffer );
544 HeapFree( GetProcessHeap(), 0, fastload );
545 GlobalFree16( hModule );
547 return (HMODULE16)11; /* invalid exe */
550 /* Get the resource table */
552 if (ne_header.resource_tab_offset < ne_header.rname_tab_offset)
554 pModule->res_table = (int)pData - (int)pModule;
555 if (!READ(mz_header.e_lfanew + ne_header.resource_tab_offset,
556 ne_header.rname_tab_offset - ne_header.resource_tab_offset,
560 return (HMODULE16)11; /* invalid exe */
562 pData += ne_header.rname_tab_offset - ne_header.resource_tab_offset;
563 NE_InitResourceHandler( hModule );
565 else pModule->res_table = 0; /* No resource table */
567 /* Get the resident names table */
569 pModule->name_table = (int)pData - (int)pModule;
570 if (!READ( mz_header.e_lfanew + ne_header.rname_tab_offset,
571 ne_header.moduleref_tab_offset - ne_header.rname_tab_offset,
575 HeapFree( GetProcessHeap(), 0, fastload );
576 GlobalFree16( hModule );
578 return (HMODULE16)11; /* invalid exe */
580 pData += ne_header.moduleref_tab_offset - ne_header.rname_tab_offset;
582 /* Get the module references table */
584 if (ne_header.n_mod_ref_tab > 0)
586 pModule->modref_table = (int)pData - (int)pModule;
587 if (!READ( mz_header.e_lfanew + ne_header.moduleref_tab_offset,
588 ne_header.n_mod_ref_tab * sizeof(WORD),
592 HeapFree( GetProcessHeap(), 0, fastload );
593 GlobalFree16( hModule );
595 return (HMODULE16)11; /* invalid exe */
597 pData += ne_header.n_mod_ref_tab * sizeof(WORD);
599 else pModule->modref_table = 0; /* No module references */
601 /* Get the imported names table */
603 pModule->import_table = (int)pData - (int)pModule;
604 if (!READ( mz_header.e_lfanew + ne_header.iname_tab_offset,
605 ne_header.entry_tab_offset - ne_header.iname_tab_offset,
609 HeapFree( GetProcessHeap(), 0, fastload );
610 GlobalFree16( hModule );
612 return (HMODULE16)11; /* invalid exe */
614 pData += ne_header.entry_tab_offset - ne_header.iname_tab_offset;
616 /* Load entry table, convert it to the optimized version used by Windows */
618 if ((pTempEntryTable = HeapAlloc( GetProcessHeap(), 0, ne_header.entry_tab_length)) != NULL)
620 BYTE nr_entries, type, *s;
622 TRACE("Converting entry table.\n");
623 pModule->entry_table = (int)pData - (int)pModule;
624 if (!READ( mz_header.e_lfanew + ne_header.entry_tab_offset,
625 ne_header.entry_tab_length, pTempEntryTable ))
627 HeapFree( GetProcessHeap(), 0, pTempEntryTable );
629 HeapFree( GetProcessHeap(), 0, fastload );
630 GlobalFree16( hModule );
632 return (HMODULE16)11; /* invalid exe */
636 TRACE("entry table: offs %04x, len %04x, entries %d\n", ne_header.entry_tab_offset, ne_header.entry_tab_length, *s);
638 bundle = (ET_BUNDLE *)pData;
639 TRACE("first bundle: %p\n", bundle);
640 memset(bundle, 0, sizeof(ET_BUNDLE)); /* in case no entry table exists */
641 entry = (ET_ENTRY *)((BYTE *)bundle+6);
643 while ((nr_entries = *s++))
647 bundle->last += nr_entries;
654 entry->segnum = *s++;
655 entry->offs = *(WORD *)s; s += 2;
656 /*TRACE(module, "entry: %p, type: %d, flags: %d, segnum: %d, offs: %04x\n", entry, entry->type, entry->flags, entry->segnum, entry->offs);*/
664 entry->segnum = type;
665 entry->offs = *(WORD *)s; s += 2;
666 /*TRACE(module, "entry: %p, type: %d, flags: %d, segnum: %d, offs: %04x\n", entry, entry->type, entry->flags, entry->segnum, entry->offs);*/
672 if (bundle->first == bundle->last)
674 bundle->first += nr_entries;
675 bundle->last += nr_entries;
680 oldbundle->next = ((int)entry - (int)pModule);
681 bundle = (ET_BUNDLE *)entry;
682 TRACE("new bundle: %p\n", bundle);
683 bundle->first = bundle->last =
684 oldbundle->last + nr_entries;
686 (BYTE *)entry += sizeof(ET_BUNDLE);
690 HeapFree( GetProcessHeap(), 0, pTempEntryTable );
695 HeapFree( GetProcessHeap(), 0, fastload );
696 GlobalFree16( hModule );
698 return (HMODULE16)11; /* invalid exe */
701 pData += ne_header.entry_tab_length + sizeof(ET_BUNDLE) +
702 2 * (ne_header.entry_tab_length - ne_header.n_mov_entry_points*6);
704 if ((DWORD)entry > (DWORD)pData)
705 ERR("converted entry table bigger than reserved space !!!\nentry: %p, pData: %p. Please report !\n", entry, pData);
707 /* Store the filename information */
709 pModule->fileinfo = (int)pData - (int)pModule;
710 size = sizeof(OFSTRUCT)-sizeof(ofs.szPathName)+strlen(ofs.szPathName)+1;
711 ofs.cBytes = size - 1;
712 memcpy( pData, &ofs, size );
715 /* Free the fast-load area */
719 HeapFree( GetProcessHeap(), 0, fastload );
721 /* Get the non-resident names table */
723 if (ne_header.nrname_tab_length)
725 pModule->nrname_handle = GLOBAL_Alloc( 0, ne_header.nrname_tab_length,
726 hModule, FALSE, FALSE, FALSE );
727 if (!pModule->nrname_handle)
729 GlobalFree16( hModule );
731 return (HMODULE16)11; /* invalid exe */
733 buffer = GlobalLock16( pModule->nrname_handle );
734 _llseek16( hFile, ne_header.nrname_tab_offset, SEEK_SET );
735 if (_hread16( hFile, buffer, ne_header.nrname_tab_length )
736 != ne_header.nrname_tab_length)
738 GlobalFree16( pModule->nrname_handle );
739 GlobalFree16( hModule );
741 return (HMODULE16)11; /* invalid exe */
744 else pModule->nrname_handle = 0;
746 /* Allocate a segment for the implicitly-loaded DLLs */
748 if (pModule->modref_count)
750 pModule->dlls_to_init = GLOBAL_Alloc(GMEM_ZEROINIT,
751 (pModule->modref_count+1)*sizeof(HMODULE16),
752 hModule, FALSE, FALSE, FALSE );
753 if (!pModule->dlls_to_init)
755 if (pModule->nrname_handle) GlobalFree16( pModule->nrname_handle );
756 GlobalFree16( hModule );
758 return (HMODULE16)11; /* invalid exe */
761 else pModule->dlls_to_init = 0;
763 NE_RegisterModule( pModule );
764 SNOOP16_RegisterDLL(pModule,ofs.szPathName);
771 /***********************************************************************
774 * Load all DLLs implicitly linked to a module.
776 static BOOL NE_LoadDLLs( NE_MODULE *pModule )
779 WORD *pModRef = (WORD *)((char *)pModule + pModule->modref_table);
780 WORD *pDLLs = (WORD *)GlobalLock16( pModule->dlls_to_init );
782 for (i = 0; i < pModule->modref_count; i++, pModRef++)
784 char buffer[260], *p;
785 BYTE *pstr = (BYTE *)pModule + pModule->import_table + *pModRef;
786 memcpy( buffer, pstr + 1, *pstr );
787 *(buffer + *pstr) = 0; /* terminate it */
789 TRACE("Loading '%s'\n", buffer );
790 if (!(*pModRef = GetModuleHandle16( buffer )))
792 /* If the DLL is not loaded yet, load it and store */
793 /* its handle in the list of DLLs to initialize. */
796 /* Append .DLL to name if no extension present */
797 if (!(p = strrchr( buffer, '.')) || strchr( p, '/' ) || strchr( p, '\\'))
798 strcat( buffer, ".DLL" );
800 if ((hDLL = MODULE_LoadModule16( buffer, TRUE, TRUE )) < 32)
802 /* FIXME: cleanup what was done */
804 MESSAGE( "Could not load '%s' required by '%.*s', error=%d\n",
805 buffer, *((BYTE*)pModule + pModule->name_table),
806 (char *)pModule + pModule->name_table + 1, hDLL );
809 *pModRef = GetExePtr( hDLL );
812 else /* Increment the reference count of the DLL */
816 pOldDLL = NE_GetPtr( *pModRef );
817 if (pOldDLL) pOldDLL->count++;
824 /**********************************************************************
827 * Load first instance of NE module from file.
829 * pModule must point to a module structure prepared by NE_LoadExeHeader.
830 * This routine must never be called twice on a module.
833 static HINSTANCE16 NE_DoLoadModule( NE_MODULE *pModule )
835 /* Allocate the segments for this module */
837 if (!NE_CreateAllSegments( pModule ))
838 return ERROR_NOT_ENOUGH_MEMORY; /* 8 */
840 /* Load the referenced DLLs */
842 if (!NE_LoadDLLs( pModule ))
843 return ERROR_FILE_NOT_FOUND; /* 2 */
845 /* Load the segments */
847 NE_LoadAllSegments( pModule );
849 /* Make sure the usage count is 1 on the first loading of */
850 /* the module, even if it contains circular DLL references */
854 return NE_GetInstance( pModule );
857 /**********************************************************************
860 * Load first instance of NE module. (Note: caller is responsible for
861 * ensuring the module isn't already loaded!)
863 * If the module turns out to be an executable module, only a
864 * handle to a module stub is returned; this needs to be initialized
865 * by calling NE_DoLoadModule later, in the context of the newly
868 * If lib_only is TRUE, however, the module is perforce treated
869 * like a DLL module, even if it is an executable module.
872 static HINSTANCE16 NE_LoadModule( LPCSTR name, BOOL lib_only )
876 HINSTANCE16 hInstance;
878 hModule = NE_LoadExeHeader( name );
879 if (hModule < 32) return hModule;
881 pModule = NE_GetPtr( hModule );
882 if ( !pModule ) return hModule;
884 if ( !lib_only && !( pModule->flags & NE_FFLAGS_LIBMODULE ) )
887 hInstance = NE_DoLoadModule( pModule );
888 if ( hInstance < 32 )
891 NE_FreeModule( hModule, 0 );
898 /**********************************************************************
899 * MODULE_LoadModule16
901 * Load a NE module in the order of the loadorder specification.
902 * The caller is responsible that the module is not loaded already.
905 static HINSTANCE16 MODULE_LoadModule16( LPCSTR libname, BOOL implicit, BOOL lib_only )
909 module_loadorder_t *plo;
911 plo = MODULE_GetLoadOrder(libname);
913 for(i = 0; i < MODULE_LOADORDER_NTYPES; i++)
915 switch(plo->loadorder[i])
917 case MODULE_LOADORDER_DLL:
918 TRACE("Trying native dll '%s'\n", libname);
919 hinst = NE_LoadModule(libname, lib_only);
922 case MODULE_LOADORDER_ELFDLL:
923 TRACE("Trying elfdll '%s'\n", libname);
924 hinst = ELFDLL_LoadModule16(libname);
927 case MODULE_LOADORDER_BI:
928 TRACE("Trying built-in '%s'\n", libname);
929 hinst = BUILTIN_LoadModule(libname);
933 ERR("Got invalid loadorder type %d (%s index %d)\n", plo->loadorder[i], plo->modulename, i);
936 case MODULE_LOADORDER_SO: /* This is not supported for NE modules */
937 case MODULE_LOADORDER_INVALID: /* We ignore this as it is an empty entry */
949 hModule = GetModuleHandle16(libname);
952 ERR("Serious trouble. Just loaded module '%s' (hinst=0x%04x), but can't get module handle\n",
954 return 6; /* ERROR_INVALID_HANDLE seems most appropriate */
957 pModule = NE_GetPtr(hModule);
960 ERR("Serious trouble. Just loaded module '%s' (hinst=0x%04x), but can't get NE_MODULE pointer\n",
962 return 6; /* ERROR_INVALID_HANDLE seems most appropriate */
965 TRACE("Loaded module '%s' at 0x%04x, \n", libname, hinst);
968 * Call initialization routines for all loaded DLLs. Note that
969 * when we load implicitly linked DLLs this will be done by InitTask().
971 if(pModule->flags & NE_FFLAGS_LIBMODULE)
973 NE_InitializeDLLs(hModule);
974 NE_DllProcessAttach(hModule);
982 /* We quit searching when we get another error than 'File not found' */
986 return hinst; /* The last error that occured */
990 /**********************************************************************
991 * LoadModule16 (KERNEL.45)
993 HINSTANCE16 WINAPI LoadModule16( LPCSTR name, LPVOID paramBlock )
995 BOOL lib_only = !paramBlock || (paramBlock == (LPVOID)-1);
996 LOADPARAMS16 *params;
997 LPSTR cmd_line, new_cmd_line;
999 STARTUPINFOA startup;
1000 PROCESS_INFORMATION info;
1007 if ( (hModule = NE_GetModuleByFilename(name) ) != 0 )
1009 /* Special case: second instance of an already loaded NE module */
1011 if ( !( pModule = NE_GetPtr( hModule ) ) ) return (HINSTANCE16)11;
1012 if ( pModule->module32 ) return (HINSTANCE16)21;
1014 /* Increment refcount */
1020 /* Main case: load first instance of NE module */
1022 if ( (hModule = MODULE_LoadModule16( name, FALSE, lib_only )) < 32 )
1025 if ( !(pModule = NE_GetPtr( hModule )) )
1026 return (HINSTANCE16)11;
1029 /* If library module, we just retrieve the instance handle */
1031 if ( ( pModule->flags & NE_FFLAGS_LIBMODULE ) || lib_only )
1032 return NE_GetInstance( pModule );
1035 * At this point, we need to create a new process.
1037 * pModule points either to an already loaded module, whose refcount
1038 * has already been incremented (to avoid having the module vanish
1039 * in the meantime), or else to a stub module which contains only header
1042 * All remaining initialization (really loading the module in the second
1043 * case, and creating the new instance in both cases) are to be done in
1044 * the context of the new process. This happens in the NE_InitProcess
1045 * routine, which will be called from the 32-bit process initialization.
1049 params = (LOADPARAMS16 *)paramBlock;
1050 cmd_line = (LPSTR)PTR_SEG_TO_LIN( params->cmdLine );
1051 if (!cmd_line) cmd_line = "";
1052 else if (*cmd_line) cmd_line++; /* skip the length byte */
1054 if (!(new_cmd_line = HeapAlloc( GetProcessHeap(), 0,
1055 strlen(cmd_line)+strlen(name)+2 )))
1057 strcpy( new_cmd_line, name );
1058 strcat( new_cmd_line, " " );
1059 strcat( new_cmd_line, cmd_line );
1061 if (params->hEnvironment) env = GlobalLock16( params->hEnvironment );
1063 memset( &info, '\0', sizeof(info) );
1064 memset( &startup, '\0', sizeof(startup) );
1065 startup.cb = sizeof(startup);
1066 if (params->showCmd)
1068 startup.dwFlags = STARTF_USESHOWWINDOW;
1069 startup.wShowWindow = ((UINT16 *)PTR_SEG_TO_LIN(params->showCmd))[1];
1072 SYSLEVEL_ReleaseWin16Lock();
1073 pdb = PROCESS_Create( pModule, -1, new_cmd_line, env,
1074 NULL, NULL, TRUE, 0, &startup, &info );
1075 SYSLEVEL_RestoreWin16Lock();
1077 CloseHandle( info.hThread );
1078 CloseHandle( info.hProcess );
1080 if (params->hEnvironment) GlobalUnlock16( params->hEnvironment );
1081 HeapFree( GetProcessHeap(), 0, new_cmd_line );
1083 return GetProcessDword( info.dwProcessId, GPD_HINSTANCE16 );
1086 /**********************************************************************
1089 BOOL NE_CreateProcess( HANDLE hFile, LPCSTR filename, LPCSTR cmd_line, LPCSTR env,
1090 LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
1091 BOOL inherit, DWORD flags, LPSTARTUPINFOA startup,
1092 LPPROCESS_INFORMATION info )
1097 SYSLEVEL_EnterWin16Lock();
1099 /* Special case: second instance of an already loaded NE module
1100 * FIXME: maybe we should mark the module in a special way during
1101 * "second instance" loading stage ?
1102 * NE_CreateSegment and NE_LoadSegment might get confused without it,
1103 * especially when it comes to self-loaders */
1105 if ( ( hModule = NE_GetModuleByFilename( filename ) ) != 0 )
1107 if ( !( pModule = NE_GetPtr( hModule) )
1108 || ( pModule->flags & NE_FFLAGS_LIBMODULE )
1109 || pModule->module32 )
1111 SetLastError( ERROR_BAD_FORMAT );
1118 /* Main case: load first instance of NE module */
1123 hModule = NE_LoadExeHeader( filename );
1126 SetLastError( hModule );
1130 if ( !( pModule = NE_GetPtr( hModule ) )
1131 || ( pModule->flags & NE_FFLAGS_LIBMODULE) )
1133 GlobalFreeAll16( hModule );
1134 SetLastError( ERROR_BAD_FORMAT );
1139 SYSLEVEL_LeaveWin16Lock();
1141 if ( !PROCESS_Create( pModule, hFile, cmd_line, env,
1142 psa, tsa, inherit, flags, startup, info ) )
1148 SYSLEVEL_LeaveWin16Lock();
1152 /**********************************************************************
1155 BOOL NE_InitProcess( NE_MODULE *pModule )
1157 HINSTANCE16 hInstance, hPrevInstance;
1160 SEGTABLEENTRY *pSegTable = NE_SEG_TABLE( pModule );
1164 SYSLEVEL_EnterWin16Lock();
1166 if ( pModule->count > 0 )
1168 /* Second instance of an already loaded NE module */
1169 /* Note that the refcount was already incremented by the parent */
1171 hPrevInstance = NE_GetInstance( pModule );
1173 if ( pModule->dgroup )
1174 if ( NE_CreateSegment( pModule, pModule->dgroup ) )
1175 NE_LoadSegment( pModule, pModule->dgroup );
1177 hInstance = NE_GetInstance( pModule );
1178 TRACE("created second instance %04x[%d] of instance %04x.\n", hInstance, pModule->dgroup, hPrevInstance);
1183 /* Load first instance of NE module */
1185 pModule->flags |= NE_FFLAGS_GUI; /* FIXME: is this necessary? */
1187 hInstance = NE_DoLoadModule( pModule );
1191 if ( hInstance < 32 )
1193 SYSLEVEL_LeaveWin16Lock();
1195 SetLastError( hInstance );
1199 /* Enter instance handles into task struct */
1201 pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1202 pTask->hInstance = hInstance;
1203 pTask->hPrevInstance = hPrevInstance;
1205 /* Use DGROUP for 16-bit stack */
1207 if (!(sp = pModule->sp))
1208 sp = pSegTable[pModule->ss-1].minsize + pModule->stack_size;
1209 sp &= ~1; sp -= sizeof(STACK16FRAME);
1210 pTask->teb->cur_stack = PTR_SEG_OFF_TO_SEGPTR( hInstance, sp );
1212 SYSLEVEL_LeaveWin16Lock();
1217 /***********************************************************************
1218 * LoadLibrary16 (KERNEL.95)
1220 HINSTANCE16 WINAPI LoadLibrary16( LPCSTR libname )
1222 return LoadModule16(libname, (LPVOID)-1 );
1226 /**********************************************************************
1229 * Call a DLL's WEP, allowing it to shut down.
1230 * FIXME: we always pass the WEP WEP_FREE_DLL, never WEP_SYSTEM_EXIT
1232 static BOOL16 MODULE_CallWEP( HMODULE16 hModule )
1234 FARPROC16 WEP = (FARPROC16)0;
1235 WORD ordinal = NE_GetOrdinal( hModule, "WEP" );
1237 if (ordinal) WEP = NE_GetEntryPoint( hModule, ordinal );
1240 WARN("module %04x doesn't have a WEP\n", hModule );
1243 return Callbacks->CallWindowsExitProc( WEP, WEP_FREE_DLL );
1247 /**********************************************************************
1250 * Implementation of FreeModule16().
1252 static BOOL16 NE_FreeModule( HMODULE16 hModule, BOOL call_wep )
1254 HMODULE16 *hPrevModule;
1259 if (!(pModule = NE_GetPtr( hModule ))) return FALSE;
1260 hModule = pModule->self;
1262 TRACE("%04x count %d\n", hModule, pModule->count );
1264 if (((INT16)(--pModule->count)) > 0 ) return TRUE;
1265 else pModule->count = 0;
1267 if (pModule->flags & NE_FFLAGS_BUILTIN)
1268 return FALSE; /* Can't free built-in module */
1270 if (call_wep && !(pModule->flags & NE_FFLAGS_WIN32))
1272 if (pModule->flags & NE_FFLAGS_LIBMODULE)
1274 MODULE_CallWEP( hModule );
1276 /* Free the objects owned by the DLL module */
1277 TASK_CallTaskSignalProc( USIG16_DLL_UNLOAD, hModule );
1278 PROCESS_CallUserSignalProc( USIG_DLL_UNLOAD_WIN16, hModule );
1281 call_wep = FALSE; /* We are freeing a task -> no more WEPs */
1285 /* Clear magic number just in case */
1287 pModule->magic = pModule->self = 0;
1289 /* Remove it from the linked list */
1291 hPrevModule = &hFirstModule;
1292 while (*hPrevModule && (*hPrevModule != hModule))
1294 hPrevModule = &(NE_GetPtr( *hPrevModule ))->next;
1296 if (*hPrevModule) *hPrevModule = pModule->next;
1298 /* Free the referenced modules */
1300 pModRef = (HMODULE16*)NE_MODULE_TABLE( pModule );
1301 for (i = 0; i < pModule->modref_count; i++, pModRef++)
1303 NE_FreeModule( *pModRef, call_wep );
1306 /* Free the module storage */
1308 GlobalFreeAll16( hModule );
1310 /* Remove module from cache */
1312 if (pCachedModule == pModule) pCachedModule = NULL;
1317 /**********************************************************************
1318 * FreeModule16 (KERNEL.46)
1320 BOOL16 WINAPI FreeModule16( HMODULE16 hModule )
1322 return NE_FreeModule( hModule, TRUE );
1326 /***********************************************************************
1327 * FreeLibrary16 (KERNEL.96)
1329 void WINAPI FreeLibrary16( HINSTANCE16 handle )
1331 TRACE("%04x\n", handle );
1332 FreeModule16( handle );
1336 /**********************************************************************
1337 * GetModuleName (KERNEL.27)
1339 BOOL16 WINAPI GetModuleName16( HINSTANCE16 hinst, LPSTR buf, INT16 count )
1344 if (!(pModule = NE_GetPtr( hinst ))) return FALSE;
1345 p = (BYTE *)pModule + pModule->name_table;
1346 if (count > *p) count = *p + 1;
1349 memcpy( buf, p + 1, count - 1 );
1350 buf[count-1] = '\0';
1356 /**********************************************************************
1357 * GetModuleUsage (KERNEL.48)
1359 INT16 WINAPI GetModuleUsage16( HINSTANCE16 hModule )
1361 NE_MODULE *pModule = NE_GetPtr( hModule );
1362 return pModule ? pModule->count : 0;
1366 /**********************************************************************
1367 * GetExpWinVer (KERNEL.167)
1369 WORD WINAPI GetExpWinVer16( HMODULE16 hModule )
1371 NE_MODULE *pModule = NE_GetPtr( hModule );
1372 if ( !pModule ) return 0;
1375 * For built-in modules, fake the expected version the module should
1376 * have according to the Windows version emulated by Wine
1378 if ( !pModule->expected_version )
1380 OSVERSIONINFOA versionInfo;
1381 versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
1383 if ( GetVersionExA( &versionInfo ) )
1384 pModule->expected_version =
1385 (versionInfo.dwMajorVersion & 0xff) << 8
1386 | (versionInfo.dwMinorVersion & 0xff);
1389 return pModule->expected_version;
1393 /**********************************************************************
1394 * GetModuleFileName16 (KERNEL.49)
1396 * Comment: see GetModuleFileNameA
1398 * Even if invoked by second instance of a program,
1399 * it still returns path of first one.
1401 INT16 WINAPI GetModuleFileName16( HINSTANCE16 hModule, LPSTR lpFileName,
1406 /* Win95 does not query hModule if set to 0 !
1407 * Is this wrong or maybe Win3.1 only ? */
1408 if (!hModule) hModule = GetCurrentTask();
1410 if (!(pModule = NE_GetPtr( hModule ))) return 0;
1411 if (pModule->expected_version >= 0x400)
1412 GetLongPathNameA(NE_MODULE_NAME(pModule), lpFileName, nSize);
1414 lstrcpynA( lpFileName, NE_MODULE_NAME(pModule), nSize );
1415 TRACE("%s\n", lpFileName );
1416 return strlen(lpFileName);
1420 /**********************************************************************
1421 * GetModuleHandle (KERNEL.47)
1423 * Find a module from a module name.
1425 * NOTE: The current implementation works the same way the Windows 95 one
1426 * does. Do not try to 'fix' it, fix the callers.
1427 * + It does not do ANY extension handling (except that strange .EXE bit)!
1428 * + It does not care about paths, just about basenames. (same as Windows)
1432 * the win16 module handle if found
1434 * HIWORD (undocumented, see "Undocumented Windows", chapter 5):
1435 * Always hFirstModule
1437 DWORD WINAPI WIN16_GetModuleHandle( SEGPTR name )
1439 if (HIWORD(name) == 0)
1440 return MAKELONG(GetExePtr( (HINSTANCE16)name), hFirstModule );
1441 return MAKELONG(GetModuleHandle16( PTR_SEG_TO_LIN(name)), hFirstModule );
1444 HMODULE16 WINAPI GetModuleHandle16( LPCSTR name )
1446 HMODULE16 hModule = hFirstModule;
1448 BYTE len, *name_table;
1449 char tmpstr[MAX_PATH];
1452 TRACE("(%s)\n", name);
1455 return GetExePtr(LOWORD(name));
1461 lstrcpynA(tmpstr, name, sizeof(tmpstr));
1463 /* If 'name' matches exactly the module name of a module:
1464 * Return its handle.
1466 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1468 pModule = NE_GetPtr( hModule );
1469 if (!pModule) break;
1470 if (pModule->flags & NE_FFLAGS_WIN32) continue;
1472 name_table = (BYTE *)pModule + pModule->name_table;
1473 if ((*name_table == len) && !strncmp(name, name_table+1, len))
1477 /* If uppercased 'name' matches exactly the module name of a module:
1480 for (s = tmpstr; *s; s++)
1483 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1485 pModule = NE_GetPtr( hModule );
1486 if (!pModule) break;
1487 if (pModule->flags & NE_FFLAGS_WIN32) continue;
1489 name_table = (BYTE *)pModule + pModule->name_table;
1490 /* FIXME: the lstrncmpiA is WRONG. It should not be case insensitive,
1491 * but case sensitive! (Unfortunately Winword 6 and subdlls have
1492 * lowercased module names, but try to load uppercase DLLs, so this
1493 * 'i' compare is just a quickfix until the loader handles that
1494 * correctly. -MM 990705
1496 if ((*name_table == len) && !lstrncmpiA(tmpstr, name_table+1, len))
1500 /* If the base filename of 'name' matches the base filename of the module
1501 * filename of some module (case-insensitive compare):
1502 * Return its handle.
1505 /* basename: search backwards in passed name to \ / or : */
1506 s = tmpstr + strlen(tmpstr);
1509 if (s[-1]=='/' || s[-1]=='\\' || s[-1]==':')
1514 /* search this in loaded filename list */
1515 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1520 pModule = NE_GetPtr( hModule );
1521 if (!pModule) break;
1522 if (!pModule->fileinfo) continue;
1523 if (pModule->flags & NE_FFLAGS_WIN32) continue;
1525 ofs = (OFSTRUCT*)((BYTE *)pModule + pModule->fileinfo);
1526 loadedfn = ((char*)ofs->szPathName) + strlen(ofs->szPathName);
1527 /* basename: search backwards in pathname to \ / or : */
1528 while (loadedfn > (char*)ofs->szPathName)
1530 if (loadedfn[-1]=='/' || loadedfn[-1]=='\\' || loadedfn[-1]==':')
1534 /* case insensitive compare ... */
1535 if (!lstrcmpiA(loadedfn, s))
1539 /* If the extension of 'name' is '.EXE' and the base filename of 'name'
1540 * matches the base filename of the module filename of some 32-bit module:
1541 * Return the corresponding 16-bit dummy module handle.
1543 if (len >= 4 && !strcasecmp(name+len-4, ".EXE"))
1545 HMODULE hModule = GetModuleHandleA( name );
1547 return MapHModuleLS( hModule );
1550 if (!strcmp(tmpstr,"MSDOS"))
1553 if (!strcmp(tmpstr,"TIMER"))
1555 FIXME("Eh... Should return caller's code segment, expect crash\n");
1562 /**********************************************************************
1563 * NE_GetModuleByFilename
1565 static HMODULE16 NE_GetModuleByFilename( LPCSTR name )
1569 BYTE len, *name_table;
1570 char tmpstr[MAX_PATH];
1573 lstrcpynA(tmpstr, name, sizeof(tmpstr));
1575 /* If the base filename of 'name' matches the base filename of the module
1576 * filename of some module (case-insensitive compare):
1577 * Return its handle.
1580 /* basename: search backwards in passed name to \ / or : */
1581 s = tmpstr + strlen(tmpstr);
1584 if (s[-1]=='/' || s[-1]=='\\' || s[-1]==':')
1589 /* search this in loaded filename list */
1590 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1595 pModule = NE_GetPtr( hModule );
1596 if (!pModule) break;
1597 if (!pModule->fileinfo) continue;
1598 if (pModule->flags & NE_FFLAGS_WIN32) continue;
1600 ofs = (OFSTRUCT*)((BYTE *)pModule + pModule->fileinfo);
1601 loadedfn = ((char*)ofs->szPathName) + strlen(ofs->szPathName);
1602 /* basename: search backwards in pathname to \ / or : */
1603 while (loadedfn > (char*)ofs->szPathName)
1605 if (loadedfn[-1]=='/' || loadedfn[-1]=='\\' || loadedfn[-1]==':')
1609 /* case insensitive compare ... */
1610 if (!lstrcmpiA(loadedfn, s))
1614 /* If basename (without ext) matches the module name of a module:
1615 * Return its handle.
1618 if ( (p = strrchr( s, '.' )) != NULL ) *p = '\0';
1621 for (hModule = hFirstModule; hModule ; hModule = pModule->next)
1623 pModule = NE_GetPtr( hModule );
1624 if (!pModule) break;
1625 if (pModule->flags & NE_FFLAGS_WIN32) continue;
1627 name_table = (BYTE *)pModule + pModule->name_table;
1628 if ((*name_table == len) && !lstrncmpiA(s, name_table+1, len))
1635 /**********************************************************************
1636 * ModuleFirst (TOOLHELP.59)
1638 BOOL16 WINAPI ModuleFirst16( MODULEENTRY *lpme )
1640 lpme->wNext = hFirstModule;
1641 return ModuleNext16( lpme );
1645 /**********************************************************************
1646 * ModuleNext (TOOLHELP.60)
1648 BOOL16 WINAPI ModuleNext16( MODULEENTRY *lpme )
1653 if (!lpme->wNext) return FALSE;
1654 if (!(pModule = NE_GetPtr( lpme->wNext ))) return FALSE;
1655 name = (char *)pModule + pModule->name_table;
1656 memcpy( lpme->szModule, name + 1, min(*name, MAX_MODULE_NAME) );
1657 lpme->szModule[min(*name, MAX_MODULE_NAME)] = '\0';
1658 lpme->hModule = lpme->wNext;
1659 lpme->wcUsage = pModule->count;
1660 lstrcpynA( lpme->szExePath, NE_MODULE_NAME(pModule), sizeof(lpme->szExePath) );
1661 lpme->wNext = pModule->next;
1666 /**********************************************************************
1667 * ModuleFindName (TOOLHELP.61)
1669 BOOL16 WINAPI ModuleFindName16( MODULEENTRY *lpme, LPCSTR name )
1671 lpme->wNext = GetModuleHandle16( name );
1672 return ModuleNext16( lpme );
1676 /**********************************************************************
1677 * ModuleFindHandle (TOOLHELP.62)
1679 BOOL16 WINAPI ModuleFindHandle16( MODULEENTRY *lpme, HMODULE16 hModule )
1681 hModule = GetExePtr( hModule );
1682 lpme->wNext = hModule;
1683 return ModuleNext16( lpme );
1687 /***************************************************************************
1688 * IsRomModule16 (KERNEL.323)
1690 BOOL16 WINAPI IsRomModule16( HMODULE16 unused )
1695 /***************************************************************************
1696 * IsRomFile16 (KERNEL.326)
1698 BOOL16 WINAPI IsRomFile16( HFILE16 unused )
1703 /***************************************************************************
1704 * MapHModuleLS (KERNEL32.520)
1706 HMODULE16 WINAPI MapHModuleLS(HMODULE hmod) {
1710 return ((TDB*)GlobalLock16(GetCurrentTask()))->hInstance;
1712 return hmod; /* we already have a 16 bit module handle */
1713 pModule = (NE_MODULE*)GlobalLock16(hFirstModule);
1715 if (pModule->module32 == hmod)
1716 return pModule->self;
1717 pModule = (NE_MODULE*)GlobalLock16(pModule->next);
1722 /***************************************************************************
1723 * MapHModuleSL (KERNEL32.521)
1725 HMODULE WINAPI MapHModuleSL(HMODULE16 hmod) {
1729 TDB *pTask = (TDB*)GlobalLock16(GetCurrentTask());
1731 hmod = pTask->hModule;
1733 pModule = (NE_MODULE*)GlobalLock16(hmod);
1734 if ( (pModule->magic!=IMAGE_OS2_SIGNATURE) ||
1735 !(pModule->flags & NE_FFLAGS_WIN32)
1738 return pModule->module32;
1741 /***************************************************************************
1742 * MapHInstLS (KERNEL32.516)(KERNEL.472)
1744 void WINAPI MapHInstLS( CONTEXT86 *context )
1746 EAX_reg(context) = MapHModuleLS(EAX_reg(context));
1749 /***************************************************************************
1750 * MapHInstSL (KERNEL32.518)(KERNEL.473)
1752 void WINAPI MapHInstSL( CONTEXT86 *context )
1754 EAX_reg(context) = MapHModuleSL(EAX_reg(context));
1757 /***************************************************************************
1758 * MapHInstLS_PN (KERNEL32.517)
1760 void WINAPI MapHInstLS_PN( CONTEXT86 *context )
1762 if (EAX_reg(context))
1763 EAX_reg(context) = MapHModuleLS(EAX_reg(context));
1766 /***************************************************************************
1767 * MapHInstSL_PN (KERNEL32.519)
1769 void WINAPI MapHInstSL_PN( CONTEXT86 *context )
1771 if (EAX_reg(context))
1772 EAX_reg(context) = MapHModuleSL(EAX_reg(context));