Release 980628
[wine/gsoc-2012-control.git] / loader / module.c
blob2668174964daadadf8dd469da4657c5a113c261a
1 /*
2 * Modules
4 * Copyright 1995 Alexandre Julliard
5 */
7 #include <assert.h>
8 #include <fcntl.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <sys/types.h>
12 #include <unistd.h>
13 #include "windows.h"
14 #include "class.h"
15 #include "file.h"
16 #include "global.h"
17 #include "heap.h"
18 #include "module.h"
19 #include "neexe.h"
20 #include "pe_image.h"
21 #include "process.h"
22 #include "thread.h"
23 #include "resource.h"
24 #include "selectors.h"
25 #include "stackframe.h"
26 #include "task.h"
27 #include "debug.h"
28 #include "callback.h"
30 extern BOOL32 THREAD_InitDone;
33 /*************************************************************************
34 * MODULE32_LookupHMODULE
35 * looks for the referenced HMODULE in the current process
37 WINE_MODREF*
38 MODULE32_LookupHMODULE(PDB32 *process,HMODULE32 hmod) {
39 WINE_MODREF *wm;
41 if (!hmod)
42 return process->exe_modref;
43 if (!HIWORD(hmod)) {
44 ERR(module,"tried to lookup 0x%04x in win32 module handler!\n",hmod);
45 return NULL;
47 for (wm = process->modref_list;wm;wm=wm->next)
48 if (wm->module == hmod)
49 return wm;
50 return NULL;
54 /***********************************************************************
55 * MODULE_CreateDummyModule
57 * Create a dummy NE module for Win32 or Winelib.
59 HMODULE32 MODULE_CreateDummyModule( const OFSTRUCT *ofs )
61 HMODULE32 hModule;
62 NE_MODULE *pModule;
63 SEGTABLEENTRY *pSegment;
64 char *pStr,*s;
65 int len;
66 const char* basename;
68 INT32 of_size = sizeof(OFSTRUCT) - sizeof(ofs->szPathName)
69 + strlen(ofs->szPathName) + 1;
70 INT32 size = sizeof(NE_MODULE) +
71 /* loaded file info */
72 of_size +
73 /* segment table: DS,CS */
74 2 * sizeof(SEGTABLEENTRY) +
75 /* name table */
76 9 +
77 /* several empty tables */
80 hModule = GlobalAlloc16( GMEM_MOVEABLE | GMEM_ZEROINIT, size );
81 if (!hModule) return (HMODULE32)11; /* invalid exe */
83 FarSetOwner( hModule, hModule );
84 pModule = (NE_MODULE *)GlobalLock16( hModule );
86 /* Set all used entries */
87 pModule->magic = IMAGE_OS2_SIGNATURE;
88 pModule->count = 1;
89 pModule->next = 0;
90 pModule->flags = 0;
91 pModule->dgroup = 1;
92 pModule->ss = 1;
93 pModule->cs = 2;
94 pModule->heap_size = 0xe000;
95 pModule->stack_size = 0x1000;
96 pModule->seg_count = 2;
97 pModule->modref_count = 0;
98 pModule->nrname_size = 0;
99 pModule->fileinfo = sizeof(NE_MODULE);
100 pModule->os_flags = NE_OSFLAGS_WINDOWS;
101 pModule->expected_version = 0x030a;
102 pModule->self = hModule;
104 /* Set loaded file information */
105 memcpy( pModule + 1, ofs, of_size );
106 ((OFSTRUCT *)(pModule+1))->cBytes = of_size - 1;
108 pSegment = (SEGTABLEENTRY*)((char*)(pModule + 1) + of_size);
109 pModule->seg_table = pModule->dgroup_entry = (int)pSegment - (int)pModule;
110 /* Data segment */
111 pSegment->size = 0;
112 pSegment->flags = NE_SEGFLAGS_DATA;
113 pSegment->minsize = 0x1000;
114 pSegment++;
115 /* Code segment */
116 pSegment->flags = 0;
117 pSegment++;
119 /* Module name */
120 pStr = (char *)pSegment;
121 pModule->name_table = (int)pStr - (int)pModule;
122 basename = strrchr(ofs->szPathName,'\\');
123 if (!basename) basename = ofs->szPathName;
124 else basename++;
125 len = strlen(basename);
126 if ((s = strchr(basename,'.'))) len = s - basename;
127 if (len > 8) len = 8;
128 *pStr = len;
129 strncpy( pStr+1, basename, len );
130 if (len < 8) pStr[len+1] = 0;
131 pStr += 9;
133 /* All tables zero terminated */
134 pModule->res_table = pModule->import_table = pModule->entry_table =
135 (int)pStr - (int)pModule;
137 NE_RegisterModule( pModule );
138 return hModule;
142 /***********************************************************************
143 * MODULE_GetWndProcEntry16 (not a Windows API function)
145 * Return an entry point from the WPROCS dll.
147 FARPROC16 MODULE_GetWndProcEntry16( LPCSTR name )
149 FARPROC16 ret = NULL;
151 if (__winelib)
153 /* FIXME: hack for Winelib */
154 extern LRESULT ColorDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
155 extern LRESULT FileOpenDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
156 extern LRESULT FileSaveDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
157 extern LRESULT FindTextDlgProc16(HWND16,UINT16,WPARAM16,LPARAM);
158 extern LRESULT PrintDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
159 extern LRESULT PrintSetupDlgProc(HWND16,UINT16,WPARAM16,LPARAM);
160 extern LRESULT ReplaceTextDlgProc16(HWND16,UINT16,WPARAM16,LPARAM);
162 if (!strcmp(name,"ColorDlgProc"))
163 return (FARPROC16)ColorDlgProc;
164 if (!strcmp(name,"FileOpenDlgProc"))
165 return (FARPROC16)FileOpenDlgProc;
166 if (!strcmp(name,"FileSaveDlgProc"))
167 return (FARPROC16)FileSaveDlgProc;
168 if (!strcmp(name,"FindTextDlgProc"))
169 return (FARPROC16)FindTextDlgProc16;
170 if (!strcmp(name,"PrintDlgProc"))
171 return (FARPROC16)PrintDlgProc;
172 if (!strcmp(name,"PrintSetupDlgProc"))
173 return (FARPROC16)PrintSetupDlgProc;
174 if (!strcmp(name,"ReplaceTextDlgProc"))
175 return (FARPROC16)ReplaceTextDlgProc16;
176 if (!strcmp(name,"DefResourceHandler"))
177 return (FARPROC16)NE_DefResourceHandler;
178 if (!strcmp(name,"LoadDIBIconHandler"))
179 return (FARPROC16)LoadDIBIconHandler;
180 if (!strcmp(name,"LoadDIBCursorHandler"))
181 return (FARPROC16)LoadDIBCursorHandler;
182 FIXME(module,"No mapping for %s(), add one in library/miscstubs.c\n",name);
183 assert( FALSE );
184 return NULL;
186 else
188 WORD ordinal;
189 static HMODULE32 hModule = 0;
191 if (!hModule) hModule = GetModuleHandle16( "WPROCS" );
192 ordinal = NE_GetOrdinal( hModule, name );
193 if (!(ret = NE_GetEntryPoint( hModule, ordinal )))
195 WARN( module, "%s not found\n", name );
196 assert( FALSE );
199 return ret;
203 /**********************************************************************
204 * MODULE_FindModule32
206 * Find a (loaded) win32 module depending on path
207 * The handling of '.' is a bit weird, but we need it that way,
208 * for sometimes the programs use '<name>.exe' and '<name>.dll' and
209 * this is the only way to differentiate. (mainly hypertrm.exe)
211 * RETURNS
212 * the module handle if found
213 * 0 if not
215 HMODULE32 MODULE_FindModule32(
216 PDB32* process, /* [in] process in which to find the library */
217 LPCSTR path /* [in] pathname of module/library to be found */
219 LPSTR filename;
220 LPSTR dotptr;
221 WINE_MODREF *wm;
223 if (!(filename = strrchr( path, '\\' )))
224 filename = HEAP_strdupA(process->heap,0,path);
225 else
226 filename = HEAP_strdupA(process->heap,0,filename+1);
227 dotptr=strrchr(filename,'.');
229 if (!process) {
230 HeapFree(process->heap,0,filename);
231 return 0;
233 for (wm=process->modref_list;wm;wm=wm->next) {
234 LPSTR xmodname,xdotptr;
236 assert (wm->modname);
237 xmodname = HEAP_strdupA(process->heap,0,wm->modname);
238 xdotptr=strrchr(xmodname,'.');
239 if ( (xdotptr && !dotptr) ||
240 (!xdotptr && dotptr)
242 if (dotptr) *dotptr = '\0';
243 if (xdotptr) *xdotptr = '\0';
245 if (!strcasecmp( filename, xmodname)) {
246 HeapFree(process->heap,0,filename);
247 HeapFree(process->heap,0,xmodname);
248 return wm->module;
250 if (dotptr) *dotptr='.';
251 /* FIXME: add paths, shortname */
252 HeapFree(process->heap,0,xmodname);
254 HeapFree(process->heap,0,filename);
255 return 0;
260 /**********************************************************************
261 * MODULE_Load
263 * Implementation of LoadModule().
265 * cmd_line must contain the whole command-line, including argv[0] (and
266 * without a preceding length byte).
267 * If cmd_line is NULL, the module is loaded as a library even if it is a .exe
269 HINSTANCE16 MODULE_Load( LPCSTR name, BOOL32 implicit,
270 LPCSTR cmd_line, LPCSTR env, UINT32 show_cmd )
272 HMODULE16 hModule;
273 HINSTANCE16 hInstance, hPrevInstance;
274 NE_MODULE *pModule;
276 if (__winelib)
278 OFSTRUCT ofs;
279 lstrcpyn32A( ofs.szPathName, name, sizeof(ofs.szPathName) );
280 if ((hModule = MODULE_CreateDummyModule( &ofs )) < 32) return hModule;
281 pModule = (NE_MODULE *)GlobalLock16( hModule );
282 hInstance = NE_CreateInstance( pModule, &hPrevInstance,
283 (cmd_line == NULL) );
285 else
287 hInstance = NE_LoadModule( name, &hPrevInstance, implicit,
288 (cmd_line == NULL) );
289 if ((hInstance == 21) && cmd_line)
290 return PE_LoadModule( name, cmd_line, env, show_cmd );
293 /* Create a task for this instance */
295 if (hInstance < 32) return hInstance;
296 pModule = NE_GetPtr( hInstance );
297 if (cmd_line && !(pModule->flags & NE_FFLAGS_LIBMODULE))
299 PDB32 *pdb;
301 pModule->flags |= NE_FFLAGS_GUI;
303 pdb = PROCESS_Create( pModule, cmd_line, env, hInstance,
304 hPrevInstance, show_cmd );
305 if (pdb && (GetNumTasks() > 1)) Yield16();
308 return hInstance;
312 /**********************************************************************
313 * LoadModule16 (KERNEL.45)
315 HINSTANCE16 LoadModule16( LPCSTR name, LPVOID paramBlock )
317 LOADPARAMS *params;
318 LPSTR cmd_line, new_cmd_line;
319 UINT16 show_cmd = 0;
320 LPCVOID env = NULL;
321 HINSTANCE16 hInstance;
323 if (!paramBlock || (paramBlock == (LPVOID)-1))
324 return LoadLibrary16( name );
326 params = (LOADPARAMS *)paramBlock;
327 cmd_line = (LPSTR)PTR_SEG_TO_LIN( params->cmdLine );
328 /* PowerPoint passes NULL as showCmd */
329 if (params->showCmd)
330 show_cmd = *((UINT16 *)PTR_SEG_TO_LIN(params->showCmd)+1);
332 if (!cmd_line) cmd_line = "";
333 else if (*cmd_line) cmd_line++; /* skip the length byte */
335 if (!(new_cmd_line = HeapAlloc( GetProcessHeap(), 0,
336 strlen(cmd_line) + strlen(name) + 2 )))
337 return 0;
338 strcpy( new_cmd_line, name );
339 strcat( new_cmd_line, " " );
340 strcat( new_cmd_line, cmd_line );
342 if (params->hEnvironment) env = GlobalLock16( params->hEnvironment );
343 hInstance = MODULE_Load( name, FALSE, new_cmd_line, env, show_cmd );
344 if (params->hEnvironment) GlobalUnlock16( params->hEnvironment );
345 HeapFree( GetProcessHeap(), 0, new_cmd_line );
346 return hInstance;
349 /**********************************************************************
350 * LoadModule32 (KERNEL32.499)
352 * FIXME
354 * This should get implemented via CreateProcess -- MODULE_Load
355 * is resolutely 16-bit.
357 DWORD LoadModule32( LPCSTR name, LPVOID paramBlock )
359 LOADPARAMS32 *params = (LOADPARAMS32 *)paramBlock;
360 #if 0
361 STARTUPINFO st;
362 PROCESSINFORMATION pi;
363 st.cb = sizeof(STARTUPINFO);
364 st.wShowWindow = p->lpCmdShow[2] ; WRONG
366 BOOL32 ret = CreateProcess32A( name, p->lpCmdLine,
367 NULL, NULL, FALSE, 0, p->lpEnvAddress,
368 NULL, &st, &pi);
369 if (!ret) {
370 /* handle errors appropriately */
372 CloseHandle32(pi.hProcess);
373 CloseHandle32(pi.hThread);
375 #else
376 return MODULE_Load( name, FALSE, params->lpCmdLine, params->lpEnvAddress,
377 *((UINT16 *)params->lpCmdShow + 1) );
378 #endif
382 /***********************************************************************
383 * GetModuleHandle (KERNEL32.237)
385 HMODULE32 WINAPI GetModuleHandle32A(LPCSTR module)
388 TRACE(win32, "%s\n", module ? module : "NULL");
389 if (module == NULL)
390 return PROCESS_Current()->exe_modref->module;
391 else
392 return MODULE_FindModule32(PROCESS_Current(),module);
395 HMODULE32 WINAPI GetModuleHandle32W(LPCWSTR module)
397 HMODULE32 hModule;
398 LPSTR modulea = HEAP_strdupWtoA( GetProcessHeap(), 0, module );
399 hModule = GetModuleHandle32A( modulea );
400 HeapFree( GetProcessHeap(), 0, modulea );
401 return hModule;
405 /***********************************************************************
406 * GetModuleFileName32A (KERNEL32.235)
408 DWORD WINAPI GetModuleFileName32A(
409 HMODULE32 hModule, /* [in] module handle (32bit) */
410 LPSTR lpFileName, /* [out] filenamebuffer */
411 DWORD size /* [in] size of filenamebuffer */
412 ) {
413 WINE_MODREF *wm = MODULE32_LookupHMODULE(PROCESS_Current(),hModule);
415 if (!wm) /* can happen on start up or the like */
416 return 0;
418 /* FIXME: we should probably get a real long name, but wm->longname
419 * is currently a UNIX filename!
421 lstrcpyn32A( lpFileName, wm->shortname, size );
422 TRACE(module, "%s\n", lpFileName );
423 return strlen(lpFileName);
427 /***********************************************************************
428 * GetModuleFileName32W (KERNEL32.236)
430 DWORD WINAPI GetModuleFileName32W( HMODULE32 hModule, LPWSTR lpFileName,
431 DWORD size )
433 LPSTR fnA = (char*)HeapAlloc( GetProcessHeap(), 0, size );
434 DWORD res = GetModuleFileName32A( hModule, fnA, size );
435 lstrcpynAtoW( lpFileName, fnA, size );
436 HeapFree( GetProcessHeap(), 0, fnA );
437 return res;
441 /***********************************************************************
442 * LoadLibraryEx32W (KERNEL.513)
443 * FIXME
445 HMODULE32 WINAPI LoadLibraryEx32W16( LPCSTR libname, HANDLE16 hf,
446 DWORD flags )
448 TRACE(module,"(%s,%d,%08lx)\n",libname,hf,flags);
449 return LoadLibraryEx32A(libname, hf,flags);
452 /***********************************************************************
453 * LoadLibraryEx32A (KERNEL32)
455 HMODULE32 WINAPI LoadLibraryEx32A(LPCSTR libname,HFILE32 hfile,DWORD flags)
457 HMODULE32 hmod;
459 hmod = PE_LoadLibraryEx32A(libname,PROCESS_Current(),hfile,flags);
460 if (hmod < 32) {
461 char buffer[256];
463 strcpy( buffer, libname );
464 strcat( buffer, ".dll" );
465 hmod = PE_LoadLibraryEx32A(buffer,PROCESS_Current(),hfile,flags);
467 /* initialize all DLLs, which haven't been initialized yet. */
468 if (hmod >= 32)
469 PE_InitializeDLLs( PROCESS_Current(), DLL_PROCESS_ATTACH, NULL);
470 return hmod;
473 /***********************************************************************
474 * LoadLibraryA (KERNEL32)
476 HMODULE32 WINAPI LoadLibrary32A(LPCSTR libname) {
477 return LoadLibraryEx32A(libname,0,0);
480 /***********************************************************************
481 * LoadLibraryW (KERNEL32)
483 HMODULE32 WINAPI LoadLibrary32W(LPCWSTR libnameW)
485 return LoadLibraryEx32W(libnameW,0,0);
488 /***********************************************************************
489 * LoadLibraryExW (KERNEL32)
491 HMODULE32 WINAPI LoadLibraryEx32W(LPCWSTR libnameW,HFILE32 hfile,DWORD flags)
493 LPSTR libnameA = HEAP_strdupWtoA( GetProcessHeap(), 0, libnameW );
494 HMODULE32 ret = LoadLibraryEx32A( libnameA , hfile, flags );
496 HeapFree( GetProcessHeap(), 0, libnameA );
497 return ret;
500 /***********************************************************************
501 * FreeLibrary
503 BOOL32 WINAPI FreeLibrary32(HINSTANCE32 hLibModule)
505 FIXME(module,"(%08x): stub\n", hLibModule);
506 return TRUE; /* FIXME */
510 /***********************************************************************
511 * PrivateLoadLibrary (KERNEL32)
513 * FIXME: rough guesswork, don't know what "Private" means
515 HINSTANCE32 WINAPI PrivateLoadLibrary(LPCSTR libname)
517 return (HINSTANCE32)LoadLibrary16(libname);
522 /***********************************************************************
523 * PrivateFreeLibrary (KERNEL32)
525 * FIXME: rough guesswork, don't know what "Private" means
527 void WINAPI PrivateFreeLibrary(HINSTANCE32 handle)
529 FreeLibrary16((HINSTANCE16)handle);
533 /***********************************************************************
534 * WinExec16 (KERNEL.166)
536 HINSTANCE16 WINAPI WinExec16( LPCSTR lpCmdLine, UINT16 nCmdShow )
538 return WinExec32( lpCmdLine, nCmdShow );
542 /***********************************************************************
543 * WinExec32 (KERNEL32.566)
545 HINSTANCE32 WINAPI WinExec32( LPCSTR lpCmdLine, UINT32 nCmdShow )
547 HINSTANCE32 handle = 2;
548 char *p, filename[256];
549 static int use_load_module = 1;
550 int spacelimit = 0, exhausted = 0;
552 if (!lpCmdLine)
553 return 2; /* File not found */
555 /* Keep trying to load a file by trying different filenames; e.g.,
556 for the cmdline "abcd efg hij", try "abcd" with args "efg hij",
557 then "abcd efg" with arg "hij", and finally "abcd efg hij" with
558 no args */
560 while(!exhausted && handle == 2) {
561 int spacecount = 0;
563 /* Build the filename and command-line */
565 lstrcpyn32A(filename, lpCmdLine,
566 sizeof(filename) - 4 /* for extension */);
568 /* Keep grabbing characters until end-of-string, tab, or until the
569 number of spaces is greater than the spacelimit */
571 for (p = filename; ; p++) {
572 if(*p == ' ') {
573 ++spacecount;
574 if(spacecount > spacelimit) {
575 ++spacelimit;
576 break;
580 if(*p == '\0' || *p == '\t') {
581 exhausted = 1;
582 break;
586 *p = '\0';
588 /* Now load the executable file */
590 if (use_load_module)
592 /* Winelib: Use LoadModule() only for the program itself */
593 if (__winelib) use_load_module = 0;
594 handle = MODULE_Load( filename, FALSE, lpCmdLine, NULL, nCmdShow );
595 if (handle == 2) /* file not found */
597 /* Check that the original file name did not have a suffix */
598 p = strrchr(filename, '.');
599 /* if there is a '.', check if either \ OR / follow */
600 if (!p || strchr(p, '/') || strchr(p, '\\'))
602 p = filename + strlen(filename);
603 strcpy( p, ".exe" );
604 handle = MODULE_Load( filename, FALSE, lpCmdLine,
605 NULL, nCmdShow );
606 *p = '\0'; /* Remove extension */
610 else
611 handle = 2; /* file not found */
613 if (handle < 32)
615 /* Try to start it as a unix program */
616 if (!fork())
618 /* Child process */
619 DOS_FULL_NAME full_name;
620 const char *unixfilename = NULL;
621 const char *argv[256], **argptr;
622 int iconic = (nCmdShow == SW_SHOWMINIMIZED ||
623 nCmdShow == SW_SHOWMINNOACTIVE);
625 THREAD_InitDone = FALSE; /* we didn't init this process */
626 /* get unixfilename */
627 if (strchr(filename, '/') ||
628 strchr(filename, ':') ||
629 strchr(filename, '\\'))
631 if (DOSFS_GetFullName( filename, TRUE, &full_name ))
632 unixfilename = full_name.long_name;
634 else unixfilename = filename;
636 if (unixfilename)
638 /* build argv */
639 argptr = argv;
640 if (iconic) *argptr++ = "-iconic";
641 *argptr++ = unixfilename;
642 p = strdup(lpCmdLine);
643 while (1)
645 while (*p && (*p == ' ' || *p == '\t')) *p++ = '\0';
646 if (!*p) break;
647 *argptr++ = p;
648 while (*p && *p != ' ' && *p != '\t') p++;
650 *argptr++ = 0;
652 /* Execute */
653 execvp(argv[0], (char**)argv);
656 /* Failed ! */
658 if (__winelib)
660 /* build argv */
661 argptr = argv;
662 *argptr++ = "wine";
663 if (iconic) *argptr++ = "-iconic";
664 *argptr++ = lpCmdLine;
665 *argptr++ = 0;
667 /* Execute */
668 execvp(argv[0] , (char**)argv);
670 /* Failed ! */
671 MSG("WinExec: can't exec 'wine %s'\n",
672 lpCmdLine);
674 exit(1);
677 } /* while (!exhausted && handle < 32) */
679 return handle;
683 /***********************************************************************
684 * WIN32_GetProcAddress16 (KERNEL32.36)
685 * Get procaddress in 16bit module from win32... (kernel32 undoc. ordinal func)
687 FARPROC16 WINAPI WIN32_GetProcAddress16( HMODULE32 hModule, LPCSTR name )
689 WORD ordinal;
690 FARPROC16 ret;
692 if (!hModule) {
693 WARN(module,"hModule may not be 0!\n");
694 return (FARPROC16)0;
696 if (HIWORD(hModule))
698 WARN( module, "hModule is Win32 handle (%08x)\n", hModule );
699 return (FARPROC16)0;
701 hModule = GetExePtr( hModule );
702 if (HIWORD(name)) {
703 ordinal = NE_GetOrdinal( hModule, name );
704 TRACE(module, "%04x '%s'\n",
705 hModule, name );
706 } else {
707 ordinal = LOWORD(name);
708 TRACE(module, "%04x %04x\n",
709 hModule, ordinal );
711 if (!ordinal) return (FARPROC16)0;
712 ret = NE_GetEntryPoint( hModule, ordinal );
713 TRACE(module,"returning %08x\n",(UINT32)ret);
714 return ret;
717 /***********************************************************************
718 * GetProcAddress16 (KERNEL.50)
720 FARPROC16 WINAPI GetProcAddress16( HMODULE16 hModule, SEGPTR name )
722 WORD ordinal;
723 FARPROC16 ret;
725 if (!hModule) hModule = GetCurrentTask();
726 hModule = GetExePtr( hModule );
728 if (HIWORD(name) != 0)
730 ordinal = NE_GetOrdinal( hModule, (LPSTR)PTR_SEG_TO_LIN(name) );
731 TRACE(module, "%04x '%s'\n",
732 hModule, (LPSTR)PTR_SEG_TO_LIN(name) );
734 else
736 ordinal = LOWORD(name);
737 TRACE(module, "%04x %04x\n",
738 hModule, ordinal );
740 if (!ordinal) return (FARPROC16)0;
742 ret = NE_GetEntryPoint( hModule, ordinal );
744 TRACE(module, "returning %08x\n", (UINT32)ret );
745 return ret;
749 /***********************************************************************
750 * GetProcAddress32 (KERNEL32.257)
752 FARPROC32 WINAPI GetProcAddress32( HMODULE32 hModule, LPCSTR function )
754 return MODULE_GetProcAddress32( PROCESS_Current(), hModule, function );
758 /***********************************************************************
759 * MODULE_GetProcAddress32 (internal)
761 FARPROC32 MODULE_GetProcAddress32(
762 PDB32 *process, /* [in] process context */
763 HMODULE32 hModule, /* [in] current module handle */
764 LPCSTR function ) /* [in] function to be looked up */
766 WINE_MODREF *wm = MODULE32_LookupHMODULE(process,hModule);
768 if (HIWORD(function))
769 TRACE(win32,"(%08lx,%s)\n",(DWORD)hModule,function);
770 else
771 TRACE(win32,"(%08lx,%p)\n",(DWORD)hModule,function);
772 if (!wm)
773 return (FARPROC32)0;
774 switch (wm->type)
776 case MODULE32_PE:
777 return PE_FindExportedFunction( process, wm, function);
778 default:
779 ERR(module,"wine_modref type %d not handled.\n",wm->type);
780 return (FARPROC32)0;
785 /***********************************************************************
786 * RtlImageNtHeaders (NTDLL)
788 LPIMAGE_NT_HEADERS WINAPI RtlImageNtHeader(HMODULE32 hModule)
790 /* basically:
791 * return hModule+(((IMAGE_DOS_HEADER*)hModule)->e_lfanew);
792 * but we could get HMODULE16 or the like (think builtin modules)
795 WINE_MODREF *wm = MODULE32_LookupHMODULE( PROCESS_Current(), hModule );
796 if (!wm || (wm->type != MODULE32_PE)) return (LPIMAGE_NT_HEADERS)0;
797 return PE_HEADER(wm->module);