ReactOS  0.4.14-dev-49-gfb4591c
LoadLibraryExW.c
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Giannis Adamopoulos
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18 
19 #include "precomp.h"
20 
22 VOID _ActivateCtx(HANDLE h, ULONG_PTR *cookie, int line);
23 VOID _DeactivateCtx(ULONG_PTR cookie, int line);
24 
25 typedef DWORD (WINAPI *LPGETVERSION)();
26 
27 VOID _TestVesion(HANDLE dll, DWORD ExpectedVersion, int line)
28 {
30  DWORD version = proc();
31  ok_(__FILE__, line)(version == ExpectedVersion, "Got version %lu, expected %lu\n", version, ExpectedVersion);
32 }
33 
35 {
36  HANDLE dll1, dll2, h;
37  ULONG_PTR cookie;
38 
39  /* Try to load the libraries without sxs */
40  dll1 = LoadLibraryExW(L"kernel32test_versioned.dll",0 , 0);
41  ok (dll1 != NULL, "LoadLibraryExW failed\n");
42  dll2 = LoadLibraryExW(L"testdata\\kernel32test_versioned.dll",0 , 0);
43  ok (dll2 != NULL, "LoadLibraryExW failed\n");
44 
45  ok (dll1 != dll2, "\n");
46  _TestVesion(dll1, 1, __LINE__);
47  _TestVesion(dll2, 2, __LINE__);
48 
49  FreeLibrary(dll1);
50  FreeLibrary(dll2);
51 
52  dll1 = LoadLibraryExW(L"kernel32test_versioned.dll",0 , 0);
53  ok (dll1 != NULL, "LoadLibraryExW failed\n");
54 
55  /* redir2dep.manifest defines an assembly with nothing but a dependency on redirtest2 assembly */
56  /* redirtest2.manifest defines an assembly that contains kernel32test_versioned.dll */
57  /* In win10 it is enought to load and activate redirtest2 */
58  /* In win2k3 however the only way to trigger the redirection is to load and activate redir2dep */
59  h = _CreateActCtxFromFile(L"testdata\\redir2dep.manifest", __LINE__);
60  _ActivateCtx(h, &cookie, __LINE__);
61  dll2 = LoadLibraryExW(L"kernel32test_versioned.dll",0 , 0);
62  _DeactivateCtx(cookie, __LINE__);
63  ok (dll2 != NULL, "LoadLibraryExW failed\n");
64 
65  ok (dll1 != dll2, "\n");
66  _TestVesion(dll1, 1, __LINE__);
67  _TestVesion(dll2, 2, __LINE__);
68 
69  FreeLibrary(dll1);
70  FreeLibrary(dll2);
71 
72  dll1 = LoadLibraryExW(L"comctl32.dll",0 ,0);
73  ok (dll1 != NULL, "LoadLibraryExW failed\n");
74 
75  h = _CreateActCtxFromFile(L"comctl32dep.manifest", __LINE__);
76  _ActivateCtx(h, &cookie, __LINE__);
77  dll2 = LoadLibraryExW(L"comctl32.dll",0 , 0);
78  _DeactivateCtx(cookie, __LINE__);
79  ok (dll2 != NULL, "LoadLibraryExW failed\n");
80 
81  ok (dll1 != dll2, "\n");
82 
83 }
84 
86 {
88 }
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
VOID _TestVesion(HANDLE dll, DWORD ExpectedVersion, int line)
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
Definition: loader.c:288
static HANDLE proc()
Definition: pdb.c:32
#define DWORD
Definition: nt_native.h:44
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
uint32_t ULONG_PTR
Definition: typedefs.h:63
static HMODULE dll
Definition: str.c:188
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR version[]
Definition: asmname.c:64
Definition: parser.c:48
VOID _DeactivateCtx(ULONG_PTR cookie, int line)
VOID _ActivateCtx(HANDLE h, ULONG_PTR *cookie, int line)
#define FreeLibrary(x)
Definition: compat.h:405
START_TEST(LoadLibraryExW)
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
VOID TestDllRedirection()
DWORD(WINAPI * LPGETVERSION)()
#define ok(value,...)
Definition: atltest.h:57
HANDLE _CreateActCtxFromFile(LPCWSTR FileName, int line)
#define GetProcAddress(x, y)
Definition: compat.h:410
#define ok_(x1, x2)
Definition: atltest.h:61