Artifact
24fc12d0257b29d77da2903ed51e70d2fad1baab :
File
expat/loadlibrary.c
— part of check-in
[5034d18e1a]
at
2017-11-16 22:18:45
on branch expat-update
— Updated to expat 2.2.5.
(user:
rolf
size: 5267)
[more...]
0000: 2f 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a /***************
0010: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0020: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0030: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0040: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 0a 20 2a 20 ************. *
0050: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0060: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0070: 20 5f 20 20 20 5f 20 5f 5f 5f 5f 20 20 5f 0a 20 _ _ ____ _.
0080: 2a 20 20 50 72 6f 6a 65 63 74 20 20 20 20 20 20 * Project
0090: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 5f _
00a0: 5f 5f 7c 20 7c 20 7c 20 7c 20 20 5f 20 5c 7c 20 __| | | | _ \|
00b0: 7c 0a 20 2a 20 20 20 20 20 20 20 20 20 20 20 20 |. *
00c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
00d0: 20 2f 20 5f 5f 7c 20 7c 20 7c 20 7c 20 7c 5f 29 / __| | | | |_)
00e0: 20 7c 20 7c 0a 20 2a 20 20 20 20 20 20 20 20 20 | |. *
00f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0100: 20 20 20 7c 20 28 5f 5f 7c 20 7c 5f 7c 20 7c 20 | (__| |_| |
0110: 20 5f 20 3c 7c 20 7c 5f 5f 5f 0a 20 2a 20 20 20 _ <| |___. *
0120: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0130: 20 20 20 20 20 20 20 20 20 20 5c 5f 5f 5f 7c 5c \___|\
0140: 5f 5f 5f 2f 7c 5f 7c 20 5c 5f 5c 5f 5f 5f 5f 5f ___/|_| \_\_____
0150: 7c 0a 20 2a 0a 20 2a 20 43 6f 70 79 72 69 67 68 |. *. * Copyrigh
0160: 74 20 28 43 29 20 32 30 31 36 20 2d 20 32 30 31 t (C) 2016 - 201
0170: 37 2c 20 53 74 65 76 65 20 48 6f 6c 6d 65 2c 20 7, Steve Holme,
0180: 3c 73 74 65 76 65 5f 68 6f 6c 6d 65 40 68 6f 74 <steve_holme@hot
0190: 6d 61 69 6c 2e 63 6f 6d 3e 2e 0a 20 2a 20 43 6f mail.com>.. * Co
01a0: 70 79 72 69 67 68 74 20 28 43 29 20 32 30 31 37 pyright (C) 2017
01b0: 2c 20 45 78 70 61 74 20 64 65 76 65 6c 6f 70 6d , Expat developm
01c0: 65 6e 74 20 74 65 61 6d 0a 20 2a 0a 20 2a 20 41 ent team. *. * A
01d0: 6c 6c 20 72 69 67 68 74 73 20 72 65 73 65 72 76 ll rights reserv
01e0: 65 64 2e 0a 20 2a 20 4c 69 63 65 6e 73 65 64 20 ed.. * Licensed
01f0: 75 6e 64 65 72 20 74 68 65 20 4d 49 54 20 6c 69 under the MIT li
0200: 63 65 6e 73 65 3a 0a 20 2a 0a 20 2a 20 50 65 72 cense:. *. * Per
0210: 6d 69 73 73 69 6f 6e 20 74 6f 20 20 75 73 65 2c mission to use,
0220: 20 63 6f 70 79 2c 20 20 6d 6f 64 69 66 79 2c 20 copy, modify,
0230: 61 6e 64 20 64 69 73 74 72 69 62 75 74 65 20 20 and distribute
0240: 74 68 69 73 20 73 6f 66 74 77 61 72 65 20 20 66 this software f
0250: 6f 72 20 61 6e 79 0a 20 2a 20 70 75 72 70 6f 73 or any. * purpos
0260: 65 20 77 69 74 68 20 20 6f 72 20 77 69 74 68 6f e with or witho
0270: 75 74 20 66 65 65 20 69 73 20 20 68 65 72 65 62 ut fee is hereb
0280: 79 20 67 72 61 6e 74 65 64 2c 20 70 72 6f 76 69 y granted, provi
0290: 64 65 64 20 74 68 61 74 20 20 74 68 65 20 61 62 ded that the ab
02a0: 6f 76 65 0a 20 2a 20 63 6f 70 79 72 69 67 68 74 ove. * copyright
02b0: 20 6e 6f 74 69 63 65 20 61 6e 64 20 74 68 69 73 notice and this
02c0: 20 70 65 72 6d 69 73 73 69 6f 6e 20 6e 6f 74 69 permission noti
02d0: 63 65 20 61 70 70 65 61 72 20 69 6e 20 61 6c 6c ce appear in all
02e0: 20 63 6f 70 69 65 73 2e 0a 20 2a 0a 20 2a 20 54 copies.. *. * T
02f0: 48 45 20 20 53 4f 46 54 57 41 52 45 20 20 49 53 HE SOFTWARE IS
0300: 20 20 50 52 4f 56 49 44 45 44 20 20 22 41 53 20 PROVIDED "AS
0310: 20 49 53 22 2c 20 20 57 49 54 48 4f 55 54 20 20 IS", WITHOUT
0320: 57 41 52 52 41 4e 54 59 20 20 4f 46 20 20 41 4e WARRANTY OF AN
0330: 59 20 20 4b 49 4e 44 2c 0a 20 2a 20 45 58 50 52 Y KIND,. * EXPR
0340: 45 53 53 20 20 4f 52 20 49 4d 50 4c 49 45 44 2c ESS OR IMPLIED,
0350: 20 20 49 4e 43 4c 55 44 49 4e 47 20 20 42 55 54 INCLUDING BUT
0360: 20 20 4e 4f 54 20 4c 49 4d 49 54 45 44 20 20 54 NOT LIMITED T
0370: 4f 20 20 54 48 45 20 57 41 52 52 41 4e 54 49 45 O THE WARRANTIE
0380: 53 20 20 4f 46 0a 20 2a 20 4d 45 52 43 48 41 4e S OF. * MERCHAN
0390: 54 41 42 49 4c 49 54 59 2c 20 46 49 54 4e 45 53 TABILITY, FITNES
03a0: 53 20 46 4f 52 20 41 20 20 50 41 52 54 49 43 55 S FOR A PARTICU
03b0: 4c 41 52 20 50 55 52 50 4f 53 45 20 41 4e 44 20 LAR PURPOSE AND
03c0: 4e 4f 4e 49 4e 46 52 49 4e 47 45 4d 45 4e 54 20 NONINFRINGEMENT
03d0: 4f 46 0a 20 2a 20 54 48 49 52 44 20 50 41 52 54 OF. * THIRD PART
03e0: 59 20 52 49 47 48 54 53 2e 20 49 4e 20 4e 4f 20 Y RIGHTS. IN NO
03f0: 45 56 45 4e 54 20 53 48 41 4c 4c 20 54 48 45 20 EVENT SHALL THE
0400: 41 55 54 48 4f 52 53 20 4f 52 20 43 4f 50 59 52 AUTHORS OR COPYR
0410: 49 47 48 54 20 48 4f 4c 44 45 52 53 20 42 45 0a IGHT HOLDERS BE.
0420: 20 2a 20 4c 49 41 42 4c 45 20 46 4f 52 20 41 4e * LIABLE FOR AN
0430: 59 20 43 4c 41 49 4d 2c 20 44 41 4d 41 47 45 53 Y CLAIM, DAMAGES
0440: 20 4f 52 20 4f 54 48 45 52 20 4c 49 41 42 49 4c OR OTHER LIABIL
0450: 49 54 59 2c 20 57 48 45 54 48 45 52 20 49 4e 20 ITY, WHETHER IN
0460: 41 4e 20 41 43 54 49 4f 4e 20 4f 46 0a 20 2a 20 AN ACTION OF. *
0470: 43 4f 4e 54 52 41 43 54 2c 20 54 4f 52 54 20 4f CONTRACT, TORT O
0480: 52 20 20 4f 54 48 45 52 57 49 53 45 2c 20 41 52 R OTHERWISE, AR
0490: 49 53 49 4e 47 20 46 52 4f 4d 2c 20 4f 55 54 20 ISING FROM, OUT
04a0: 4f 46 20 4f 52 20 20 49 4e 20 43 4f 4e 4e 45 43 OF OR IN CONNEC
04b0: 54 49 4f 4e 20 57 49 54 48 0a 20 2a 20 54 48 45 TION WITH. * THE
04c0: 20 53 4f 46 54 57 41 52 45 20 4f 52 20 54 48 45 SOFTWARE OR THE
04d0: 20 55 53 45 20 4f 52 20 4f 54 48 45 52 20 44 45 USE OR OTHER DE
04e0: 41 4c 49 4e 47 53 20 49 4e 20 54 48 45 20 53 4f ALINGS IN THE SO
04f0: 46 54 57 41 52 45 2e 0a 20 2a 0a 20 2a 20 45 78 FTWARE.. *. * Ex
0500: 63 65 70 74 20 61 73 20 63 6f 6e 74 61 69 6e 65 cept as containe
0510: 64 20 69 6e 20 74 68 69 73 20 6e 6f 74 69 63 65 d in this notice
0520: 2c 20 20 74 68 65 20 6e 61 6d 65 20 6f 66 20 61 , the name of a
0530: 20 63 6f 70 79 72 69 67 68 74 20 68 6f 6c 64 65 copyright holde
0540: 72 20 73 68 61 6c 6c 0a 20 2a 20 6e 6f 74 20 62 r shall. * not b
0550: 65 20 75 73 65 64 20 69 6e 20 61 64 76 65 72 74 e used in advert
0560: 69 73 69 6e 67 20 6f 72 20 6f 74 68 65 72 77 69 ising or otherwi
0570: 73 65 20 74 6f 20 70 72 6f 6d 6f 74 65 20 74 68 se to promote th
0580: 65 20 73 61 6c 65 2c 20 75 73 65 20 6f 72 20 6f e sale, use or o
0590: 74 68 65 72 0a 20 2a 20 64 65 61 6c 69 6e 67 73 ther. * dealings
05a0: 20 20 69 6e 20 74 68 69 73 20 20 53 6f 66 74 77 in this Softw
05b0: 61 72 65 20 77 69 74 68 6f 75 74 20 20 70 72 69 are without pri
05c0: 6f 72 20 77 72 69 74 74 65 6e 20 20 61 75 74 68 or written auth
05d0: 6f 72 69 7a 61 74 69 6f 6e 20 6f 66 20 20 74 68 orization of th
05e0: 65 0a 20 2a 20 63 6f 70 79 72 69 67 68 74 20 68 e. * copyright h
05f0: 6f 6c 64 65 72 2e 0a 20 2a 0a 20 2a 2a 2a 2a 2a older.. *. *****
0600: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0610: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0620: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0630: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0640: 2a 2a 2a 2a 2a 2a 2f 0a 0a 23 69 66 20 64 65 66 ******/..#if def
0650: 69 6e 65 64 28 5f 57 49 4e 33 32 29 0a 0a 23 69 ined(_WIN32)..#i
0660: 6e 63 6c 75 64 65 20 3c 77 69 6e 64 6f 77 73 2e nclude <windows.
0670: 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 74 63 68 h>.#include <tch
0680: 61 72 2e 68 3e 0a 0a 0a 48 4d 4f 44 55 4c 45 20 ar.h>...HMODULE
0690: 5f 45 78 70 61 74 5f 4c 6f 61 64 4c 69 62 72 61 _Expat_LoadLibra
06a0: 72 79 28 4c 50 43 54 53 54 52 20 66 69 6c 65 6e ry(LPCTSTR filen
06b0: 61 6d 65 29 3b 0a 0a 0a 23 69 66 20 21 64 65 66 ame);...#if !def
06c0: 69 6e 65 64 28 4c 4f 41 44 5f 57 49 54 48 5f 41 ined(LOAD_WITH_A
06d0: 4c 54 45 52 45 44 5f 53 45 41 52 43 48 5f 50 41 LTERED_SEARCH_PA
06e0: 54 48 29 0a 23 64 65 66 69 6e 65 20 4c 4f 41 44 TH).#define LOAD
06f0: 5f 57 49 54 48 5f 41 4c 54 45 52 45 44 5f 53 45 _WITH_ALTERED_SE
0700: 41 52 43 48 5f 50 41 54 48 20 20 30 78 30 30 30 ARCH_PATH 0x000
0710: 30 30 30 30 38 0a 23 65 6e 64 69 66 0a 0a 23 69 00008.#endif..#i
0720: 66 20 21 64 65 66 69 6e 65 64 28 4c 4f 41 44 5f f !defined(LOAD_
0730: 4c 49 42 52 41 52 59 5f 53 45 41 52 43 48 5f 53 LIBRARY_SEARCH_S
0740: 59 53 54 45 4d 33 32 29 0a 23 64 65 66 69 6e 65 YSTEM32).#define
0750: 20 4c 4f 41 44 5f 4c 49 42 52 41 52 59 5f 53 45 LOAD_LIBRARY_SE
0760: 41 52 43 48 5f 53 59 53 54 45 4d 33 32 20 20 20 ARCH_SYSTEM32
0770: 30 78 30 30 30 30 30 38 30 30 0a 23 65 6e 64 69 0x00000800.#endi
0780: 66 0a 0a 2f 2a 20 57 65 20 75 73 65 20 6f 75 72 f../* We use our
0790: 20 6f 77 6e 20 74 79 70 65 64 65 66 20 68 65 72 own typedef her
07a0: 65 20 73 69 6e 63 65 20 73 6f 6d 65 20 68 65 61 e since some hea
07b0: 64 65 72 73 20 6d 69 67 68 74 20 6c 61 63 6b 20 ders might lack
07c0: 74 68 65 73 65 20 2a 2f 0a 74 79 70 65 64 65 66 these */.typedef
07d0: 20 48 4d 4f 44 55 4c 45 20 28 41 50 49 45 4e 54 HMODULE (APIENT
07e0: 52 59 20 2a 4c 4f 41 44 4c 49 42 52 41 52 59 45 RY *LOADLIBRARYE
07f0: 58 5f 46 4e 29 28 4c 50 43 54 53 54 52 2c 20 48 X_FN)(LPCTSTR, H
0800: 41 4e 44 4c 45 2c 20 44 57 4f 52 44 29 3b 0a 0a ANDLE, DWORD);..
0810: 2f 2a 20 53 65 65 20 66 75 6e 63 74 69 6f 6e 20 /* See function
0820: 64 65 66 69 6e 69 74 69 6f 6e 73 20 69 6e 20 77 definitions in w
0830: 69 6e 62 61 73 65 2e 68 20 2a 2f 0a 23 69 66 64 inbase.h */.#ifd
0840: 65 66 20 55 4e 49 43 4f 44 45 0a 23 20 20 69 66 ef UNICODE.# if
0850: 64 65 66 20 5f 57 49 4e 33 32 5f 57 43 45 0a 23 def _WIN32_WCE.#
0860: 20 20 20 20 64 65 66 69 6e 65 20 4c 4f 41 44 4c define LOADL
0870: 49 42 41 52 59 45 58 20 20 4c 22 4c 6f 61 64 4c IBARYEX L"LoadL
0880: 69 62 72 61 72 79 45 78 57 22 0a 23 20 20 65 6c ibraryExW".# el
0890: 73 65 0a 23 20 20 20 20 64 65 66 69 6e 65 20 4c se.# define L
08a0: 4f 41 44 4c 49 42 41 52 59 45 58 20 20 22 4c 6f OADLIBARYEX "Lo
08b0: 61 64 4c 69 62 72 61 72 79 45 78 57 22 0a 23 20 adLibraryExW".#
08c0: 20 65 6e 64 69 66 0a 23 65 6c 73 65 0a 23 20 20 endif.#else.#
08d0: 64 65 66 69 6e 65 20 4c 4f 41 44 4c 49 42 41 52 define LOADLIBAR
08e0: 59 45 58 20 20 20 20 22 4c 6f 61 64 4c 69 62 72 YEX "LoadLibr
08f0: 61 72 79 45 78 41 22 0a 23 65 6e 64 69 66 0a 0a aryExA".#endif..
0900: 0a 2f 2a 0a 20 2a 20 5f 45 78 70 61 74 5f 4c 6f ./*. * _Expat_Lo
0910: 61 64 4c 69 62 72 61 72 79 28 29 0a 20 2a 0a 20 adLibrary(). *.
0920: 2a 20 54 68 69 73 20 69 73 20 75 73 65 64 20 74 * This is used t
0930: 6f 20 64 79 6e 61 6d 69 63 61 6c 6c 79 20 6c 6f o dynamically lo
0940: 61 64 20 44 4c 4c 73 20 75 73 69 6e 67 20 74 68 ad DLLs using th
0950: 65 20 6d 6f 73 74 20 73 65 63 75 72 65 20 6d 65 e most secure me
0960: 74 68 6f 64 20 61 76 61 69 6c 61 62 6c 65 0a 20 thod available.
0970: 2a 20 66 6f 72 20 74 68 65 20 76 65 72 73 69 6f * for the versio
0980: 6e 20 6f 66 20 57 69 6e 64 6f 77 73 20 74 68 61 n of Windows tha
0990: 74 20 77 65 20 61 72 65 20 72 75 6e 6e 69 6e 67 t we are running
09a0: 20 6f 6e 2e 0a 20 2a 0a 20 2a 20 50 61 72 61 6d on.. *. * Param
09b0: 65 74 65 72 73 3a 0a 20 2a 0a 20 2a 20 66 69 6c eters:. *. * fil
09c0: 65 6e 61 6d 65 20 20 5b 69 6e 5d 20 2d 20 54 68 ename [in] - Th
09d0: 65 20 66 69 6c 65 6e 61 6d 65 20 6f 72 20 66 75 e filename or fu
09e0: 6c 6c 20 70 61 74 68 20 6f 66 20 74 68 65 20 44 ll path of the D
09f0: 4c 4c 20 74 6f 20 6c 6f 61 64 2e 20 49 66 20 6f LL to load. If o
0a00: 6e 6c 79 20 74 68 65 0a 20 2a 20 20 20 20 20 20 nly the. *
0a10: 20 20 20 20 20 20 20 20 20 20 20 20 66 69 6c 65 file
0a20: 6e 61 6d 65 20 69 73 20 70 61 73 73 65 64 20 74 name is passed t
0a30: 68 65 6e 20 74 68 65 20 44 4c 4c 20 77 69 6c 6c hen the DLL will
0a40: 20 62 65 20 6c 6f 61 64 65 64 20 66 72 6f 6d 20 be loaded from
0a50: 74 68 65 0a 20 2a 20 20 20 20 20 20 20 20 20 20 the. *
0a60: 20 20 20 20 20 20 20 20 57 69 6e 64 6f 77 73 20 Windows
0a70: 73 79 73 74 65 6d 20 64 69 72 65 63 74 6f 72 79 system directory
0a80: 2e 0a 20 2a 0a 20 2a 20 52 65 74 75 72 6e 73 20 .. *. * Returns
0a90: 74 68 65 20 68 61 6e 64 6c 65 20 6f 66 20 74 68 the handle of th
0aa0: 65 20 6d 6f 64 75 6c 65 20 6f 6e 20 73 75 63 63 e module on succ
0ab0: 65 73 73 3b 20 6f 74 68 65 72 77 69 73 65 20 4e ess; otherwise N
0ac0: 55 4c 4c 2e 0a 20 2a 2f 0a 48 4d 4f 44 55 4c 45 ULL.. */.HMODULE
0ad0: 20 5f 45 78 70 61 74 5f 4c 6f 61 64 4c 69 62 72 _Expat_LoadLibr
0ae0: 61 72 79 28 4c 50 43 54 53 54 52 20 66 69 6c 65 ary(LPCTSTR file
0af0: 6e 61 6d 65 29 0a 7b 0a 20 20 48 4d 4f 44 55 4c name).{. HMODUL
0b00: 45 20 68 4d 6f 64 75 6c 65 20 3d 20 4e 55 4c 4c E hModule = NULL
0b10: 3b 0a 20 20 4c 4f 41 44 4c 49 42 52 41 52 59 45 ;. LOADLIBRARYE
0b20: 58 5f 46 4e 20 70 4c 6f 61 64 4c 69 62 72 61 72 X_FN pLoadLibrar
0b30: 79 45 78 20 3d 20 4e 55 4c 4c 3b 0a 0a 20 20 2f yEx = NULL;.. /
0b40: 2a 20 47 65 74 20 61 20 68 61 6e 64 6c 65 20 74 * Get a handle t
0b50: 6f 20 6b 65 72 6e 65 6c 33 32 20 73 6f 20 77 65 o kernel32 so we
0b60: 20 63 61 6e 20 61 63 63 65 73 73 20 69 74 27 73 can access it's
0b70: 20 66 75 6e 63 74 69 6f 6e 73 20 61 74 20 72 75 functions at ru
0b80: 6e 74 69 6d 65 20 2a 2f 0a 20 20 48 4d 4f 44 55 ntime */. HMODU
0b90: 4c 45 20 68 4b 65 72 6e 65 6c 33 32 20 3d 20 47 LE hKernel32 = G
0ba0: 65 74 4d 6f 64 75 6c 65 48 61 6e 64 6c 65 28 54 etModuleHandle(T
0bb0: 45 58 54 28 22 6b 65 72 6e 65 6c 33 32 22 29 29 EXT("kernel32"))
0bc0: 3b 0a 20 20 69 66 28 21 68 4b 65 72 6e 65 6c 33 ;. if(!hKernel3
0bd0: 32 29 0a 20 20 20 20 72 65 74 75 72 6e 20 4e 55 2). return NU
0be0: 4c 4c 3b 20 20 2f 2a 20 4c 43 4f 56 5f 45 58 43 LL; /* LCOV_EXC
0bf0: 4c 5f 4c 49 4e 45 20 2a 2f 0a 0a 20 20 2f 2a 20 L_LINE */.. /*
0c00: 41 74 74 65 6d 70 74 20 74 6f 20 66 69 6e 64 20 Attempt to find
0c10: 4c 6f 61 64 4c 69 62 72 61 72 79 45 78 28 29 20 LoadLibraryEx()
0c20: 77 68 69 63 68 20 69 73 20 6f 6e 6c 79 20 61 76 which is only av
0c30: 61 69 6c 61 62 6c 65 20 6f 6e 20 57 69 6e 64 6f ailable on Windo
0c40: 77 73 20 32 30 30 30 0a 20 20 20 20 20 61 6e 64 ws 2000. and
0c50: 20 61 62 6f 76 65 20 2a 2f 0a 20 20 70 4c 6f 61 above */. pLoa
0c60: 64 4c 69 62 72 61 72 79 45 78 20 3d 20 28 4c 4f dLibraryEx = (LO
0c70: 41 44 4c 49 42 52 41 52 59 45 58 5f 46 4e 29 20 ADLIBRARYEX_FN)
0c80: 47 65 74 50 72 6f 63 41 64 64 72 65 73 73 28 68 GetProcAddress(h
0c90: 4b 65 72 6e 65 6c 33 32 2c 20 4c 4f 41 44 4c 49 Kernel32, LOADLI
0ca0: 42 41 52 59 45 58 29 3b 0a 0a 20 20 2f 2a 20 44 BARYEX);.. /* D
0cb0: 65 74 65 63 74 20 69 66 20 74 68 65 72 65 27 73 etect if there's
0cc0: 20 61 6c 72 65 61 64 79 20 61 20 70 61 74 68 20 already a path
0cd0: 69 6e 20 74 68 65 20 66 69 6c 65 6e 61 6d 65 20 in the filename
0ce0: 61 6e 64 20 6c 6f 61 64 20 74 68 65 20 6c 69 62 and load the lib
0cf0: 72 61 72 79 20 69 66 0a 20 20 20 20 20 74 68 65 rary if. the
0d00: 72 65 20 69 73 2e 20 4e 6f 74 65 3a 20 42 6f 74 re is. Note: Bot
0d10: 68 20 62 61 63 6b 20 73 6c 61 73 68 65 73 20 61 h back slashes a
0d20: 6e 64 20 66 6f 72 77 61 72 64 20 73 6c 61 73 68 nd forward slash
0d30: 65 73 20 68 61 76 65 20 62 65 65 6e 20 73 75 70 es have been sup
0d40: 70 6f 72 74 65 64 0a 20 20 20 20 20 73 69 6e 63 ported. sinc
0d50: 65 20 74 68 65 20 65 61 72 6c 69 65 72 20 64 61 e the earlier da
0d60: 79 73 20 6f 66 20 44 4f 53 20 61 74 20 61 6e 20 ys of DOS at an
0d70: 41 50 49 20 6c 65 76 65 6c 20 61 6c 74 68 6f 75 API level althou
0d80: 67 68 20 74 68 65 79 20 61 72 65 20 6e 6f 74 0a gh they are not.
0d90: 20 20 20 20 20 73 75 70 70 6f 72 74 65 64 20 62 supported b
0da0: 79 20 63 6f 6d 6d 61 6e 64 20 70 72 6f 6d 70 74 y command prompt
0db0: 20 2a 2f 0a 20 20 69 66 28 5f 74 63 73 70 62 72 */. if(_tcspbr
0dc0: 6b 28 66 69 6c 65 6e 61 6d 65 2c 20 54 45 58 54 k(filename, TEXT
0dd0: 28 22 5c 5c 2f 22 29 29 29 20 7b 0a 20 20 20 20 ("\\/"))) {.
0de0: 2f 2a 2a 20 21 63 68 65 63 6b 73 72 63 21 20 64 /** !checksrc! d
0df0: 69 73 61 62 6c 65 20 42 41 4e 4e 45 44 46 55 4e isable BANNEDFUN
0e00: 43 20 31 20 2a 2a 2f 0a 20 20 20 20 68 4d 6f 64 C 1 **/. hMod
0e10: 75 6c 65 20 3d 20 70 4c 6f 61 64 4c 69 62 72 61 ule = pLoadLibra
0e20: 72 79 45 78 20 3f 0a 20 20 20 20 20 20 70 4c 6f ryEx ?. pLo
0e30: 61 64 4c 69 62 72 61 72 79 45 78 28 66 69 6c 65 adLibraryEx(file
0e40: 6e 61 6d 65 2c 20 4e 55 4c 4c 2c 20 4c 4f 41 44 name, NULL, LOAD
0e50: 5f 57 49 54 48 5f 41 4c 54 45 52 45 44 5f 53 45 _WITH_ALTERED_SE
0e60: 41 52 43 48 5f 50 41 54 48 29 20 3a 0a 20 20 20 ARCH_PATH) :.
0e70: 20 20 20 4c 6f 61 64 4c 69 62 72 61 72 79 28 66 LoadLibrary(f
0e80: 69 6c 65 6e 61 6d 65 29 3b 0a 20 20 7d 0a 20 20 ilename);. }.
0e90: 2f 2a 20 44 65 74 65 63 74 20 69 66 20 4b 42 32 /* Detect if KB2
0ea0: 35 33 33 36 32 33 20 69 73 20 69 6e 73 74 61 6c 533623 is instal
0eb0: 6c 65 64 2c 20 61 73 20 4c 4f 41 44 5f 4c 49 42 led, as LOAD_LIB
0ec0: 41 52 59 5f 53 45 41 52 43 48 5f 53 59 53 54 45 ARY_SEARCH_SYSTE
0ed0: 4d 33 32 20 69 73 20 6f 6e 6c 79 0a 20 20 20 20 M32 is only.
0ee0: 20 73 75 70 70 6f 72 74 65 64 20 6f 6e 20 57 69 supported on Wi
0ef0: 6e 64 6f 77 73 20 56 69 73 74 61 2c 20 57 69 6e ndows Vista, Win
0f00: 64 6f 77 73 20 53 65 72 76 65 72 20 32 30 30 38 dows Server 2008
0f10: 2c 20 57 69 6e 64 6f 77 73 20 37 20 61 6e 64 20 , Windows 7 and
0f20: 57 69 6e 64 6f 77 73 0a 20 20 20 20 20 53 65 72 Windows. Ser
0f30: 76 65 72 20 32 30 30 38 20 52 32 20 77 69 74 68 ver 2008 R2 with
0f40: 20 74 68 69 73 20 70 61 74 63 68 20 6f 72 20 6e this patch or n
0f50: 61 74 69 76 65 6c 79 20 6f 6e 20 57 69 6e 64 6f atively on Windo
0f60: 77 73 20 38 20 61 6e 64 20 61 62 6f 76 65 20 2a ws 8 and above *
0f70: 2f 0a 20 20 65 6c 73 65 20 69 66 28 70 4c 6f 61 /. else if(pLoa
0f80: 64 4c 69 62 72 61 72 79 45 78 20 26 26 20 47 65 dLibraryEx && Ge
0f90: 74 50 72 6f 63 41 64 64 72 65 73 73 28 68 4b 65 tProcAddress(hKe
0fa0: 72 6e 65 6c 33 32 2c 20 22 41 64 64 44 6c 6c 44 rnel32, "AddDllD
0fb0: 69 72 65 63 74 6f 72 79 22 29 29 20 7b 0a 20 20 irectory")) {.
0fc0: 20 20 2f 2a 20 4c 6f 61 64 20 74 68 65 20 44 4c /* Load the DL
0fd0: 4c 20 66 72 6f 6d 20 74 68 65 20 57 69 6e 64 6f L from the Windo
0fe0: 77 73 20 73 79 73 74 65 6d 20 64 69 72 65 63 74 ws system direct
0ff0: 6f 72 79 20 2a 2f 0a 20 20 20 20 68 4d 6f 64 75 ory */. hModu
1000: 6c 65 20 3d 20 70 4c 6f 61 64 4c 69 62 72 61 72 le = pLoadLibrar
1010: 79 45 78 28 66 69 6c 65 6e 61 6d 65 2c 20 4e 55 yEx(filename, NU
1020: 4c 4c 2c 20 4c 4f 41 44 5f 4c 49 42 52 41 52 59 LL, LOAD_LIBRARY
1030: 5f 53 45 41 52 43 48 5f 53 59 53 54 45 4d 33 32 _SEARCH_SYSTEM32
1040: 29 3b 0a 20 20 7d 0a 20 20 65 6c 73 65 20 7b 0a );. }. else {.
1050: 20 20 20 20 2f 2a 20 41 74 74 65 6d 70 74 20 74 /* Attempt t
1060: 6f 20 67 65 74 20 74 68 65 20 57 69 6e 64 6f 77 o get the Window
1070: 73 20 73 79 73 74 65 6d 20 70 61 74 68 20 2a 2f s system path */
1080: 0a 20 20 20 20 55 49 4e 54 20 73 79 73 74 65 6d . UINT system
1090: 64 69 72 6c 65 6e 20 3d 20 47 65 74 53 79 73 74 dirlen = GetSyst
10a0: 65 6d 44 69 72 65 63 74 6f 72 79 28 4e 55 4c 4c emDirectory(NULL
10b0: 2c 20 30 29 3b 0a 20 20 20 20 69 66 28 73 79 73 , 0);. if(sys
10c0: 74 65 6d 64 69 72 6c 65 6e 29 20 7b 0a 20 20 20 temdirlen) {.
10d0: 20 20 20 2f 2a 20 41 6c 6c 6f 63 61 74 65 20 73 /* Allocate s
10e0: 70 61 63 65 20 66 6f 72 20 74 68 65 20 66 75 6c pace for the ful
10f0: 6c 20 44 4c 4c 20 70 61 74 68 20 28 52 6f 6f 6d l DLL path (Room
1100: 20 66 6f 72 20 74 68 65 20 6e 75 6c 6c 20 74 65 for the null te
1110: 72 6d 69 6e 61 74 6f 72 0a 20 20 20 20 20 20 20 rminator.
1120: 20 20 69 73 20 69 6e 63 6c 75 64 65 64 20 69 6e is included in
1130: 20 73 79 73 74 65 6d 64 69 72 6c 65 6e 29 20 2a systemdirlen) *
1140: 2f 0a 20 20 20 20 20 20 73 69 7a 65 5f 74 20 66 /. size_t f
1150: 69 6c 65 6e 61 6d 65 6c 65 6e 20 3d 20 5f 74 63 ilenamelen = _tc
1160: 73 6c 65 6e 28 66 69 6c 65 6e 61 6d 65 29 3b 0a slen(filename);.
1170: 20 20 20 20 20 20 54 43 48 41 52 20 2a 70 61 74 TCHAR *pat
1180: 68 20 3d 20 6d 61 6c 6c 6f 63 28 73 69 7a 65 6f h = malloc(sizeo
1190: 66 28 54 43 48 41 52 29 20 2a 20 28 73 79 73 74 f(TCHAR) * (syst
11a0: 65 6d 64 69 72 6c 65 6e 20 2b 20 31 20 2b 20 66 emdirlen + 1 + f
11b0: 69 6c 65 6e 61 6d 65 6c 65 6e 29 29 3b 0a 20 20 ilenamelen));.
11c0: 20 20 20 20 69 66 28 70 61 74 68 20 26 26 20 47 if(path && G
11d0: 65 74 53 79 73 74 65 6d 44 69 72 65 63 74 6f 72 etSystemDirector
11e0: 79 28 70 61 74 68 2c 20 73 79 73 74 65 6d 64 69 y(path, systemdi
11f0: 72 6c 65 6e 29 29 20 7b 0a 20 20 20 20 20 20 20 rlen)) {.
1200: 20 2f 2a 20 43 61 6c 63 75 6c 61 74 65 20 74 68 /* Calculate th
1210: 65 20 66 75 6c 6c 20 44 4c 4c 20 70 61 74 68 20 e full DLL path
1220: 2a 2f 0a 20 20 20 20 20 20 20 20 5f 74 63 73 63 */. _tcsc
1230: 70 79 28 70 61 74 68 20 2b 20 5f 74 63 73 6c 65 py(path + _tcsle
1240: 6e 28 70 61 74 68 29 2c 20 54 45 58 54 28 22 5c n(path), TEXT("\
1250: 5c 22 29 29 3b 0a 20 20 20 20 20 20 20 20 5f 74 \"));. _t
1260: 63 73 63 70 79 28 70 61 74 68 20 2b 20 5f 74 63 cscpy(path + _tc
1270: 73 6c 65 6e 28 70 61 74 68 29 2c 20 66 69 6c 65 slen(path), file
1280: 6e 61 6d 65 29 3b 0a 0a 20 20 20 20 20 20 20 20 name);..
1290: 2f 2a 20 4c 6f 61 64 20 74 68 65 20 44 4c 4c 20 /* Load the DLL
12a0: 66 72 6f 6d 20 74 68 65 20 57 69 6e 64 6f 77 73 from the Windows
12b0: 20 73 79 73 74 65 6d 20 64 69 72 65 63 74 6f 72 system director
12c0: 79 20 2a 2f 0a 20 20 20 20 20 20 20 20 2f 2a 2a y */. /**
12d0: 20 21 63 68 65 63 6b 73 72 63 21 20 64 69 73 61 !checksrc! disa
12e0: 62 6c 65 20 42 41 4e 4e 45 44 46 55 4e 43 20 31 ble BANNEDFUNC 1
12f0: 20 2a 2a 2f 0a 20 20 20 20 20 20 20 20 68 4d 6f **/. hMo
1300: 64 75 6c 65 20 3d 20 70 4c 6f 61 64 4c 69 62 72 dule = pLoadLibr
1310: 61 72 79 45 78 20 3f 0a 20 20 20 20 20 20 20 20 aryEx ?.
1320: 20 20 70 4c 6f 61 64 4c 69 62 72 61 72 79 45 78 pLoadLibraryEx
1330: 28 70 61 74 68 2c 20 4e 55 4c 4c 2c 20 4c 4f 41 (path, NULL, LOA
1340: 44 5f 57 49 54 48 5f 41 4c 54 45 52 45 44 5f 53 D_WITH_ALTERED_S
1350: 45 41 52 43 48 5f 50 41 54 48 29 20 3a 0a 20 20 EARCH_PATH) :.
1360: 20 20 20 20 20 20 20 20 4c 6f 61 64 4c 69 62 72 LoadLibr
1370: 61 72 79 28 70 61 74 68 29 3b 0a 0a 20 20 20 20 ary(path);..
1380: 20 20 7d 0a 20 20 20 20 20 20 66 72 65 65 28 70 }. free(p
1390: 61 74 68 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a ath);. }. }.
13a0: 0a 20 20 72 65 74 75 72 6e 20 68 4d 6f 64 75 6c . return hModul
13b0: 65 3b 0a 7d 0a 0a 23 65 6c 73 65 20 2f 2a 20 64 e;.}..#else /* d
13c0: 65 66 69 6e 65 64 28 5f 57 49 4e 33 32 29 20 2a efined(_WIN32) *
13d0: 2f 0a 0a 2f 2a 20 49 53 4f 20 43 20 72 65 71 75 /../* ISO C requ
13e0: 69 72 65 73 20 61 20 74 72 61 6e 73 6c 61 74 69 ires a translati
13f0: 6f 6e 20 75 6e 69 74 20 74 6f 20 63 6f 6e 74 61 on unit to conta
1400: 69 6e 20 61 74 20 6c 65 61 73 74 20 6f 6e 65 20 in at least one
1410: 64 65 63 6c 61 72 61 74 69 6f 6e 0a 20 20 20 5b declaration. [
1420: 2d 57 65 6d 70 74 79 2d 74 72 61 6e 73 6c 61 74 -Wempty-translat
1430: 69 6f 6e 2d 75 6e 69 74 5d 20 2a 2f 0a 74 79 70 ion-unit] */.typ
1440: 65 64 65 66 20 69 6e 74 20 5f 54 52 41 4e 53 4c edef int _TRANSL
1450: 41 54 49 4f 4e 5f 55 4e 49 54 5f 4c 4f 41 44 5f ATION_UNIT_LOAD_
1460: 4c 49 42 52 41 52 59 5f 43 5f 4e 4f 54 5f 45 4d LIBRARY_C_NOT_EM
1470: 54 50 59 3b 0a 0a 23 65 6e 64 69 66 20 2f 2a 20 TPY;..#endif /*
1480: 64 65 66 69 6e 65 64 28 5f 57 49 4e 33 32 29 20 defined(_WIN32)
1490: 2a 2f 0a */.