1 /*
2  * Utility routines for comctl32 v6 tests
3  *
4  * Copyright 2006 Mike McCormack for CodeWeavers
5  * Copyright 2007 George Gov
6  * Copyright 2009 Owen Rudge for CodeWeavers
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22 
23 #ifdef __REACTOS__
24 #pragma once
25 #endif
26 
27 #ifdef __i386__
28 #define ARCH "x86"
29 #elif defined __x86_64__
30 #define ARCH "amd64"
31 #elif defined __arm__
32 #define ARCH "arm"
33 #elif defined __aarch64__
34 #define ARCH "arm64"
35 #else
36 #define ARCH "none"
37 #endif
38 
39 static const CHAR manifest_name[] = "cc6.manifest";
40 
41 static const CHAR manifest[] =
42     "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
43     "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">\n"
44     "  <assemblyIdentity\n"
45     "      type=\"win32\"\n"
46     "      name=\"Wine.ComCtl32.Tests\"\n"
47     "      version=\"1.0.0.0\"\n"
48     "      processorArchitecture=\"" ARCH "\"\n"
49     "  />\n"
50     "<description>Wine comctl32 test suite</description>\n"
51     "<dependency>\n"
52     "  <dependentAssembly>\n"
53     "    <assemblyIdentity\n"
54     "        type=\"win32\"\n"
55     "        name=\"microsoft.windows.common-controls\"\n"
56     "        version=\"6.0.0.0\"\n"
57     "        processorArchitecture=\"" ARCH "\"\n"
58     "        publicKeyToken=\"6595b64144ccf1df\"\n"
59     "        language=\"*\"\n"
60     "    />\n"
61     "</dependentAssembly>\n"
62     "</dependency>\n"
63     "</assembly>\n";
64 
65 static void unload_v6_module(ULONG_PTR cookie, HANDLE hCtx)
66 {
67     DeactivateActCtx(0, cookie);
68     ReleaseActCtx(hCtx);
69 
70     DeleteFileA(manifest_name);
71 }
72 
73 static BOOL load_v6_module(ULONG_PTR *pcookie, HANDLE *hCtx)
74 {
75     ACTCTX_SECTION_KEYED_DATA data;
76     DWORD written;
77     HMODULE hmod;
78     ACTCTXA ctx;
79     HANDLE file;
80     BOOL ret;
81 
82     /* create manifest */
83     file = CreateFileA( manifest_name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL );
84     if (file != INVALID_HANDLE_VALUE)
85     {
86         ret = (WriteFile( file, manifest, sizeof(manifest)-1, &written, NULL ) &&
87                written == sizeof(manifest)-1);
88         CloseHandle( file );
89         if (!ret)
90         {
91             DeleteFileA( manifest_name );
92             skip("Failed to fill manifest file. Skipping comctl32 V6 tests.\n");
93             return FALSE;
94         }
95         else
96             trace("created %s\n", manifest_name);
97     }
98     else
99     {
100         skip("Failed to create manifest file. Skipping comctl32 V6 tests.\n");
101         return FALSE;
102     }
103 
104     memset(&ctx, 0, sizeof(ctx));
105     ctx.cbSize = sizeof(ctx);
106     ctx.lpSource = manifest_name;
107 
108     *hCtx = CreateActCtxA(&ctx);
109     ok(*hCtx != 0, "Expected context handle\n");
110 
111     hmod = GetModuleHandleA("comctl32.dll");
112 
113     ret = ActivateActCtx(*hCtx, pcookie);
114     ok(ret, "Failed to activate context, error %d.\n", GetLastError());
115 
116     if (!ret)
117     {
118         win_skip("A problem during context activation occurred.\n");
119         DeleteFileA(manifest_name);
120     }
121 
122     data.cbSize = sizeof(data);
123     ret = FindActCtxSectionStringA(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
124         "comctl32.dll", &data);
125     ok(ret, "failed to find comctl32.dll in active context, %u\n", GetLastError());
126     if (ret)
127     {
128         FreeLibrary(hmod);
129         LoadLibraryA("comctl32.dll");
130     }
131 
132     return ret;
133 }
134 
135 #undef ARCH
136