Release 980503
[wine/multimedia.git] / loader / ne / module.c
blob5cd97f8c9a05aa9749626b29f833cae53d3e0764
1 /*
2 * NE modules
4 * Copyright 1995 Alexandre Julliard
5 */
7 #include <assert.h>
8 #include <stdlib.h>
9 #include "module.h"
10 #include "ldt.h"
11 #include "heap.h"
12 #include "global.h"
13 #include "process.h"
14 #include "debug.h"
16 HMODULE16 hFirstModule = 0;
18 /***********************************************************************
19 * NE_DumpModule
21 void NE_DumpModule( HMODULE16 hModule )
23 int i, ordinal;
24 SEGTABLEENTRY *pSeg;
25 BYTE *pstr;
26 WORD *pword;
27 NE_MODULE *pModule;
29 if (!(pModule = MODULE_GetPtr16( hModule )))
31 fprintf( stderr, "**** %04x is not a module handle\n", hModule );
32 return;
35 /* Dump the module info */
36 DUMP( "---\n" );
37 DUMP( "Module %04x:\n", hModule );
38 DUMP( "count=%d flags=%04x heap=%d stack=%d\n",
39 pModule->count, pModule->flags,
40 pModule->heap_size, pModule->stack_size );
41 DUMP( "cs:ip=%04x:%04x ss:sp=%04x:%04x ds=%04x nb seg=%d modrefs=%d\n",
42 pModule->cs, pModule->ip, pModule->ss, pModule->sp, pModule->dgroup,
43 pModule->seg_count, pModule->modref_count );
44 DUMP( "os_flags=%d swap_area=%d version=%04x\n",
45 pModule->os_flags, pModule->min_swap_area,
46 pModule->expected_version );
47 if (pModule->flags & NE_FFLAGS_WIN32)
48 DUMP( "PE module=%08x\n", pModule->module32 );
50 /* Dump the file info */
51 DUMP( "---\n" );
52 DUMP( "Filename: '%s'\n", NE_MODULE_NAME(pModule) );
54 /* Dump the segment table */
55 DUMP( "---\n" );
56 DUMP( "Segment table:\n" );
57 pSeg = NE_SEG_TABLE( pModule );
58 for (i = 0; i < pModule->seg_count; i++, pSeg++)
59 DUMP( "%02x: pos=%d size=%d flags=%04x minsize=%d sel=%04x\n",
60 i + 1, pSeg->filepos, pSeg->size, pSeg->flags,
61 pSeg->minsize, pSeg->selector );
63 /* Dump the resource table */
64 DUMP( "---\n" );
65 DUMP( "Resource table:\n" );
66 if (pModule->res_table)
68 pword = (WORD *)((BYTE *)pModule + pModule->res_table);
69 DUMP( "Alignment: %d\n", *pword++ );
70 while (*pword)
72 struct resource_typeinfo_s *ptr = (struct resource_typeinfo_s *)pword;
73 struct resource_nameinfo_s *pname = (struct resource_nameinfo_s *)(ptr + 1);
74 DUMP( "id=%04x count=%d\n", ptr->type_id, ptr->count );
75 for (i = 0; i < ptr->count; i++, pname++)
76 DUMP( "offset=%d len=%d id=%04x\n",
77 pname->offset, pname->length, pname->id );
78 pword = (WORD *)pname;
81 else DUMP( "None\n" );
83 /* Dump the resident name table */
84 DUMP( "---\n" );
85 DUMP( "Resident-name table:\n" );
86 pstr = (char *)pModule + pModule->name_table;
87 while (*pstr)
89 DUMP( "%*.*s: %d\n", *pstr, *pstr, pstr + 1,
90 *(WORD *)(pstr + *pstr + 1) );
91 pstr += *pstr + 1 + sizeof(WORD);
94 /* Dump the module reference table */
95 DUMP( "---\n" );
96 DUMP( "Module ref table:\n" );
97 if (pModule->modref_table)
99 pword = (WORD *)((BYTE *)pModule + pModule->modref_table);
100 for (i = 0; i < pModule->modref_count; i++, pword++)
102 DUMP( "%d: %04x -> '%s'\n", i, *pword,
103 MODULE_GetModuleName(*pword));
106 else DUMP( "None\n" );
108 /* Dump the entry table */
109 DUMP( "---\n" );
110 DUMP( "Entry table:\n" );
111 pstr = (char *)pModule + pModule->entry_table;
112 ordinal = 1;
113 while (*pstr)
115 DUMP( "Bundle %d-%d: %02x\n", ordinal, ordinal + *pstr - 1, pstr[1]);
116 if (!pstr[1])
118 ordinal += *pstr;
119 pstr += 2;
121 else if ((BYTE)pstr[1] == 0xff) /* moveable */
123 i = *pstr;
124 pstr += 2;
125 while (i--)
127 DUMP( "%d: %02x:%04x (moveable)\n",
128 ordinal++, pstr[3], *(WORD *)(pstr + 4) );
129 pstr += 6;
132 else /* fixed */
134 i = *pstr;
135 pstr += 2;
136 while (i--)
138 DUMP( "%d: %04x (fixed)\n",
139 ordinal++, *(WORD *)(pstr + 1) );
140 pstr += 3;
145 /* Dump the non-resident names table */
146 DUMP( "---\n" );
147 DUMP( "Non-resident names table:\n" );
148 if (pModule->nrname_handle)
150 pstr = (char *)GlobalLock16( pModule->nrname_handle );
151 while (*pstr)
153 DUMP( "%*.*s: %d\n", *pstr, *pstr, pstr + 1,
154 *(WORD *)(pstr + *pstr + 1) );
155 pstr += *pstr + 1 + sizeof(WORD);
158 DUMP( "\n" );
162 /***********************************************************************
163 * NE_WalkModules
165 * Walk the module list and print the modules.
167 void NE_WalkModules(void)
169 HMODULE16 hModule = hFirstModule;
170 fprintf( stderr, "Module Flags Name\n" );
171 while (hModule)
173 NE_MODULE *pModule = MODULE_GetPtr16( hModule );
174 if (!pModule)
176 fprintf( stderr, "**** Bad module %04x in list\n", hModule );
177 return;
179 fprintf( stderr, " %04x %04x %.*s\n", hModule, pModule->flags,
180 *((char *)pModule + pModule->name_table),
181 (char *)pModule + pModule->name_table + 1 );
182 hModule = pModule->next;
187 /**********************************************************************
188 * NE_RegisterModule
190 void NE_RegisterModule( NE_MODULE *pModule )
192 pModule->next = hFirstModule;
193 hFirstModule = pModule->self;
197 /***********************************************************************
198 * NE_GetOrdinal
200 * Lookup the ordinal for a given name.
202 WORD NE_GetOrdinal( HMODULE16 hModule, const char *name )
204 unsigned char buffer[256], *cpnt;
205 BYTE len;
206 NE_MODULE *pModule;
208 if (!(pModule = MODULE_GetPtr16( hModule ))) return 0;
209 assert( !(pModule->flags & NE_FFLAGS_WIN32) );
211 TRACE( module, "(%04x,'%s')\n", hModule, name );
213 /* First handle names of the form '#xxxx' */
215 if (name[0] == '#') return atoi( name + 1 );
217 /* Now copy and uppercase the string */
219 strcpy( buffer, name );
220 CharUpper32A( buffer );
221 len = strlen( buffer );
223 /* First search the resident names */
225 cpnt = (char *)pModule + pModule->name_table;
227 /* Skip the first entry (module name) */
228 cpnt += *cpnt + 1 + sizeof(WORD);
229 while (*cpnt)
231 if (((BYTE)*cpnt == len) && !memcmp( cpnt+1, buffer, len ))
233 TRACE(module, " Found: ordinal=%d\n",
234 *(WORD *)(cpnt + *cpnt + 1) );
235 return *(WORD *)(cpnt + *cpnt + 1);
237 cpnt += *cpnt + 1 + sizeof(WORD);
240 /* Now search the non-resident names table */
242 if (!pModule->nrname_handle) return 0; /* No non-resident table */
243 cpnt = (char *)GlobalLock16( pModule->nrname_handle );
245 /* Skip the first entry (module description string) */
246 cpnt += *cpnt + 1 + sizeof(WORD);
247 while (*cpnt)
249 if (((BYTE)*cpnt == len) && !memcmp( cpnt+1, buffer, len ))
251 TRACE(module, " Found: ordinal=%d\n",
252 *(WORD *)(cpnt + *cpnt + 1) );
253 return *(WORD *)(cpnt + *cpnt + 1);
255 cpnt += *cpnt + 1 + sizeof(WORD);
257 return 0;
261 /***********************************************************************
262 * NE_GetEntryPoint (WPROCS.27)
264 * Return the entry point for a given ordinal.
266 FARPROC16 NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal )
268 NE_MODULE *pModule;
269 WORD curOrdinal = 1;
270 BYTE *p;
271 WORD sel, offset;
273 if (!(pModule = MODULE_GetPtr16( hModule ))) return 0;
274 assert( !(pModule->flags & NE_FFLAGS_WIN32) );
276 p = (BYTE *)pModule + pModule->entry_table;
277 while (*p && (curOrdinal + *p <= ordinal))
279 /* Skipping this bundle */
280 curOrdinal += *p;
281 switch(p[1])
283 case 0: p += 2; break; /* unused */
284 case 0xff: p += 2 + *p * 6; break; /* moveable */
285 default: p += 2 + *p * 3; break; /* fixed */
288 if (!*p) return 0;
290 switch(p[1])
292 case 0: /* unused */
293 return 0;
294 case 0xff: /* moveable */
295 p += 2 + 6 * (ordinal - curOrdinal);
296 sel = p[3];
297 offset = *(WORD *)(p + 4);
298 break;
299 default: /* fixed */
300 sel = p[1];
301 p += 2 + 3 * (ordinal - curOrdinal);
302 offset = *(WORD *)(p + 1);
303 break;
306 if (sel == 0xfe) sel = 0xffff; /* constant entry */
307 else sel = (WORD)(DWORD)NE_SEG_TABLE(pModule)[sel-1].selector;
308 return (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( sel, offset );
312 /***********************************************************************
313 * NE_SetEntryPoint
315 * Change the value of an entry point. Use with caution!
316 * It can only change the offset value, not the selector.
318 BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset )
320 NE_MODULE *pModule;
321 WORD curOrdinal = 1;
322 BYTE *p;
324 if (!(pModule = MODULE_GetPtr16( hModule ))) return FALSE;
325 assert( !(pModule->flags & NE_FFLAGS_WIN32) );
327 p = (BYTE *)pModule + pModule->entry_table;
328 while (*p && (curOrdinal + *p <= ordinal))
330 /* Skipping this bundle */
331 curOrdinal += *p;
332 switch(p[1])
334 case 0: p += 2; break; /* unused */
335 case 0xff: p += 2 + *p * 6; break; /* moveable */
336 default: p += 2 + *p * 3; break; /* fixed */
339 if (!*p) return FALSE;
341 switch(p[1])
343 case 0: /* unused */
344 return FALSE;
345 case 0xff: /* moveable */
346 p += 2 + 6 * (ordinal - curOrdinal);
347 *(WORD *)(p + 4) = offset;
348 break;
349 default: /* fixed */
350 p += 2 + 3 * (ordinal - curOrdinal);
351 *(WORD *)(p + 1) = offset;
352 break;
354 return TRUE;
358 /***********************************************************************
359 * NE_LoadExeHeader
361 static HMODULE16 NE_LoadExeHeader( HFILE32 hFile, OFSTRUCT *ofs )
363 IMAGE_DOS_HEADER mz_header;
364 IMAGE_OS2_HEADER ne_header;
365 int size;
366 HMODULE16 hModule;
367 NE_MODULE *pModule;
368 BYTE *pData;
369 char *buffer, *fastload = NULL;
370 int fastload_offset = 0, fastload_length = 0;
372 /* Read a block from either the file or the fast-load area. */
373 #define READ(offset,size,buffer) \
374 ((fastload && ((offset) >= fastload_offset) && \
375 ((offset)+(size) <= fastload_offset+fastload_length)) ? \
376 (memcpy( buffer, fastload+(offset)-fastload_offset, (size) ), TRUE) : \
377 (_llseek32( hFile, (offset), SEEK_SET), \
378 _lread32( hFile, (buffer), (size) ) == (size)))
380 _llseek32( hFile, 0, SEEK_SET );
381 if ((_lread32(hFile,&mz_header,sizeof(mz_header)) != sizeof(mz_header)) ||
382 (mz_header.e_magic != IMAGE_DOS_SIGNATURE))
383 return (HMODULE16)11; /* invalid exe */
385 _llseek32( hFile, mz_header.e_lfanew, SEEK_SET );
386 if (_lread32( hFile, &ne_header, sizeof(ne_header) ) != sizeof(ne_header))
387 return (HMODULE16)11; /* invalid exe */
389 if (ne_header.ne_magic == IMAGE_NT_SIGNATURE) return (HMODULE16)21; /* win32 exe */
390 if (ne_header.ne_magic != IMAGE_OS2_SIGNATURE) return (HMODULE16)11; /* invalid exe */
392 if (ne_header.ne_magic == IMAGE_OS2_SIGNATURE_LX) {
393 fprintf(stderr, "Sorry, this is an OS/2 linear executable (LX) file !\n");
394 return (HMODULE16)12;
397 /* We now have a valid NE header */
399 size = sizeof(NE_MODULE) +
400 /* loaded file info */
401 sizeof(OFSTRUCT)-sizeof(ofs->szPathName)+strlen(ofs->szPathName)+1+
402 /* segment table */
403 ne_header.n_segment_tab * sizeof(SEGTABLEENTRY) +
404 /* resource table */
405 ne_header.rname_tab_offset - ne_header.resource_tab_offset +
406 /* resident names table */
407 ne_header.moduleref_tab_offset - ne_header.rname_tab_offset +
408 /* module ref table */
409 ne_header.n_mod_ref_tab * sizeof(WORD) +
410 /* imported names table */
411 ne_header.entry_tab_offset - ne_header.iname_tab_offset +
412 /* entry table length */
413 ne_header.entry_tab_length;
415 hModule = GlobalAlloc16( GMEM_MOVEABLE | GMEM_ZEROINIT, size );
416 if (!hModule) return (HMODULE16)11; /* invalid exe */
417 FarSetOwner( hModule, hModule );
418 pModule = (NE_MODULE *)GlobalLock16( hModule );
419 memcpy( pModule, &ne_header, sizeof(ne_header) );
420 pModule->count = 0;
421 pModule->module32 = 0;
422 pModule->self = hModule;
423 pModule->self_loading_sel = 0;
424 pData = (BYTE *)(pModule + 1);
426 /* Clear internal Wine flags in case they are set in the EXE file */
428 pModule->flags &= ~(NE_FFLAGS_BUILTIN|NE_FFLAGS_WIN32|NE_FFLAGS_IMPLICIT);
430 /* Read the fast-load area */
432 if (ne_header.additional_flags & NE_AFLAGS_FASTLOAD)
434 fastload_offset=ne_header.fastload_offset<<ne_header.align_shift_count;
435 fastload_length=ne_header.fastload_length<<ne_header.align_shift_count;
436 TRACE(module, "Using fast-load area offset=%x len=%d\n",
437 fastload_offset, fastload_length );
438 if ((fastload = HeapAlloc( SystemHeap, 0, fastload_length )) != NULL)
440 _llseek32( hFile, fastload_offset, SEEK_SET);
441 if (_lread32(hFile, fastload, fastload_length) != fastload_length)
443 HeapFree( SystemHeap, 0, fastload );
444 fprintf(stderr, "Error reading fast-load area !\n");
445 fastload = NULL;
450 /* Store the filename information */
452 pModule->fileinfo = (int)pData - (int)pModule;
453 size = sizeof(OFSTRUCT)-sizeof(ofs->szPathName)+strlen(ofs->szPathName)+1;
454 memcpy( pData, ofs, size );
455 ((OFSTRUCT *)pData)->cBytes = size - 1;
456 pData += size;
458 /* Get the segment table */
460 pModule->seg_table = (int)pData - (int)pModule;
461 buffer = HeapAlloc( SystemHeap, 0, ne_header.n_segment_tab *
462 sizeof(struct ne_segment_table_entry_s));
463 if (buffer)
465 int i;
466 struct ne_segment_table_entry_s *pSeg;
468 if (!READ( mz_header.e_lfanew + ne_header.segment_tab_offset,
469 ne_header.n_segment_tab * sizeof(struct ne_segment_table_entry_s),
470 buffer ))
472 HeapFree( SystemHeap, 0, buffer );
473 if (fastload) HeapFree( SystemHeap, 0, fastload );
474 GlobalFree16( hModule );
475 return (HMODULE16)11; /* invalid exe */
477 pSeg = (struct ne_segment_table_entry_s *)buffer;
478 for (i = ne_header.n_segment_tab; i > 0; i--, pSeg++)
480 memcpy( pData, pSeg, sizeof(*pSeg) );
481 pData += sizeof(SEGTABLEENTRY);
483 HeapFree( SystemHeap, 0, buffer );
485 else
487 if (fastload) HeapFree( SystemHeap, 0, fastload );
488 GlobalFree16( hModule );
489 return (HMODULE16)11; /* invalid exe */
492 /* Get the resource table */
494 if (ne_header.resource_tab_offset < ne_header.rname_tab_offset)
496 pModule->res_table = (int)pData - (int)pModule;
497 if (!READ(mz_header.e_lfanew + ne_header.resource_tab_offset,
498 ne_header.rname_tab_offset - ne_header.resource_tab_offset,
499 pData )) return (HMODULE16)11; /* invalid exe */
500 pData += ne_header.rname_tab_offset - ne_header.resource_tab_offset;
501 NE_InitResourceHandler( hModule );
503 else pModule->res_table = 0; /* No resource table */
505 /* Get the resident names table */
507 pModule->name_table = (int)pData - (int)pModule;
508 if (!READ( mz_header.e_lfanew + ne_header.rname_tab_offset,
509 ne_header.moduleref_tab_offset - ne_header.rname_tab_offset,
510 pData ))
512 if (fastload) HeapFree( SystemHeap, 0, fastload );
513 GlobalFree16( hModule );
514 return (HMODULE16)11; /* invalid exe */
516 pData += ne_header.moduleref_tab_offset - ne_header.rname_tab_offset;
518 /* Get the module references table */
520 if (ne_header.n_mod_ref_tab > 0)
522 pModule->modref_table = (int)pData - (int)pModule;
523 if (!READ( mz_header.e_lfanew + ne_header.moduleref_tab_offset,
524 ne_header.n_mod_ref_tab * sizeof(WORD),
525 pData ))
527 if (fastload) HeapFree( SystemHeap, 0, fastload );
528 GlobalFree16( hModule );
529 return (HMODULE16)11; /* invalid exe */
531 pData += ne_header.n_mod_ref_tab * sizeof(WORD);
533 else pModule->modref_table = 0; /* No module references */
535 /* Get the imported names table */
537 pModule->import_table = (int)pData - (int)pModule;
538 if (!READ( mz_header.e_lfanew + ne_header.iname_tab_offset,
539 ne_header.entry_tab_offset - ne_header.iname_tab_offset,
540 pData ))
542 if (fastload) HeapFree( SystemHeap, 0, fastload );
543 GlobalFree16( hModule );
544 return (HMODULE16)11; /* invalid exe */
546 pData += ne_header.entry_tab_offset - ne_header.iname_tab_offset;
548 /* Get the entry table */
550 pModule->entry_table = (int)pData - (int)pModule;
551 if (!READ( mz_header.e_lfanew + ne_header.entry_tab_offset,
552 ne_header.entry_tab_length,
553 pData ))
555 if (fastload) HeapFree( SystemHeap, 0, fastload );
556 GlobalFree16( hModule );
557 return (HMODULE16)11; /* invalid exe */
559 pData += ne_header.entry_tab_length;
561 /* Free the fast-load area */
563 #undef READ
564 if (fastload) HeapFree( SystemHeap, 0, fastload );
566 /* Get the non-resident names table */
568 if (ne_header.nrname_tab_length)
570 pModule->nrname_handle = GLOBAL_Alloc( 0, ne_header.nrname_tab_length,
571 hModule, FALSE, FALSE, FALSE );
572 if (!pModule->nrname_handle)
574 GlobalFree16( hModule );
575 return (HMODULE16)11; /* invalid exe */
577 buffer = GlobalLock16( pModule->nrname_handle );
578 _llseek32( hFile, ne_header.nrname_tab_offset, SEEK_SET );
579 if (_lread32( hFile, buffer, ne_header.nrname_tab_length )
580 != ne_header.nrname_tab_length)
582 GlobalFree16( pModule->nrname_handle );
583 GlobalFree16( hModule );
584 return (HMODULE16)11; /* invalid exe */
587 else pModule->nrname_handle = 0;
589 /* Allocate a segment for the implicitly-loaded DLLs */
591 if (pModule->modref_count)
593 pModule->dlls_to_init = GLOBAL_Alloc(GMEM_ZEROINIT,
594 (pModule->modref_count+1)*sizeof(HMODULE16),
595 hModule, FALSE, FALSE, FALSE );
596 if (!pModule->dlls_to_init)
598 if (pModule->nrname_handle) GlobalFree16( pModule->nrname_handle );
599 GlobalFree16( hModule );
600 return (HMODULE16)11; /* invalid exe */
603 else pModule->dlls_to_init = 0;
605 NE_RegisterModule( pModule );
606 return hModule;
610 /***********************************************************************
611 * NE_LoadDLLs
613 * Load all DLLs implicitly linked to a module.
615 static BOOL32 NE_LoadDLLs( NE_MODULE *pModule )
617 int i;
618 WORD *pModRef = (WORD *)((char *)pModule + pModule->modref_table);
619 WORD *pDLLs = (WORD *)GlobalLock16( pModule->dlls_to_init );
621 for (i = 0; i < pModule->modref_count; i++, pModRef++)
623 char buffer[256];
624 BYTE *pstr = (BYTE *)pModule + pModule->import_table + *pModRef;
625 memcpy( buffer, pstr + 1, *pstr );
626 strcpy( buffer + *pstr, ".dll" );
627 TRACE(module, "Loading '%s'\n", buffer );
628 if (!(*pModRef = MODULE_FindModule16( buffer )))
630 /* If the DLL is not loaded yet, load it and store */
631 /* its handle in the list of DLLs to initialize. */
632 HMODULE16 hDLL;
634 if ((hDLL = MODULE_Load( buffer, NE_FFLAGS_IMPLICIT,
635 NULL, NULL, 0 )) == 2)
637 /* file not found */
638 char *p;
640 /* Try with prepending the path of the current module */
641 GetModuleFileName16( pModule->self, buffer, sizeof(buffer) );
642 if (!(p = strrchr( buffer, '\\' ))) p = buffer;
643 memcpy( p + 1, pstr + 1, *pstr );
644 strcpy( p + 1 + *pstr, ".dll" );
645 hDLL = MODULE_Load( buffer, NE_FFLAGS_IMPLICIT, NULL, NULL, 0);
647 if (hDLL < 32)
649 /* FIXME: cleanup what was done */
651 fprintf( stderr, "Could not load '%s' required by '%.*s', error = %d\n",
652 buffer, *((BYTE*)pModule + pModule->name_table),
653 (char *)pModule + pModule->name_table + 1, hDLL );
654 return FALSE;
656 *pModRef = GetExePtr( hDLL );
657 *pDLLs++ = *pModRef;
659 else /* Increment the reference count of the DLL */
661 NE_MODULE *pOldDLL = MODULE_GetPtr16( *pModRef );
662 if (pOldDLL) pOldDLL->count++;
665 return TRUE;
669 /**********************************************************************
670 * NE_LoadModule
672 * Implementation of LoadModule().
674 * cmd_line must contain the whole command-line, including argv[0] (and
675 * without a preceding length byte).
676 * If cmd_line is NULL, the module is loaded as a library even if it is a .exe
678 HINSTANCE16 NE_LoadModule( HFILE32 hFile, OFSTRUCT *ofs, UINT16 flags,
679 LPCSTR cmd_line, LPCSTR env, UINT32 show_cmd )
681 HMODULE16 hModule;
682 HINSTANCE16 hInstance;
683 NE_MODULE *pModule;
685 /* Create the module structure */
687 if ((hModule = NE_LoadExeHeader( hFile, ofs )) < 32) return hModule;
689 pModule = MODULE_GetPtr16( hModule );
690 pModule->flags |= flags; /* stamp implicitly loaded modules */
692 /* Allocate the segments for this module */
694 NE_CreateSegments( hModule );
695 hInstance = MODULE_CreateInstance( hModule, NULL, (cmd_line == NULL) );
697 /* Load the referenced DLLs */
699 if (!NE_LoadDLLs( pModule ))
700 return 2; /* File not found (FIXME: free everything) */
702 /* Load the segments */
704 NE_LoadAllSegments( pModule );
706 /* Fixup the functions prologs */
708 NE_FixupPrologs( pModule );
710 /* Make sure the usage count is 1 on the first loading of */
711 /* the module, even if it contains circular DLL references */
713 pModule->count = 1;
715 /* Call initialization rountines for all loaded DLLs. Note that
716 * when we load implicitly linked DLLs this will be done by InitTask().
719 if ((pModule->flags & (NE_FFLAGS_LIBMODULE | NE_FFLAGS_IMPLICIT)) ==
720 NE_FFLAGS_LIBMODULE)
721 NE_InitializeDLLs( hModule );
723 /* Create a task for this instance */
725 if (cmd_line && !(pModule->flags & NE_FFLAGS_LIBMODULE))
727 PDB32 *pdb;
729 pModule->flags |= NE_FFLAGS_GUI;
731 pdb = PROCESS_Create( pModule, cmd_line, env, hInstance, 0, show_cmd );
732 if (pdb && (GetNumTasks() > 1)) Yield16();
735 return hInstance;