wined3d: In device_map_psamplers(), only touch the sampler mapping for samplers that...
[wine/hacks.git] / dlls / kernel32 / actctx.c
blob1d5461f68c40da14c7a1b13f281b2ec320433f6a
1 /*
2 * Activation contexts
4 * Copyright 2004 Jon Griffiths
5 * Copyright 2007 Eric Pouech
6 * Copyright 2007 Jacek Caban for CodeWeavers
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.
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.
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
23 #include "config.h"
24 #include "wine/port.h"
26 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winerror.h"
30 #include "winnls.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(actctx);
36 #define ACTCTX_FLAGS_ALL (\
37 ACTCTX_FLAG_PROCESSOR_ARCHITECTURE_VALID |\
38 ACTCTX_FLAG_LANGID_VALID |\
39 ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID |\
40 ACTCTX_FLAG_RESOURCE_NAME_VALID |\
41 ACTCTX_FLAG_SET_PROCESS_DEFAULT |\
42 ACTCTX_FLAG_APPLICATION_NAME_VALID |\
43 ACTCTX_FLAG_SOURCE_IS_ASSEMBLYREF |\
44 ACTCTX_FLAG_HMODULE_VALID )
46 #define ACTCTX_FAKE_HANDLE ((HANDLE) 0xf00baa)
47 #define ACTCTX_FAKE_COOKIE ((ULONG_PTR) 0xf00bad)
49 #define ACTCTX_MAGIC 0xC07E3E11
51 struct actctx
53 ULONG magic;
54 LONG ref_count;
57 /***********************************************************************
58 * CreateActCtxA (KERNEL32.@)
60 * Create an activation context.
62 HANDLE WINAPI CreateActCtxA(PCACTCTXA pActCtx)
64 ACTCTXW actw;
65 SIZE_T len;
66 HANDLE ret = INVALID_HANDLE_VALUE;
67 LPWSTR src = NULL, assdir = NULL, resname = NULL, appname = NULL;
69 TRACE("%p %08x\n", pActCtx, pActCtx ? pActCtx->dwFlags : 0);
71 if (!pActCtx || pActCtx->cbSize != sizeof(*pActCtx) ||
72 (pActCtx->dwFlags & ~ACTCTX_FLAGS_ALL))
74 SetLastError(ERROR_INVALID_PARAMETER);
75 return INVALID_HANDLE_VALUE;
78 actw.cbSize = sizeof(actw);
79 actw.dwFlags = pActCtx->dwFlags;
80 if (pActCtx->lpSource)
82 len = MultiByteToWideChar(CP_ACP, 0, pActCtx->lpSource, -1, NULL, 0);
83 src = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
84 if (!src) return INVALID_HANDLE_VALUE;
85 MultiByteToWideChar(CP_ACP, 0, pActCtx->lpSource, -1, src, len);
87 actw.lpSource = src;
89 if (actw.dwFlags & ACTCTX_FLAG_PROCESSOR_ARCHITECTURE_VALID)
90 actw.wProcessorArchitecture = pActCtx->wProcessorArchitecture;
91 if (actw.dwFlags & ACTCTX_FLAG_LANGID_VALID)
92 actw.wLangId = pActCtx->wLangId;
93 if (actw.dwFlags & ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID)
95 len = MultiByteToWideChar(CP_ACP, 0, pActCtx->lpAssemblyDirectory, -1, NULL, 0);
96 assdir = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
97 if (!assdir) goto done;
98 MultiByteToWideChar(CP_ACP, 0, pActCtx->lpAssemblyDirectory, -1, assdir, len);
99 actw.lpAssemblyDirectory = assdir;
101 if (actw.dwFlags & ACTCTX_FLAG_RESOURCE_NAME_VALID)
103 if ((ULONG_PTR)pActCtx->lpResourceName >> 16)
105 len = MultiByteToWideChar(CP_ACP, 0, pActCtx->lpResourceName, -1, NULL, 0);
106 resname = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
107 if (!resname) goto done;
108 MultiByteToWideChar(CP_ACP, 0, pActCtx->lpResourceName, -1, resname, len);
109 actw.lpResourceName = resname;
111 else actw.lpResourceName = (LPWSTR)pActCtx->lpResourceName;
113 if (actw.dwFlags & ACTCTX_FLAG_APPLICATION_NAME_VALID)
115 len = MultiByteToWideChar(CP_ACP, 0, pActCtx->lpApplicationName, -1, NULL, 0);
116 appname = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
117 if (!appname) goto done;
118 MultiByteToWideChar(CP_ACP, 0, pActCtx->lpApplicationName, -1, appname, len);
119 actw.lpApplicationName = appname;
121 if (actw.dwFlags & ACTCTX_FLAG_HMODULE_VALID)
122 actw.hModule = pActCtx->hModule;
124 ret = CreateActCtxW(&actw);
126 done:
127 HeapFree(GetProcessHeap(), 0, src);
128 HeapFree(GetProcessHeap(), 0, assdir);
129 HeapFree(GetProcessHeap(), 0, resname);
130 HeapFree(GetProcessHeap(), 0, appname);
131 return ret;
134 /***********************************************************************
135 * CreateActCtxW (KERNEL32.@)
137 * Create an activation context.
139 HANDLE WINAPI CreateActCtxW(PCACTCTXW pActCtx)
141 struct actctx* actctx;
142 DWORD ret = ERROR_SUCCESS;
144 TRACE("%p %08x\n", pActCtx, pActCtx ? pActCtx->dwFlags : 0);
146 if (!pActCtx || pActCtx->cbSize != sizeof(*pActCtx) ||
147 (pActCtx->dwFlags & ~ACTCTX_FLAGS_ALL))
149 SetLastError(ERROR_INVALID_PARAMETER);
150 return INVALID_HANDLE_VALUE;
152 actctx = HeapAlloc(GetProcessHeap(), 0, sizeof(*actctx));
153 if (!actctx) return INVALID_HANDLE_VALUE;
155 actctx->magic = ACTCTX_MAGIC;
156 actctx->ref_count = 1;
158 if (ret == ERROR_SUCCESS)
160 return (HANDLE)actctx;
163 ReleaseActCtx((HANDLE)actctx);
164 SetLastError(ret);
165 return INVALID_HANDLE_VALUE;
168 static struct actctx* check_actctx(HANDLE h)
170 struct actctx* actctx = (struct actctx*)h;
172 switch (actctx->magic)
174 case ACTCTX_MAGIC: return actctx;
175 default:
176 SetLastError(ERROR_INVALID_HANDLE);
177 return NULL;
181 /***********************************************************************
182 * ActivateActCtx (KERNEL32.@)
184 * Activate an activation context.
186 BOOL WINAPI ActivateActCtx(HANDLE hActCtx, ULONG_PTR *ulCookie)
188 static BOOL reported = FALSE;
190 if (reported)
191 TRACE("%p %p\n", hActCtx, ulCookie);
192 else
194 FIXME("%p %p\n", hActCtx, ulCookie);
195 reported = TRUE;
198 if (ulCookie)
199 *ulCookie = ACTCTX_FAKE_COOKIE;
200 return TRUE;
203 /***********************************************************************
204 * DeactivateActCtx (KERNEL32.@)
206 * Deactivate an activation context.
208 BOOL WINAPI DeactivateActCtx(DWORD dwFlags, ULONG_PTR ulCookie)
210 static BOOL reported = FALSE;
212 if (reported)
213 TRACE("%08x %08lx\n", dwFlags, ulCookie);
214 else
216 FIXME("%08x %08lx\n", dwFlags, ulCookie);
217 reported = TRUE;
220 if (ulCookie != ACTCTX_FAKE_COOKIE)
221 return FALSE;
222 return TRUE;
225 /***********************************************************************
226 * GetCurrentActCtx (KERNEL32.@)
228 * Get the current activation context.
230 BOOL WINAPI GetCurrentActCtx(HANDLE* phActCtx)
232 FIXME("%p\n", phActCtx);
233 *phActCtx = ACTCTX_FAKE_HANDLE;
234 return TRUE;
237 /***********************************************************************
238 * AddRefActCtx (KERNEL32.@)
240 * Add a reference to an activation context.
242 void WINAPI AddRefActCtx(HANDLE hActCtx)
244 struct actctx* actctx;
246 TRACE("%p\n", hActCtx);
248 if ((actctx = check_actctx(hActCtx)))
249 InterlockedIncrement( &actctx->ref_count );
252 /***********************************************************************
253 * ReleaseActCtx (KERNEL32.@)
255 * Release a reference to an activation context.
257 void WINAPI ReleaseActCtx(HANDLE hActCtx)
259 struct actctx* actctx;
261 TRACE("%p\n", hActCtx);
263 if ((actctx = check_actctx(hActCtx)))
265 if (!InterlockedDecrement( &actctx->ref_count ))
267 actctx->magic = 0;
268 HeapFree(GetProcessHeap(), 0, actctx);
273 /***********************************************************************
274 * ZombifyActCtx (KERNEL32.@)
276 * Release a reference to an activation context.
278 BOOL WINAPI ZombifyActCtx(HANDLE hActCtx)
280 FIXME("%p\n", hActCtx);
281 if (hActCtx != ACTCTX_FAKE_HANDLE)
282 return FALSE;
283 return TRUE;
286 /***********************************************************************
287 * FindActCtxSectionStringA (KERNEL32.@)
289 * Find information about a GUID in an activation context.
291 BOOL WINAPI FindActCtxSectionStringA(DWORD dwFlags, const GUID* lpExtGuid,
292 ULONG ulId, LPCSTR lpSearchStr,
293 PACTCTX_SECTION_KEYED_DATA pInfo)
295 FIXME("%08x %s %u %s %p\n", dwFlags, debugstr_guid(lpExtGuid),
296 ulId, debugstr_a(lpSearchStr), pInfo);
297 SetLastError( ERROR_CALL_NOT_IMPLEMENTED);
298 return FALSE;
301 /***********************************************************************
302 * FindActCtxSectionStringW (KERNEL32.@)
304 * Find information about a GUID in an activation context.
306 BOOL WINAPI FindActCtxSectionStringW(DWORD dwFlags, const GUID* lpExtGuid,
307 ULONG ulId, LPCWSTR lpSearchStr,
308 PACTCTX_SECTION_KEYED_DATA pInfo)
310 FIXME("%08x %s %u %s %p\n", dwFlags, debugstr_guid(lpExtGuid),
311 ulId, debugstr_w(lpSearchStr), pInfo);
313 if (lpExtGuid)
315 FIXME("expected lpExtGuid == NULL\n");
316 SetLastError(ERROR_INVALID_PARAMETER);
317 return FALSE;
320 if (dwFlags & ~FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX)
322 FIXME("unknown dwFlags %08x\n", dwFlags);
323 SetLastError(ERROR_INVALID_PARAMETER);
324 return FALSE;
327 if (!pInfo || pInfo->cbSize < sizeof (ACTCTX_SECTION_KEYED_DATA))
329 SetLastError(ERROR_INVALID_PARAMETER);
330 return FALSE;
333 pInfo->ulDataFormatVersion = 1;
334 pInfo->lpData = NULL;
335 pInfo->lpSectionGlobalData = NULL;
336 pInfo->ulSectionGlobalDataLength = 0;
337 pInfo->lpSectionBase = NULL;
338 pInfo->ulSectionTotalLength = 0;
339 pInfo->hActCtx = ACTCTX_FAKE_HANDLE;
340 pInfo->ulAssemblyRosterIndex = 0;
342 return TRUE;
345 /***********************************************************************
346 * FindActCtxSectionGuid (KERNEL32.@)
348 * Find information about a GUID in an activation context.
350 BOOL WINAPI FindActCtxSectionGuid(DWORD dwFlags, const GUID* lpExtGuid,
351 ULONG ulId, const GUID* lpSearchGuid,
352 PACTCTX_SECTION_KEYED_DATA pInfo)
354 FIXME("%08x %s %u %s %p\n", dwFlags, debugstr_guid(lpExtGuid),
355 ulId, debugstr_guid(lpSearchGuid), pInfo);
356 SetLastError( ERROR_CALL_NOT_IMPLEMENTED);
357 return FALSE;
360 /***********************************************************************
361 * QueryActCtxW (KERNEL32.@)
363 * Get information about an activation context.
365 BOOL WINAPI QueryActCtxW(DWORD dwFlags, HANDLE hActCtx, PVOID pvSubInst,
366 ULONG ulClass, PVOID pvBuff, SIZE_T cbBuff,
367 SIZE_T *pcbLen)
369 FIXME("%08x %p %p %u %p %ld %p\n", dwFlags, hActCtx,
370 pvSubInst, ulClass, pvBuff, cbBuff, pcbLen);
371 /* this makes Adobe Photoshop 7.0 happy */
372 SetLastError( ERROR_CALL_NOT_IMPLEMENTED);
373 return FALSE;