Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenactctx.c
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS system libraries 00004 * FILE: dll/win32/kernel32/misc/actctx.c 00005 * PURPOSE: Activation contexts 00006 * PROGRAMMERS: Jacek Caban for CodeWeavers 00007 * Eric Pouech 00008 * Jon Griffiths 00009 * Dmitry Chapyshev (dmitry@reactos.org) 00010 * Samuel Serapión 00011 */ 00012 00013 /* synched with wine 1.1.26 */ 00014 00015 #include <k32.h> 00016 #define NDEBUG 00017 #include <debug.h> 00018 DEBUG_CHANNEL(actctx); 00019 00020 #define ACTCTX_FAKE_HANDLE ((HANDLE) 0xf00baa) 00021 00022 /*********************************************************************** 00023 * CreateActCtxA (KERNEL32.@) 00024 * 00025 * Create an activation context. 00026 */ 00027 HANDLE WINAPI CreateActCtxA(PCACTCTXA pActCtx) 00028 { 00029 ACTCTXW actw; 00030 SIZE_T len; 00031 HANDLE ret = INVALID_HANDLE_VALUE; 00032 LPWSTR src = NULL, assdir = NULL, resname = NULL, appname = NULL; 00033 00034 TRACE("%p %08x\n", pActCtx, pActCtx ? pActCtx->dwFlags : 0); 00035 00036 if (!pActCtx || pActCtx->cbSize != sizeof(*pActCtx)) 00037 { 00038 SetLastError(ERROR_INVALID_PARAMETER); 00039 return INVALID_HANDLE_VALUE; 00040 } 00041 00042 actw.cbSize = sizeof(actw); 00043 actw.dwFlags = pActCtx->dwFlags; 00044 if (pActCtx->lpSource) 00045 { 00046 len = MultiByteToWideChar(CP_ACP, 0, pActCtx->lpSource, -1, NULL, 0); 00047 src = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); 00048 if (!src) return INVALID_HANDLE_VALUE; 00049 MultiByteToWideChar(CP_ACP, 0, pActCtx->lpSource, -1, src, len); 00050 } 00051 actw.lpSource = src; 00052 00053 if (actw.dwFlags & ACTCTX_FLAG_PROCESSOR_ARCHITECTURE_VALID) 00054 actw.wProcessorArchitecture = pActCtx->wProcessorArchitecture; 00055 if (actw.dwFlags & ACTCTX_FLAG_LANGID_VALID) 00056 actw.wLangId = pActCtx->wLangId; 00057 if (actw.dwFlags & ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID) 00058 { 00059 len = MultiByteToWideChar(CP_ACP, 0, pActCtx->lpAssemblyDirectory, -1, NULL, 0); 00060 assdir = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); 00061 if (!assdir) goto done; 00062 MultiByteToWideChar(CP_ACP, 0, pActCtx->lpAssemblyDirectory, -1, assdir, len); 00063 actw.lpAssemblyDirectory = assdir; 00064 } 00065 if (actw.dwFlags & ACTCTX_FLAG_RESOURCE_NAME_VALID) 00066 { 00067 if ((ULONG_PTR)pActCtx->lpResourceName >> 16) 00068 { 00069 len = MultiByteToWideChar(CP_ACP, 0, pActCtx->lpResourceName, -1, NULL, 0); 00070 resname = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); 00071 if (!resname) goto done; 00072 MultiByteToWideChar(CP_ACP, 0, pActCtx->lpResourceName, -1, resname, len); 00073 actw.lpResourceName = resname; 00074 } 00075 else actw.lpResourceName = (LPCWSTR)pActCtx->lpResourceName; 00076 } 00077 if (actw.dwFlags & ACTCTX_FLAG_APPLICATION_NAME_VALID) 00078 { 00079 len = MultiByteToWideChar(CP_ACP, 0, pActCtx->lpApplicationName, -1, NULL, 0); 00080 appname = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); 00081 if (!appname) goto done; 00082 MultiByteToWideChar(CP_ACP, 0, pActCtx->lpApplicationName, -1, appname, len); 00083 actw.lpApplicationName = appname; 00084 } 00085 if (actw.dwFlags & ACTCTX_FLAG_HMODULE_VALID) 00086 actw.hModule = pActCtx->hModule; 00087 00088 ret = CreateActCtxW(&actw); 00089 00090 done: 00091 HeapFree(GetProcessHeap(), 0, src); 00092 HeapFree(GetProcessHeap(), 0, assdir); 00093 HeapFree(GetProcessHeap(), 0, resname); 00094 HeapFree(GetProcessHeap(), 0, appname); 00095 return ret; 00096 } 00097 00098 /*********************************************************************** 00099 * CreateActCtxW (KERNEL32.@) 00100 * 00101 * Create an activation context. 00102 */ 00103 HANDLE WINAPI CreateActCtxW(PCACTCTXW pActCtx) 00104 { 00105 NTSTATUS status; 00106 HANDLE hActCtx; 00107 00108 TRACE("%p %08x\n", pActCtx, pActCtx ? pActCtx->dwFlags : 0); 00109 00110 if ((status = RtlCreateActivationContext(&hActCtx, (PVOID*)pActCtx))) 00111 { 00112 SetLastError(RtlNtStatusToDosError(status)); 00113 return INVALID_HANDLE_VALUE; 00114 } 00115 return hActCtx; 00116 } 00117 00118 /*********************************************************************** 00119 * ActivateActCtx (KERNEL32.@) 00120 * 00121 * Activate an activation context. 00122 */ 00123 BOOL WINAPI ActivateActCtx(HANDLE hActCtx, ULONG_PTR *ulCookie) 00124 { 00125 NTSTATUS status; 00126 00127 if ((status = RtlActivateActivationContext( 0, hActCtx, ulCookie ))) 00128 { 00129 SetLastError(RtlNtStatusToDosError(status)); 00130 return FALSE; 00131 } 00132 return TRUE; 00133 } 00134 00135 /*********************************************************************** 00136 * DeactivateActCtx (KERNEL32.@) 00137 * 00138 * Deactivate an activation context. 00139 */ 00140 BOOL WINAPI DeactivateActCtx(DWORD dwFlags, ULONG_PTR ulCookie) 00141 { 00142 RtlDeactivateActivationContext( dwFlags, ulCookie ); 00143 return TRUE; 00144 } 00145 00146 /*********************************************************************** 00147 * GetCurrentActCtx (KERNEL32.@) 00148 * 00149 * Get the current activation context. 00150 */ 00151 BOOL WINAPI GetCurrentActCtx(HANDLE* phActCtx) 00152 { 00153 NTSTATUS status; 00154 00155 if ((status = RtlGetActiveActivationContext(phActCtx))) 00156 { 00157 SetLastError(RtlNtStatusToDosError(status)); 00158 return FALSE; 00159 } 00160 return TRUE; 00161 } 00162 00163 /*********************************************************************** 00164 * AddRefActCtx (KERNEL32.@) 00165 * 00166 * Add a reference to an activation context. 00167 */ 00168 void WINAPI AddRefActCtx(HANDLE hActCtx) 00169 { 00170 RtlAddRefActivationContext(hActCtx); 00171 } 00172 00173 /*********************************************************************** 00174 * ReleaseActCtx (KERNEL32.@) 00175 * 00176 * Release a reference to an activation context. 00177 */ 00178 void WINAPI ReleaseActCtx(HANDLE hActCtx) 00179 { 00180 RtlReleaseActivationContext(hActCtx); 00181 } 00182 00183 /*********************************************************************** 00184 * ZombifyActCtx (KERNEL32.@) 00185 * 00186 * Release a reference to an activation context. 00187 */ 00188 BOOL WINAPI ZombifyActCtx(HANDLE hActCtx) 00189 { 00190 FIXME("%p\n", hActCtx); 00191 if (hActCtx != ACTCTX_FAKE_HANDLE) 00192 return FALSE; 00193 return TRUE; 00194 } 00195 00196 /*********************************************************************** 00197 * FindActCtxSectionStringA (KERNEL32.@) 00198 * 00199 * Find information about a string in an activation context. 00200 */ 00201 BOOL WINAPI FindActCtxSectionStringA(DWORD dwFlags, const GUID* lpExtGuid, 00202 ULONG ulId, LPCSTR lpSearchStr, 00203 PACTCTX_SECTION_KEYED_DATA pInfo) 00204 { 00205 LPWSTR search_str; 00206 DWORD len; 00207 BOOL ret; 00208 00209 TRACE("%08x %s %u %s %p\n", dwFlags, debugstr_guid(lpExtGuid), 00210 ulId, debugstr_a(lpSearchStr), pInfo); 00211 00212 if (!lpSearchStr) 00213 { 00214 SetLastError(ERROR_INVALID_PARAMETER); 00215 return FALSE; 00216 } 00217 00218 len = MultiByteToWideChar(CP_ACP, 0, lpSearchStr, -1, NULL, 0); 00219 search_str = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); 00220 MultiByteToWideChar(CP_ACP, 0, lpSearchStr, -1, search_str, len); 00221 00222 ret = FindActCtxSectionStringW(dwFlags, lpExtGuid, ulId, search_str, pInfo); 00223 00224 HeapFree(GetProcessHeap(), 0, search_str); 00225 return ret; 00226 } 00227 00228 /*********************************************************************** 00229 * FindActCtxSectionStringW (KERNEL32.@) 00230 * 00231 * Find information about a string in an activation context. 00232 */ 00233 BOOL WINAPI FindActCtxSectionStringW(DWORD dwFlags, const GUID* lpExtGuid, 00234 ULONG ulId, LPCWSTR lpSearchStr, 00235 PACTCTX_SECTION_KEYED_DATA pInfo) 00236 { 00237 UNICODE_STRING us; 00238 NTSTATUS status; 00239 00240 RtlInitUnicodeString(&us, lpSearchStr); 00241 if ((status = RtlFindActivationContextSectionString(dwFlags, lpExtGuid, ulId, &us, pInfo))) 00242 { 00243 SetLastError(RtlNtStatusToDosError(status)); 00244 return FALSE; 00245 } 00246 return TRUE; 00247 } 00248 00249 /*********************************************************************** 00250 * FindActCtxSectionGuid (KERNEL32.@) 00251 * 00252 * Find information about a GUID in an activation context. 00253 */ 00254 BOOL WINAPI FindActCtxSectionGuid(DWORD dwFlags, const GUID* lpExtGuid, 00255 ULONG ulId, const GUID* lpSearchGuid, 00256 PACTCTX_SECTION_KEYED_DATA pInfo) 00257 { 00258 FIXME("%08x %s %u %s %p\n", dwFlags, debugstr_guid(lpExtGuid), 00259 ulId, debugstr_guid(lpSearchGuid), pInfo); 00260 SetLastError( ERROR_CALL_NOT_IMPLEMENTED); 00261 return FALSE; 00262 } 00263 00264 /*********************************************************************** 00265 * QueryActCtxW (KERNEL32.@) 00266 * 00267 * Get information about an activation context. 00268 */ 00269 BOOL WINAPI QueryActCtxW(DWORD dwFlags, HANDLE hActCtx, PVOID pvSubInst, 00270 ULONG ulClass, PVOID pvBuff, SIZE_T cbBuff, 00271 SIZE_T *pcbLen) 00272 { 00273 NTSTATUS status; 00274 00275 if ((status = RtlQueryInformationActivationContext( dwFlags, hActCtx, pvSubInst, ulClass, 00276 pvBuff, cbBuff, pcbLen ))) 00277 { 00278 SetLastError(RtlNtStatusToDosError(status)); 00279 return FALSE; 00280 } 00281 return TRUE; 00282 } 00283 00284 /* REACTOS PRIVATE ************************************************************/ 00285 00286 VOID 00287 NTAPI 00288 BasepFreeActivationContextActivationBlock(IN PBASEP_ACTCTX_BLOCK ActivationBlock) 00289 { 00290 /* Exit if there was nothing passed in */ 00291 if (!ActivationBlock) return; 00292 00293 /* Do we have a context? */ 00294 if (ActivationBlock->ActivationContext) 00295 { 00296 /* Release and clear it */ 00297 RtlReleaseActivationContext(ActivationBlock->ActivationContext); 00298 ActivationBlock->ActivationContext = NULL; 00299 } 00300 00301 /* Free the block */ 00302 RtlFreeHeap(RtlGetProcessHeap(), 0, ActivationBlock); 00303 } 00304 00305 NTSTATUS 00306 NTAPI 00307 BasepAllocateActivationContextActivationBlock(IN DWORD Flags, 00308 IN PVOID CompletionRoutine, 00309 IN PVOID CompletionContext, 00310 OUT PBASEP_ACTCTX_BLOCK *ActivationBlock) 00311 { 00312 NTSTATUS Status; 00313 ACTIVATION_CONTEXT_BASIC_INFORMATION ContextInfo; 00314 00315 /* Clear the info structure */ 00316 ContextInfo.dwFlags = 0; 00317 ContextInfo.hActCtx = NULL; 00318 00319 /* Assume failure */ 00320 if (ActivationBlock) *ActivationBlock = NULL; 00321 00322 /* Only support valid flags */ 00323 if (Flags & ~(1 | 2)) // FIXME: What are they? 2 looks like BASEP_ACTCTX_FORCE_BLOCK 00324 { 00325 /* Fail if unknown flags are passed in */ 00326 Status = STATUS_INVALID_PARAMETER_1; 00327 goto Quickie; 00328 } 00329 00330 /* Caller should have passed in an activation block */ 00331 if (!ActivationBlock) 00332 { 00333 /* Fail otherwise */ 00334 Status = STATUS_INVALID_PARAMETER_4; 00335 goto Quickie; 00336 } 00337 00338 /* Query RTL for information on the current activation context */ 00339 Status = RtlQueryInformationActivationContext(1, 00340 NULL, 00341 0, 00342 ActivationContextBasicInformation, 00343 &ContextInfo, 00344 sizeof(ContextInfo), 00345 NULL); 00346 if (!NT_SUCCESS(Status)) 00347 { 00348 /* Failed -- bail out */ 00349 DPRINT1("SXS: %s - Failure getting active activation context; ntstatus %08lx\n", 00350 __FUNCTION__, Status); 00351 goto Quickie; 00352 } 00353 00354 /* Check if the current one should be freed */ 00355 if (ContextInfo.dwFlags & 1) 00356 { 00357 /* Release and clear it */ 00358 RtlReleaseActivationContext(ContextInfo.hActCtx); 00359 ContextInfo.hActCtx = NULL; 00360 } 00361 00362 /* Check if there's an active context, or if the caller is forcing one */ 00363 if (!(Flags & 2) || (ContextInfo.hActCtx)) 00364 { 00365 /* Allocate the block */ 00366 *ActivationBlock = RtlAllocateHeap(RtlGetProcessHeap(), 00367 0, 00368 sizeof(BASEP_ACTCTX_BLOCK)); 00369 if (!(*ActivationBlock)) 00370 { 00371 /* Ran out of memory, fail */ 00372 Status = STATUS_NO_MEMORY; 00373 goto Quickie; 00374 } 00375 00376 /* Fill it out */ 00377 (*ActivationBlock)->ActivationContext = ContextInfo.hActCtx; 00378 (*ActivationBlock)->Flags = 0; 00379 if (Flags & 1) (*ActivationBlock)->Flags |= 1; // Not sure about this flag 00380 (*ActivationBlock)->CompletionRoutine = CompletionRoutine; 00381 (*ActivationBlock)->CompletionContext = CompletionContext; 00382 00383 /* Tell Quickie below not to free anything, since this is success */ 00384 ContextInfo.hActCtx = NULL; 00385 } 00386 00387 /* Set success status */ 00388 Status = STATUS_SUCCESS; 00389 00390 Quickie: 00391 /* Failure or success path, return to caller and free on failure */ 00392 if (ContextInfo.hActCtx) RtlReleaseActivationContext(ContextInfo.hActCtx); 00393 return Status; 00394 } 00395 00396 /* EOF */ Generated on Sat May 26 2012 04:23:04 for ReactOS by
1.7.6.1
|