d3d10core: Set the initial blend factors to 1.0f.
[wine/multimedia.git] / dlls / kernel32 / actctx.c
blobbcf95ec2191ecb68cd85424cbd36fa8ca1331ecc
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 "winternl.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(actctx);
36 /***********************************************************************
37 * CreateActCtxA (KERNEL32.@)
39 * Create an activation context.
41 HANDLE WINAPI CreateActCtxA(PCACTCTXA pActCtx)
43 ACTCTXW actw;
44 SIZE_T len;
45 HANDLE ret = INVALID_HANDLE_VALUE;
46 LPWSTR src = NULL, assdir = NULL, resname = NULL, appname = NULL;
48 TRACE("%p %08x\n", pActCtx, pActCtx ? pActCtx->dwFlags : 0);
50 if (!pActCtx || pActCtx->cbSize != sizeof(*pActCtx))
52 SetLastError(ERROR_INVALID_PARAMETER);
53 return INVALID_HANDLE_VALUE;
56 actw.cbSize = sizeof(actw);
57 actw.dwFlags = pActCtx->dwFlags;
58 if (pActCtx->lpSource)
60 len = MultiByteToWideChar(CP_ACP, 0, pActCtx->lpSource, -1, NULL, 0);
61 src = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
62 if (!src) return INVALID_HANDLE_VALUE;
63 MultiByteToWideChar(CP_ACP, 0, pActCtx->lpSource, -1, src, len);
65 actw.lpSource = src;
67 if (actw.dwFlags & ACTCTX_FLAG_PROCESSOR_ARCHITECTURE_VALID)
68 actw.wProcessorArchitecture = pActCtx->wProcessorArchitecture;
69 if (actw.dwFlags & ACTCTX_FLAG_LANGID_VALID)
70 actw.wLangId = pActCtx->wLangId;
71 if (actw.dwFlags & ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID)
73 len = MultiByteToWideChar(CP_ACP, 0, pActCtx->lpAssemblyDirectory, -1, NULL, 0);
74 assdir = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
75 if (!assdir) goto done;
76 MultiByteToWideChar(CP_ACP, 0, pActCtx->lpAssemblyDirectory, -1, assdir, len);
77 actw.lpAssemblyDirectory = assdir;
79 if (actw.dwFlags & ACTCTX_FLAG_RESOURCE_NAME_VALID)
81 if ((ULONG_PTR)pActCtx->lpResourceName >> 16)
83 len = MultiByteToWideChar(CP_ACP, 0, pActCtx->lpResourceName, -1, NULL, 0);
84 resname = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
85 if (!resname) goto done;
86 MultiByteToWideChar(CP_ACP, 0, pActCtx->lpResourceName, -1, resname, len);
87 actw.lpResourceName = resname;
89 else actw.lpResourceName = (LPCWSTR)pActCtx->lpResourceName;
91 if (actw.dwFlags & ACTCTX_FLAG_APPLICATION_NAME_VALID)
93 len = MultiByteToWideChar(CP_ACP, 0, pActCtx->lpApplicationName, -1, NULL, 0);
94 appname = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
95 if (!appname) goto done;
96 MultiByteToWideChar(CP_ACP, 0, pActCtx->lpApplicationName, -1, appname, len);
97 actw.lpApplicationName = appname;
99 if (actw.dwFlags & ACTCTX_FLAG_HMODULE_VALID)
100 actw.hModule = pActCtx->hModule;
102 ret = CreateActCtxW(&actw);
104 done:
105 HeapFree(GetProcessHeap(), 0, src);
106 HeapFree(GetProcessHeap(), 0, assdir);
107 HeapFree(GetProcessHeap(), 0, resname);
108 HeapFree(GetProcessHeap(), 0, appname);
109 return ret;
112 /***********************************************************************
113 * CreateActCtxW (KERNEL32.@)
115 * Create an activation context.
117 HANDLE WINAPI CreateActCtxW(PCACTCTXW pActCtx)
119 NTSTATUS status;
120 HANDLE hActCtx;
122 TRACE("%p %08x\n", pActCtx, pActCtx ? pActCtx->dwFlags : 0);
124 if ((status = RtlCreateActivationContext(&hActCtx, pActCtx)))
126 SetLastError(RtlNtStatusToDosError(status));
127 return INVALID_HANDLE_VALUE;
129 return hActCtx;
132 /***********************************************************************
133 * ActivateActCtx (KERNEL32.@)
135 * Activate an activation context.
137 BOOL WINAPI ActivateActCtx(HANDLE hActCtx, ULONG_PTR *ulCookie)
139 NTSTATUS status;
141 if ((status = RtlActivateActivationContext( 0, hActCtx, ulCookie )))
143 SetLastError(RtlNtStatusToDosError(status));
144 return FALSE;
146 return TRUE;
149 /***********************************************************************
150 * DeactivateActCtx (KERNEL32.@)
152 * Deactivate an activation context.
154 BOOL WINAPI DeactivateActCtx(DWORD dwFlags, ULONG_PTR ulCookie)
156 RtlDeactivateActivationContext( dwFlags, ulCookie );
157 return TRUE;
160 /***********************************************************************
161 * GetCurrentActCtx (KERNEL32.@)
163 * Get the current activation context.
165 BOOL WINAPI GetCurrentActCtx(HANDLE* phActCtx)
167 NTSTATUS status;
169 if ((status = RtlGetActiveActivationContext(phActCtx)))
171 SetLastError(RtlNtStatusToDosError(status));
172 return FALSE;
174 return TRUE;
177 /***********************************************************************
178 * AddRefActCtx (KERNEL32.@)
180 * Add a reference to an activation context.
182 void WINAPI AddRefActCtx(HANDLE hActCtx)
184 RtlAddRefActivationContext(hActCtx);
187 /***********************************************************************
188 * ReleaseActCtx (KERNEL32.@)
190 * Release a reference to an activation context.
192 void WINAPI ReleaseActCtx(HANDLE hActCtx)
194 RtlReleaseActivationContext(hActCtx);
197 /***********************************************************************
198 * ZombifyActCtx (KERNEL32.@)
200 * Deactivate context without releasing it.
202 BOOL WINAPI ZombifyActCtx(HANDLE hActCtx)
204 NTSTATUS status;
206 if ((status = RtlZombifyActivationContext(hActCtx)))
208 SetLastError(RtlNtStatusToDosError(status));
209 return FALSE;
211 return TRUE;
214 /***********************************************************************
215 * FindActCtxSectionStringA (KERNEL32.@)
217 * Find information about a string in an activation context.
219 BOOL WINAPI FindActCtxSectionStringA(DWORD dwFlags, const GUID* lpExtGuid,
220 ULONG ulId, LPCSTR lpSearchStr,
221 PACTCTX_SECTION_KEYED_DATA pInfo)
223 LPWSTR search_str;
224 DWORD len;
225 BOOL ret;
227 TRACE("%08x %s %u %s %p\n", dwFlags, debugstr_guid(lpExtGuid),
228 ulId, debugstr_a(lpSearchStr), pInfo);
230 if (!lpSearchStr)
232 SetLastError(ERROR_INVALID_PARAMETER);
233 return FALSE;
236 len = MultiByteToWideChar(CP_ACP, 0, lpSearchStr, -1, NULL, 0);
237 search_str = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
238 MultiByteToWideChar(CP_ACP, 0, lpSearchStr, -1, search_str, len);
240 ret = FindActCtxSectionStringW(dwFlags, lpExtGuid, ulId, search_str, pInfo);
242 HeapFree(GetProcessHeap(), 0, search_str);
243 return ret;
246 /***********************************************************************
247 * FindActCtxSectionStringW (KERNEL32.@)
249 * Find information about a string in an activation context.
251 BOOL WINAPI FindActCtxSectionStringW(DWORD dwFlags, const GUID* lpExtGuid,
252 ULONG ulId, LPCWSTR lpSearchStr,
253 PACTCTX_SECTION_KEYED_DATA pInfo)
255 UNICODE_STRING us;
256 NTSTATUS status;
258 RtlInitUnicodeString(&us, lpSearchStr);
259 if ((status = RtlFindActivationContextSectionString(dwFlags, lpExtGuid, ulId, &us, pInfo)))
261 SetLastError(RtlNtStatusToDosError(status));
262 return FALSE;
264 return TRUE;
267 /***********************************************************************
268 * FindActCtxSectionGuid (KERNEL32.@)
270 * Find information about a GUID in an activation context.
272 BOOL WINAPI FindActCtxSectionGuid(DWORD dwFlags, const GUID* lpExtGuid,
273 ULONG ulId, const GUID* lpSearchGuid,
274 PACTCTX_SECTION_KEYED_DATA pInfo)
276 NTSTATUS status;
278 if ((status = RtlFindActivationContextSectionGuid(dwFlags, lpExtGuid, ulId, lpSearchGuid, pInfo)))
280 SetLastError(RtlNtStatusToDosError(status));
281 return FALSE;
284 return TRUE;
287 /***********************************************************************
288 * QueryActCtxW (KERNEL32.@)
290 * Get information about an activation context.
292 BOOL WINAPI QueryActCtxW(DWORD dwFlags, HANDLE hActCtx, PVOID pvSubInst,
293 ULONG ulClass, PVOID pvBuff, SIZE_T cbBuff,
294 SIZE_T *pcbLen)
296 NTSTATUS status;
298 if ((status = RtlQueryInformationActivationContext( dwFlags, hActCtx, pvSubInst, ulClass,
299 pvBuff, cbBuff, pcbLen )))
301 SetLastError(RtlNtStatusToDosError(status));
302 return FALSE;
304 return TRUE;