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 #pragma once
24 
25 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
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 inline void unload_v6_module(ULONG_PTR cookie, HANDLE hCtx)
66 {
67     HANDLE hKernel32;
68     BOOL (WINAPI *pDeactivateActCtx)(DWORD, ULONG_PTR);
69     VOID (WINAPI *pReleaseActCtx)(HANDLE);
70 
71     hKernel32 = GetModuleHandleA("kernel32.dll");
72     pDeactivateActCtx = (void*)GetProcAddress(hKernel32, "DeactivateActCtx");
73     pReleaseActCtx = (void*)GetProcAddress(hKernel32, "ReleaseActCtx");
74     if (!pDeactivateActCtx || !pReleaseActCtx)
75     {
76         win_skip("Activation contexts unsupported\n");
77         return;
78     }
79 
80     pDeactivateActCtx(0, cookie);
81     pReleaseActCtx(hCtx);
82 
83     DeleteFileA(manifest_name);
84 }
85 
86 static inline BOOL load_v6_module(ULONG_PTR *pcookie, HANDLE *hCtx)
87 {
88     HANDLE hKernel32;
89     HANDLE (WINAPI *pCreateActCtxA)(ACTCTXA*);
90     BOOL (WINAPI *pActivateActCtx)(HANDLE, ULONG_PTR*);
91     BOOL (WINAPI *pFindActCtxSectionStringA)(DWORD,const GUID *,ULONG,LPCSTR,PACTCTX_SECTION_KEYED_DATA);
92 
93     ACTCTX_SECTION_KEYED_DATA data;
94 
95     ACTCTXA ctx;
96     BOOL ret;
97     HANDLE file;
98     DWORD written;
99 
100     hKernel32 = GetModuleHandleA("kernel32.dll");
101     pCreateActCtxA = (void*)GetProcAddress(hKernel32, "CreateActCtxA");
102     pActivateActCtx = (void*)GetProcAddress(hKernel32, "ActivateActCtx");
103     pFindActCtxSectionStringA = (void*)GetProcAddress(hKernel32, "FindActCtxSectionStringA");
104     if (!(pCreateActCtxA && pActivateActCtx))
105     {
106         win_skip("Activation contexts unsupported. No version 6 tests possible.\n");
107         return FALSE;
108     }
109 
110     /* create manifest */
111     file = CreateFileA( manifest_name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL );
112     if (file != INVALID_HANDLE_VALUE)
113     {
114         ret = (WriteFile( file, manifest, sizeof(manifest)-1, &written, NULL ) &&
115                written == sizeof(manifest)-1);
116         CloseHandle( file );
117         if (!ret)
118         {
119             DeleteFileA( manifest_name );
120             skip("Failed to fill manifest file. Skipping comctl32 V6 tests.\n");
121             return FALSE;
122         }
123         else
124             trace("created %s\n", manifest_name);
125     }
126     else
127     {
128         skip("Failed to create manifest file. Skipping comctl32 V6 tests.\n");
129         return FALSE;
130     }
131 
132     memset(&ctx, 0, sizeof(ctx));
133     ctx.cbSize = sizeof(ctx);
134     ctx.lpSource = manifest_name;
135 
136     *hCtx = pCreateActCtxA(&ctx);
137     ok(*hCtx != 0, "Expected context handle\n");
138 
139     ret = pActivateActCtx(*hCtx, pcookie);
140     expect(TRUE, ret);
141 
142     if (!ret)
143     {
144         win_skip("A problem during context activation occurred.\n");
145         DeleteFileA(manifest_name);
146     }
147 
148     data.cbSize = sizeof(data);
149     ret = pFindActCtxSectionStringA(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
150         "comctl32.dll", &data);
151     ok(ret, "failed to find comctl32.dll in active context, %u\n", GetLastError());
152     if (ret)
153         LoadLibraryA("comctl32.dll");
154 
155     return ret;
156 }
157 
158 #undef expect
159 #undef ARCH
160