4 * Copyright 1995 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
30 #include <sys/types.h>
34 #include "wine/winbase16.h"
46 #include "wine/debug.h"
47 #include "wine/unicode.h"
48 #include "wine/server.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(module
);
51 WINE_DECLARE_DEBUG_CHANNEL(win32
);
52 WINE_DECLARE_DEBUG_CHANNEL(loaddll
);
55 /****************************************************************************
56 * DisableThreadLibraryCalls (KERNEL32.@)
58 * Inform the module loader that thread notifications are not required for a dll.
61 * hModule [I] Module handle to skip calls for
64 * Success: TRUE. Thread attach and detach notifications will not be sent
66 * Failure: FALSE. Use GetLastError() to determine the cause.
69 * This is typically called from the dll entry point of a dll during process
70 * attachment, for dlls that do not need to process thread notifications.
72 BOOL WINAPI
DisableThreadLibraryCalls( HMODULE hModule
)
74 NTSTATUS nts
= LdrDisableThreadCalloutsForDll( hModule
);
75 if (nts
== STATUS_SUCCESS
) return TRUE
;
77 SetLastError( RtlNtStatusToDosError( nts
) );
82 /* Check whether a file is an OS/2 or a very old Windows executable
83 * by testing on import of KERNEL.
85 * FIXME: is reading the module imports the only way of discerning
86 * old Windows binaries from OS/2 ones ? At least it seems so...
88 static enum binary_type
MODULE_Decide_OS2_OldWin(HANDLE hfile
, const IMAGE_DOS_HEADER
*mz
,
89 const IMAGE_OS2_HEADER
*ne
)
91 DWORD currpos
= SetFilePointer( hfile
, 0, NULL
, SEEK_CUR
);
92 enum binary_type ret
= BINARY_OS216
;
98 /* read modref table */
99 if ( (SetFilePointer( hfile
, mz
->e_lfanew
+ ne
->ne_modtab
, NULL
, SEEK_SET
) == -1)
100 || (!(modtab
= HeapAlloc( GetProcessHeap(), 0, ne
->ne_cmod
*sizeof(WORD
))))
101 || (!(ReadFile(hfile
, modtab
, ne
->ne_cmod
*sizeof(WORD
), &len
, NULL
)))
102 || (len
!= ne
->ne_cmod
*sizeof(WORD
)) )
105 /* read imported names table */
106 if ( (SetFilePointer( hfile
, mz
->e_lfanew
+ ne
->ne_imptab
, NULL
, SEEK_SET
) == -1)
107 || (!(nametab
= HeapAlloc( GetProcessHeap(), 0, ne
->ne_enttab
- ne
->ne_imptab
)))
108 || (!(ReadFile(hfile
, nametab
, ne
->ne_enttab
- ne
->ne_imptab
, &len
, NULL
)))
109 || (len
!= ne
->ne_enttab
- ne
->ne_imptab
) )
112 for (i
=0; i
< ne
->ne_cmod
; i
++)
114 LPSTR module
= &nametab
[modtab
[i
]];
115 TRACE("modref: %.*s\n", module
[0], &module
[1]);
116 if (!(strncmp(&module
[1], "KERNEL", module
[0])))
117 { /* very old Windows file */
118 MESSAGE("This seems to be a very old (pre-3.0) Windows executable. Expect crashes, especially if this is a real-mode binary !\n");
125 ERR("Hmm, an error occurred. Is this binary file broken ?\n");
128 HeapFree( GetProcessHeap(), 0, modtab
);
129 HeapFree( GetProcessHeap(), 0, nametab
);
130 SetFilePointer( hfile
, currpos
, NULL
, SEEK_SET
); /* restore filepos */
134 /***********************************************************************
135 * MODULE_GetBinaryType
137 enum binary_type
MODULE_GetBinaryType( HANDLE hfile
)
143 unsigned char magic
[4];
144 unsigned char ignored
[12];
150 unsigned long cputype
;
151 unsigned long cpusubtype
;
152 unsigned long filetype
;
160 /* Seek to the start of the file and read the header information. */
161 if (SetFilePointer( hfile
, 0, NULL
, SEEK_SET
) == -1)
162 return BINARY_UNKNOWN
;
163 if (!ReadFile( hfile
, &header
, sizeof(header
), &len
, NULL
) || len
!= sizeof(header
))
164 return BINARY_UNKNOWN
;
166 if (!memcmp( header
.elf
.magic
, "\177ELF", 4 ))
168 /* FIXME: we don't bother to check byte order, architecture, etc. */
169 switch(header
.elf
.type
)
171 case 2: return BINARY_UNIX_EXE
;
172 case 3: return BINARY_UNIX_LIB
;
174 return BINARY_UNKNOWN
;
177 /* Mach-o File with Endian set to Big Endian or Little Endian*/
178 if (header
.macho
.magic
== 0xfeedface || header
.macho
.magic
== 0xecafdeef)
180 switch(header
.macho
.filetype
)
182 case 0x8: /* MH_BUNDLE */ return BINARY_UNIX_LIB
;
184 return BINARY_UNKNOWN
;
187 /* Not ELF, try DOS */
189 if (header
.mz
.e_magic
== IMAGE_DOS_SIGNATURE
)
191 /* We do have a DOS image so we will now try to seek into
192 * the file by the amount indicated by the field
193 * "Offset to extended header" and read in the
194 * "magic" field information at that location.
195 * This will tell us if there is more header information
198 /* But before we do we will make sure that header
199 * structure encompasses the "Offset to extended header"
202 if (header
.mz
.e_lfanew
< sizeof(IMAGE_DOS_HEADER
))
204 if (SetFilePointer( hfile
, header
.mz
.e_lfanew
, NULL
, SEEK_SET
) == -1)
206 if (!ReadFile( hfile
, magic
, sizeof(magic
), &len
, NULL
) || len
!= sizeof(magic
))
209 /* Reading the magic field succeeded so
210 * we will try to determine what type it is.
212 if (!memcmp( magic
, "PE\0\0", 4 ))
214 IMAGE_FILE_HEADER FileHeader
;
216 if (ReadFile( hfile
, &FileHeader
, sizeof(FileHeader
), &len
, NULL
) && len
== sizeof(FileHeader
))
218 if (FileHeader
.Characteristics
& IMAGE_FILE_DLL
) return BINARY_PE_DLL
;
219 return BINARY_PE_EXE
;
224 if (!memcmp( magic
, "NE", 2 ))
226 /* This is a Windows executable (NE) header. This can
227 * mean either a 16-bit OS/2 or a 16-bit Windows or even a
228 * DOS program (running under a DOS extender). To decide
229 * which, we'll have to read the NE header.
232 if ( SetFilePointer( hfile
, header
.mz
.e_lfanew
, NULL
, SEEK_SET
) != -1
233 && ReadFile( hfile
, &ne
, sizeof(ne
), &len
, NULL
)
234 && len
== sizeof(ne
) )
236 switch ( ne
.ne_exetyp
)
238 case 2: return BINARY_WIN16
;
239 case 5: return BINARY_DOS
;
240 default: return MODULE_Decide_OS2_OldWin(hfile
, &header
.mz
, &ne
);
243 /* Couldn't read header, so abort. */
247 /* Unknown extended header, but this file is nonetheless DOS-executable. */
251 return BINARY_UNKNOWN
;
254 /***********************************************************************
255 * GetBinaryTypeA [KERNEL32.@]
256 * GetBinaryType [KERNEL32.@]
258 * Determine whether a file is executable, and if so, what kind.
261 * lpApplicationName [I] Path of the file to check
262 * lpBinaryType [O] Destination for the binary type
265 * TRUE, if the file is an executable, in which case lpBinaryType is set.
266 * FALSE, if the file is not an executable or if the function fails.
269 * The type of executable is a property that determines which subsytem an
270 * executable file runs under. lpBinaryType can be set to one of the following
272 * SCS_32BIT_BINARY: A Win32 based application
273 * SCS_DOS_BINARY: An MS-Dos based application
274 * SCS_WOW_BINARY: A Win16 based application
275 * SCS_PIF_BINARY: A PIF file that executes an MS-Dos based app
276 * SCS_POSIX_BINARY: A POSIX based application ( Not implemented )
277 * SCS_OS216_BINARY: A 16bit OS/2 based application
279 * To find the binary type, this function reads in the files header information.
280 * If extended header information is not present it will assume that the file
281 * is a DOS executable. If extended header information is present it will
282 * determine if the file is a 16 or 32 bit Windows executable by checking the
283 * flags in the header.
285 * ".com" and ".pif" files are only recognized by their file name extension,
286 * as per native Windows.
288 BOOL WINAPI
GetBinaryTypeA( LPCSTR lpApplicationName
, LPDWORD lpBinaryType
)
294 TRACE_(win32
)("%s\n", lpApplicationName
);
298 if ( lpApplicationName
== NULL
|| lpBinaryType
== NULL
)
301 /* Open the file indicated by lpApplicationName for reading.
303 hfile
= CreateFileA( lpApplicationName
, GENERIC_READ
, FILE_SHARE_READ
,
304 NULL
, OPEN_EXISTING
, 0, 0 );
305 if ( hfile
== INVALID_HANDLE_VALUE
)
310 switch(MODULE_GetBinaryType( hfile
))
313 /* try to determine from file name */
314 ptr
= strrchr( lpApplicationName
, '.' );
316 if (!FILE_strcasecmp( ptr
, ".COM" ))
318 *lpBinaryType
= SCS_DOS_BINARY
;
321 else if (!FILE_strcasecmp( ptr
, ".PIF" ))
323 *lpBinaryType
= SCS_PIF_BINARY
;
329 *lpBinaryType
= SCS_32BIT_BINARY
;
333 *lpBinaryType
= SCS_WOW_BINARY
;
337 *lpBinaryType
= SCS_OS216_BINARY
;
341 *lpBinaryType
= SCS_DOS_BINARY
;
344 case BINARY_UNIX_EXE
:
345 case BINARY_UNIX_LIB
:
350 CloseHandle( hfile
);
354 /***********************************************************************
355 * GetBinaryTypeW [KERNEL32.@]
357 * Unicode version of GetBinaryTypeA.
359 BOOL WINAPI
GetBinaryTypeW( LPCWSTR lpApplicationName
, LPDWORD lpBinaryType
)
364 TRACE_(win32
)("%s\n", debugstr_w(lpApplicationName
) );
368 if ( lpApplicationName
== NULL
|| lpBinaryType
== NULL
)
371 /* Convert the wide string to a ascii string.
373 strNew
= HEAP_strdupWtoA( GetProcessHeap(), 0, lpApplicationName
);
375 if ( strNew
!= NULL
)
377 ret
= GetBinaryTypeA( strNew
, lpBinaryType
);
379 /* Free the allocated string.
381 HeapFree( GetProcessHeap(), 0, strNew
);
388 /***********************************************************************
389 * GetModuleHandleA (KERNEL32.@)
390 * GetModuleHandle32 (KERNEL.488)
392 * Get the handle of a dll loaded into the process address space.
395 * module [I] Name of the dll
398 * Success: A handle to the loaded dll.
399 * Failure: A NULL handle. Use GetLastError() to determine the cause.
401 HMODULE WINAPI
GetModuleHandleA(LPCSTR module
)
407 if (!module
) return NtCurrentTeb()->Peb
->ImageBaseAddress
;
409 RtlCreateUnicodeStringFromAsciiz(&wstr
, module
);
410 nts
= LdrGetDllHandle(0, 0, &wstr
, &ret
);
411 RtlFreeUnicodeString( &wstr
);
412 if (nts
!= STATUS_SUCCESS
)
415 SetLastError( RtlNtStatusToDosError( nts
) );
420 /***********************************************************************
421 * GetModuleHandleW (KERNEL32.@)
423 * Unicode version of GetModuleHandleA.
425 HMODULE WINAPI
GetModuleHandleW(LPCWSTR module
)
431 if (!module
) return NtCurrentTeb()->Peb
->ImageBaseAddress
;
433 RtlInitUnicodeString( &wstr
, module
);
434 nts
= LdrGetDllHandle( 0, 0, &wstr
, &ret
);
435 if (nts
!= STATUS_SUCCESS
)
437 SetLastError( RtlNtStatusToDosError( nts
) );
444 /***********************************************************************
445 * GetModuleFileNameA (KERNEL32.@)
446 * GetModuleFileName32 (KERNEL.487)
448 * Get the file name of a loaded module from its handle.
451 * Success: The length of the file name, excluding the terminating NUL.
452 * Failure: 0. Use GetLastError() to determine the cause.
455 * This function always returns the long path of hModule (as opposed to
456 * GetModuleFileName16() which returns short paths when the modules version
459 DWORD WINAPI
GetModuleFileNameA(
460 HMODULE hModule
, /* [in] Module handle (32 bit) */
461 LPSTR lpFileName
, /* [out] Destination for file name */
462 DWORD size
) /* [in] Size of lpFileName in characters */
464 LPWSTR filenameW
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(WCHAR
) );
468 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
471 GetModuleFileNameW( hModule
, filenameW
, size
);
472 WideCharToMultiByte( CP_ACP
, 0, filenameW
, -1, lpFileName
, size
, NULL
, NULL
);
473 HeapFree( GetProcessHeap(), 0, filenameW
);
474 return strlen( lpFileName
);
477 /***********************************************************************
478 * GetModuleFileNameW (KERNEL32.@)
480 * Unicode version of GetModuleFileNameA.
482 DWORD WINAPI
GetModuleFileNameW( HMODULE hModule
, LPWSTR lpFileName
, DWORD size
)
488 LdrLockLoaderLock( 0, NULL
, &magic
);
489 if (!hModule
&& !(NtCurrentTeb()->tibflags
& TEBF_WIN32
))
491 /* 16-bit task - get current NE module name */
492 NE_MODULE
*pModule
= NE_GetPtr( GetCurrentTask() );
495 WCHAR path
[MAX_PATH
];
497 MultiByteToWideChar( CP_ACP
, 0, NE_MODULE_NAME(pModule
), -1, path
, MAX_PATH
);
498 GetLongPathNameW(path
, lpFileName
, size
);
506 if (!hModule
) hModule
= NtCurrentTeb()->Peb
->ImageBaseAddress
;
507 nts
= LdrFindEntryForAddress( hModule
, &pldr
);
508 if (nts
== STATUS_SUCCESS
) lstrcpynW(lpFileName
, pldr
->FullDllName
.Buffer
, size
);
509 else SetLastError( RtlNtStatusToDosError( nts
) );
512 LdrUnlockLoaderLock( 0, magic
);
514 TRACE( "%s\n", debugstr_w(lpFileName
) );
515 return strlenW(lpFileName
);
519 /***********************************************************************
520 * get_dll_system_path
522 static const WCHAR
*get_dll_system_path(void)
531 exe_name
= NtCurrentTeb()->Peb
->ProcessParameters
->ImagePathName
.Buffer
;
532 if (!(p
= strrchrW( exe_name
, '\\' ))) p
= exe_name
;
533 /* include trailing backslash only on drive root */
534 if (p
== exe_name
+ 2 && exe_name
[1] == ':') p
++;
536 len
+= GetSystemDirectoryW( NULL
, 0 );
537 len
+= GetWindowsDirectoryW( NULL
, 0 );
538 path
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
539 memcpy( path
, exe_name
, (p
- exe_name
) * sizeof(WCHAR
) );
540 p
= path
+ (p
- exe_name
);
544 GetSystemDirectoryW( p
, path
+ len
- p
);
547 GetWindowsDirectoryW( p
, path
+ len
- p
);
553 /******************************************************************
556 * Compute the load path to use for a given dll.
557 * Returned pointer must be freed by caller.
559 static WCHAR
*get_dll_load_path( LPCWSTR module
)
561 static const WCHAR pathW
[] = {'P','A','T','H',0};
563 const WCHAR
*system_path
= get_dll_system_path();
564 const WCHAR
*mod_end
= NULL
;
565 UNICODE_STRING name
, value
;
567 int len
= 0, path_len
= 0;
569 /* adjust length for module name */
574 if ((p
= strrchrW( mod_end
, '\\' ))) mod_end
= p
;
575 if ((p
= strrchrW( mod_end
, '/' ))) mod_end
= p
;
576 if (mod_end
== module
+ 2 && module
[1] == ':') mod_end
++;
577 if (mod_end
== module
&& module
[0] && module
[1] == ':') mod_end
+= 2;
578 len
+= (mod_end
- module
);
579 system_path
= strchrW( system_path
, ';' );
581 len
+= strlenW( system_path
) + 2;
583 /* get the PATH variable */
585 RtlInitUnicodeString( &name
, pathW
);
587 value
.MaximumLength
= 0;
589 if (RtlQueryEnvironmentVariable_U( NULL
, &name
, &value
) == STATUS_BUFFER_TOO_SMALL
)
590 path_len
= value
.Length
;
592 if (!(ret
= HeapAlloc( GetProcessHeap(), 0, path_len
+ len
* sizeof(WCHAR
) ))) return NULL
;
596 memcpy( ret
, module
, (mod_end
- module
) * sizeof(WCHAR
) );
597 p
+= (mod_end
- module
);
599 strcpyW( p
, system_path
);
603 value
.MaximumLength
= path_len
;
605 while (RtlQueryEnvironmentVariable_U( NULL
, &name
, &value
) == STATUS_BUFFER_TOO_SMALL
)
609 /* grow the buffer and retry */
610 path_len
= value
.Length
;
611 if (!(new_ptr
= HeapReAlloc( GetProcessHeap(), 0, ret
, path_len
+ len
* sizeof(WCHAR
) )))
613 HeapFree( GetProcessHeap(), 0, ret
);
616 value
.Buffer
= new_ptr
+ (value
.Buffer
- ret
);
617 value
.MaximumLength
= path_len
;
620 value
.Buffer
[value
.Length
/ sizeof(WCHAR
)] = 0;
625 /******************************************************************
626 * MODULE_InitLoadPath
628 * Create the initial dll load path.
630 void MODULE_InitLoadPath(void)
632 WCHAR
*path
= get_dll_load_path( NULL
);
633 RtlInitUnicodeString( &NtCurrentTeb()->Peb
->ProcessParameters
->DllPath
, path
);
637 /******************************************************************
638 * load_library_as_datafile
640 static BOOL
load_library_as_datafile( LPCWSTR name
, HMODULE
* hmod
)
642 static const WCHAR dotDLL
[] = {'.','d','l','l',0};
644 WCHAR filenameW
[MAX_PATH
];
645 HANDLE hFile
= INVALID_HANDLE_VALUE
;
651 if (SearchPathW( NULL
, (LPCWSTR
)name
, dotDLL
, sizeof(filenameW
) / sizeof(filenameW
[0]),
654 hFile
= CreateFileW( filenameW
, GENERIC_READ
, FILE_SHARE_READ
,
655 NULL
, OPEN_EXISTING
, 0, 0 );
657 if (hFile
== INVALID_HANDLE_VALUE
) return FALSE
;
659 mapping
= CreateFileMappingW( hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
660 CloseHandle( hFile
);
661 if (!mapping
) return FALSE
;
663 module
= MapViewOfFile( mapping
, FILE_MAP_READ
, 0, 0, 0 );
664 CloseHandle( mapping
);
665 if (!module
) return FALSE
;
667 /* make sure it's a valid PE file */
668 if (!RtlImageNtHeader(module
))
670 UnmapViewOfFile( module
);
673 *hmod
= (HMODULE
)((char *)module
+ 1); /* set low bit of handle to indicate datafile module */
678 /******************************************************************
681 * Helper for LoadLibraryExA/W.
683 static HMODULE
load_library( const UNICODE_STRING
*libname
, DWORD flags
)
689 if (flags
& LOAD_LIBRARY_AS_DATAFILE
)
691 /* The method in load_library_as_datafile allows searching for the
692 * 'native' libraries only
694 if (load_library_as_datafile( libname
->Buffer
, &hModule
)) return hModule
;
695 flags
|= DONT_RESOLVE_DLL_REFERENCES
; /* Just in case */
696 /* Fallback to normal behaviour */
699 load_path
= get_dll_load_path( flags
& LOAD_WITH_ALTERED_SEARCH_PATH
? libname
->Buffer
: NULL
);
700 nts
= LdrLoadDll( load_path
, flags
, libname
, &hModule
);
701 HeapFree( GetProcessHeap(), 0, load_path
);
702 if (nts
!= STATUS_SUCCESS
)
705 SetLastError( RtlNtStatusToDosError( nts
) );
711 /******************************************************************
712 * LoadLibraryExA (KERNEL32.@)
714 * Load a dll file into the process address space.
717 * libname [I] Name of the file to load
718 * hfile [I] Reserved, must be 0.
719 * flags [I] Flags for loading the dll
722 * Success: A handle to the loaded dll.
723 * Failure: A NULL handle. Use GetLastError() to determine the cause.
726 * The HFILE parameter is not used and marked reserved in the SDK. I can
727 * only guess that it should force a file to be mapped, but I rather
728 * ignore the parameter because it would be extremely difficult to
729 * integrate this with different types of module representations.
731 HMODULE WINAPI
LoadLibraryExA(LPCSTR libname
, HANDLE hfile
, DWORD flags
)
738 SetLastError(ERROR_INVALID_PARAMETER
);
741 RtlCreateUnicodeStringFromAsciiz( &wstr
, libname
);
742 hModule
= load_library( &wstr
, flags
);
743 RtlFreeUnicodeString( &wstr
);
747 /***********************************************************************
748 * LoadLibraryExW (KERNEL32.@)
750 * Unicode version of LoadLibraryExA.
752 HMODULE WINAPI
LoadLibraryExW(LPCWSTR libnameW
, HANDLE hfile
, DWORD flags
)
758 SetLastError(ERROR_INVALID_PARAMETER
);
761 RtlInitUnicodeString( &wstr
, libnameW
);
762 return load_library( &wstr
, flags
);
765 /***********************************************************************
766 * LoadLibraryA (KERNEL32.@)
768 * Load a dll file into the process address space.
771 * libname [I] Name of the file to load
774 * Success: A handle to the loaded dll.
775 * Failure: A NULL handle. Use GetLastError() to determine the cause.
778 * See LoadLibraryExA().
780 HMODULE WINAPI
LoadLibraryA(LPCSTR libname
)
782 return LoadLibraryExA(libname
, 0, 0);
785 /***********************************************************************
786 * LoadLibraryW (KERNEL32.@)
788 * Unicode version of LoadLibraryA.
790 HMODULE WINAPI
LoadLibraryW(LPCWSTR libnameW
)
792 return LoadLibraryExW(libnameW
, 0, 0);
795 /***********************************************************************
796 * FreeLibrary (KERNEL32.@)
797 * FreeLibrary32 (KERNEL.486)
799 * Free a dll loaded into the process address space.
802 * hLibModule [I] Handle to the dll returned by LoadLibraryA().
805 * Success: TRUE. The dll is removed if it is not still in use.
806 * Failure: FALSE. Use GetLastError() to determine the cause.
808 BOOL WINAPI
FreeLibrary(HINSTANCE hLibModule
)
815 SetLastError( ERROR_INVALID_HANDLE
);
819 if ((ULONG_PTR
)hLibModule
& 1)
821 /* this is a LOAD_LIBRARY_AS_DATAFILE module */
822 char *ptr
= (char *)hLibModule
- 1;
823 UnmapViewOfFile( ptr
);
827 if ((nts
= LdrUnloadDll( hLibModule
)) == STATUS_SUCCESS
) retv
= TRUE
;
828 else SetLastError( RtlNtStatusToDosError( nts
) );
833 /***********************************************************************
834 * GetProcAddress (KERNEL32.@)
836 * Find the address of an exported symbol in a loaded dll.
839 * hModule [I] Handle to the dll returned by LoadLibraryA().
840 * function [I] Name of the symbol, or an integer ordinal number < 16384
843 * Success: A pointer to the symbol in the process address space.
844 * Failure: NULL. Use GetLastError() to determine the cause.
846 FARPROC WINAPI
GetProcAddress( HMODULE hModule
, LPCSTR function
)
851 if (HIWORD(function
))
855 RtlInitAnsiString( &str
, function
);
856 nts
= LdrGetProcedureAddress( hModule
, &str
, 0, (void**)&fp
);
859 nts
= LdrGetProcedureAddress( hModule
, NULL
, (DWORD
)function
, (void**)&fp
);
860 if (nts
!= STATUS_SUCCESS
)
862 SetLastError( RtlNtStatusToDosError( nts
) );
868 /***********************************************************************
869 * GetProcAddress32 (KERNEL.453)
871 * Find the address of an exported symbol in a loaded dll.
874 * hModule [I] Handle to the dll returned by LoadLibraryA().
875 * function [I] Name of the symbol, or an integer ordinal number < 16384
878 * Success: A pointer to the symbol in the process address space.
879 * Failure: NULL. Use GetLastError() to determine the cause.
881 FARPROC WINAPI
GetProcAddress32_16( HMODULE hModule
, LPCSTR function
)
883 /* FIXME: we used to disable snoop when returning proc for Win16 subsystem */
884 return GetProcAddress( hModule
, function
);