win32u: Use KBDTABLES for NtUserVkKeyScanEx.
[wine.git] / dlls / sxs / sxs.c
blob150a49a322fd6d426f15b0d4874612b9daa28a05
1 /*
2 * sxs main
4 * Copyright 2007 EA Durbin
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <stdlib.h>
24 #include "windef.h"
25 #include "winbase.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(sxs);
31 typedef struct _SXS_GUID_INFORMATION_CLR
33 DWORD cbSize;
34 DWORD dwFlags;
35 PCWSTR pcwszRuntimeVersion;
36 PCWSTR pcwszTypeName;
37 PCWSTR pcwszAssemblyIdentity;
38 } SXS_GUID_INFORMATION_CLR, *PSXS_GUID_INFORMATION_CLR;
40 #define SXS_GUID_INFORMATION_CLR_FLAG_IS_SURROGATE 0x1
41 #define SXS_GUID_INFORMATION_CLR_FLAG_IS_CLASS 0x2
43 #define SXS_LOOKUP_CLR_GUID_USE_ACTCTX 0x00000001
44 #define SXS_LOOKUP_CLR_GUID_FIND_SURROGATE 0x00010000
45 #define SXS_LOOKUP_CLR_GUID_FIND_CLR_CLASS 0x00020000
46 #define SXS_LOOKUP_CLR_GUID_FIND_ANY (SXS_LOOKUP_CLR_GUID_FIND_SURROGATE | SXS_LOOKUP_CLR_GUID_FIND_CLR_CLASS)
48 struct comclassredirect_data
50 ULONG size;
51 ULONG flags;
52 DWORD model;
53 GUID clsid;
54 GUID alias;
55 GUID clsid2;
56 GUID tlbid;
57 ULONG name_len;
58 ULONG name_offset;
59 ULONG progid_len;
60 ULONG progid_offset;
61 ULONG clrdata_len;
62 ULONG clrdata_offset;
63 DWORD miscstatus;
64 DWORD miscstatuscontent;
65 DWORD miscstatusthumbnail;
66 DWORD miscstatusicon;
67 DWORD miscstatusdocprint;
70 struct clrclass_data
72 ULONG size;
73 DWORD res[2];
74 ULONG module_len;
75 ULONG module_offset;
76 ULONG name_len;
77 ULONG name_offset;
78 ULONG version_len;
79 ULONG version_offset;
80 DWORD res2[2];
83 struct clrsurrogate_data
85 ULONG size;
86 DWORD res;
87 GUID clsid;
88 ULONG version_offset;
89 ULONG version_len;
90 ULONG name_offset;
91 ULONG name_len;
94 BOOL WINAPI SxsLookupClrGuid(DWORD flags, GUID *clsid, HANDLE actctx, void *buffer, SIZE_T buffer_len,
95 SIZE_T *buffer_len_required)
97 ACTCTX_SECTION_KEYED_DATA guid_info = { sizeof(ACTCTX_SECTION_KEYED_DATA) };
98 ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION *assembly_info = NULL;
99 SIZE_T bytes_assembly_info;
100 unsigned int len_version = 0, len_name, len_identity;
101 const void *ptr_name, *ptr_version, *ptr_identity;
102 SXS_GUID_INFORMATION_CLR *ret = buffer;
103 BOOL retval = FALSE;
104 char *ret_strings;
105 ULONG_PTR cookie;
107 TRACE("%#lx, %s, %p, %p, %Ix, %p.\n", flags, wine_dbgstr_guid(clsid), actctx,
108 buffer, buffer_len, buffer_len_required);
110 if (flags & SXS_LOOKUP_CLR_GUID_USE_ACTCTX)
112 if (!ActivateActCtx(actctx, &cookie))
114 WARN("Failed to activate context.\n");
115 return FALSE;
119 if (flags & SXS_LOOKUP_CLR_GUID_FIND_SURROGATE)
121 if ((retval = FindActCtxSectionGuid(FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX, NULL,
122 ACTIVATION_CONTEXT_SECTION_CLR_SURROGATES, clsid, &guid_info)))
124 flags &= ~SXS_LOOKUP_CLR_GUID_FIND_CLR_CLASS;
128 if (!retval && (flags & SXS_LOOKUP_CLR_GUID_FIND_CLR_CLASS))
130 if ((retval = FindActCtxSectionGuid(FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX, NULL,
131 ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION, clsid, &guid_info)))
133 flags &= ~SXS_LOOKUP_CLR_GUID_FIND_SURROGATE;
137 if (!retval)
139 SetLastError(ERROR_NOT_FOUND);
140 goto out;
143 retval = QueryActCtxW(0, guid_info.hActCtx, &guid_info.ulAssemblyRosterIndex,
144 AssemblyDetailedInformationInActivationContext, NULL, 0, &bytes_assembly_info);
145 if (!retval && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
147 goto out;
150 assembly_info = malloc(bytes_assembly_info);
151 if (!(retval = QueryActCtxW(0, guid_info.hActCtx, &guid_info.ulAssemblyRosterIndex,
152 AssemblyDetailedInformationInActivationContext, assembly_info,
153 bytes_assembly_info, &bytes_assembly_info)))
155 goto out;
158 if (flags & SXS_LOOKUP_CLR_GUID_FIND_CLR_CLASS)
160 const struct comclassredirect_data *redirect_data = guid_info.lpData;
161 const struct clrclass_data *class_data;
163 class_data = (void *)((char *)redirect_data + redirect_data->clrdata_offset);
164 ptr_name = (char *)class_data + class_data->name_offset;
165 ptr_version = (char *)class_data + class_data->version_offset;
166 len_name = class_data->name_len + sizeof(WCHAR);
167 if (class_data->version_len)
168 len_version = class_data->version_len + sizeof(WCHAR);
170 else
172 const struct clrsurrogate_data *surrogate = guid_info.lpData;
173 ptr_name = (char *)surrogate + surrogate->name_offset;
174 ptr_version = (char *)surrogate + surrogate->version_offset;
175 len_name = surrogate->name_len + sizeof(WCHAR);
176 if (surrogate->version_len)
177 len_version = surrogate->version_len + sizeof(WCHAR);
180 ptr_identity = assembly_info->lpAssemblyEncodedAssemblyIdentity;
181 len_identity = assembly_info->ulEncodedAssemblyIdentityLength + sizeof(WCHAR);
183 *buffer_len_required = sizeof(*ret) + len_identity + len_version + len_name;
184 if (!buffer || buffer_len < *buffer_len_required)
186 SetLastError(ERROR_INSUFFICIENT_BUFFER);
187 retval = FALSE;
188 goto out;
191 ret->cbSize = sizeof(*ret);
192 ret->dwFlags = flags & SXS_LOOKUP_CLR_GUID_FIND_CLR_CLASS ? SXS_GUID_INFORMATION_CLR_FLAG_IS_CLASS :
193 SXS_GUID_INFORMATION_CLR_FLAG_IS_SURROGATE;
195 /* Copy strings into buffer */
196 ret_strings = (char *)ret + sizeof(*ret);
198 memcpy(ret_strings, ptr_identity, len_identity);
199 ret->pcwszAssemblyIdentity = (WCHAR *)ret_strings;
200 ret_strings += len_identity;
202 memcpy(ret_strings, ptr_name, len_name);
203 ret->pcwszTypeName = (WCHAR *)ret_strings;
204 ret_strings += len_name;
206 if (len_version > 0)
208 memcpy(ret_strings, ptr_version, len_version);
209 ret->pcwszRuntimeVersion = (WCHAR *)ret_strings;
211 else
212 ret->pcwszRuntimeVersion = NULL;
214 SetLastError(0);
216 out:
217 ReleaseActCtx(guid_info.hActCtx);
219 if (flags & SXS_LOOKUP_CLR_GUID_USE_ACTCTX)
220 DeactivateActCtx(0, cookie);
222 free(assembly_info);
223 return retval;