1 /* 2 * COPYRIGHT: See COPYING in the top level directory 3 * PROJECT: ReactOS system libraries 4 * FILE: dll/win32/kernel32/wine/actctx.c 5 * PURPOSE: Activation contexts 6 * PROGRAMMERS: Jacek Caban for CodeWeavers 7 * Eric Pouech 8 * Jon Griffiths 9 * Dmitry Chapyshev (dmitry@reactos.org) 10 * Samuel Serapi�n 11 */ 12 13 /* Synched with Wine 1.7.55 */ 14 15 #include <k32.h> 16 17 #define NDEBUG 18 #include <debug.h> 19 DEBUG_CHANNEL(actctx); 20 21 /*********************************************************************** 22 * CreateActCtxA (KERNEL32.@) 23 * 24 * Create an activation context. 25 */ 26 HANDLE WINAPI CreateActCtxA(PCACTCTXA pActCtx) 27 { 28 ACTCTXW actw; 29 SIZE_T len; 30 HANDLE ret = INVALID_HANDLE_VALUE; 31 LPWSTR src = NULL, assdir = NULL, resname = NULL, appname = NULL; 32 33 TRACE("%p %08x\n", pActCtx, pActCtx ? pActCtx->dwFlags : 0); 34 35 if (!pActCtx || pActCtx->cbSize != sizeof(*pActCtx)) 36 { 37 SetLastError(ERROR_INVALID_PARAMETER); 38 return INVALID_HANDLE_VALUE; 39 } 40 41 actw.cbSize = sizeof(actw); 42 actw.dwFlags = pActCtx->dwFlags; 43 if (pActCtx->lpSource) 44 { 45 len = MultiByteToWideChar(CP_ACP, 0, pActCtx->lpSource, -1, NULL, 0); 46 src = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); 47 if (!src) return INVALID_HANDLE_VALUE; 48 MultiByteToWideChar(CP_ACP, 0, pActCtx->lpSource, -1, src, len); 49 } 50 actw.lpSource = src; 51 52 if (actw.dwFlags & ACTCTX_FLAG_PROCESSOR_ARCHITECTURE_VALID) 53 actw.wProcessorArchitecture = pActCtx->wProcessorArchitecture; 54 if (actw.dwFlags & ACTCTX_FLAG_LANGID_VALID) 55 actw.wLangId = pActCtx->wLangId; 56 if (actw.dwFlags & ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID) 57 { 58 len = MultiByteToWideChar(CP_ACP, 0, pActCtx->lpAssemblyDirectory, -1, NULL, 0); 59 assdir = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); 60 if (!assdir) goto done; 61 MultiByteToWideChar(CP_ACP, 0, pActCtx->lpAssemblyDirectory, -1, assdir, len); 62 actw.lpAssemblyDirectory = assdir; 63 } 64 if (actw.dwFlags & ACTCTX_FLAG_RESOURCE_NAME_VALID) 65 { 66 if ((ULONG_PTR)pActCtx->lpResourceName >> 16) 67 { 68 len = MultiByteToWideChar(CP_ACP, 0, pActCtx->lpResourceName, -1, NULL, 0); 69 resname = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); 70 if (!resname) goto done; 71 MultiByteToWideChar(CP_ACP, 0, pActCtx->lpResourceName, -1, resname, len); 72 actw.lpResourceName = resname; 73 } 74 else actw.lpResourceName = (LPCWSTR)pActCtx->lpResourceName; 75 } 76 if (actw.dwFlags & ACTCTX_FLAG_APPLICATION_NAME_VALID) 77 { 78 len = MultiByteToWideChar(CP_ACP, 0, pActCtx->lpApplicationName, -1, NULL, 0); 79 appname = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); 80 if (!appname) goto done; 81 MultiByteToWideChar(CP_ACP, 0, pActCtx->lpApplicationName, -1, appname, len); 82 actw.lpApplicationName = appname; 83 } 84 if (actw.dwFlags & ACTCTX_FLAG_HMODULE_VALID) 85 actw.hModule = pActCtx->hModule; 86 87 ret = CreateActCtxW(&actw); 88 89 done: 90 HeapFree(GetProcessHeap(), 0, src); 91 HeapFree(GetProcessHeap(), 0, assdir); 92 HeapFree(GetProcessHeap(), 0, resname); 93 HeapFree(GetProcessHeap(), 0, appname); 94 return ret; 95 } 96 97 /*********************************************************************** 98 * CreateActCtxW (KERNEL32.@) 99 * 100 * Create an activation context. 101 */ 102 HANDLE WINAPI CreateActCtxW(PCACTCTXW pActCtx) 103 { 104 NTSTATUS status; 105 HANDLE hActCtx; 106 107 TRACE("%p %08x\n", pActCtx, pActCtx ? pActCtx->dwFlags : 0); 108 109 if ((status = RtlCreateActivationContext(0, (PVOID)pActCtx, 0, NULL, NULL, &hActCtx))) 110 { 111 SetLastError(RtlNtStatusToDosError(status)); 112 return INVALID_HANDLE_VALUE; 113 } 114 return hActCtx; 115 } 116 117 #ifndef __REACTOS__ 118 /*********************************************************************** 119 * ActivateActCtx (KERNEL32.@) 120 * 121 * Activate an activation context. 122 */ 123 BOOL WINAPI ActivateActCtx(HANDLE hActCtx, ULONG_PTR *ulCookie) 124 { 125 NTSTATUS status; 126 127 if ((status = RtlActivateActivationContext( 0, hActCtx, ulCookie ))) 128 { 129 SetLastError(RtlNtStatusToDosError(status)); 130 return FALSE; 131 } 132 return TRUE; 133 } 134 135 /*********************************************************************** 136 * DeactivateActCtx (KERNEL32.@) 137 * 138 * Deactivate an activation context. 139 */ 140 BOOL WINAPI DeactivateActCtx(DWORD dwFlags, ULONG_PTR ulCookie) 141 { 142 RtlDeactivateActivationContext( dwFlags, ulCookie ); 143 return TRUE; 144 } 145 146 /*********************************************************************** 147 * GetCurrentActCtx (KERNEL32.@) 148 * 149 * Get the current activation context. 150 */ 151 BOOL WINAPI GetCurrentActCtx(HANDLE* phActCtx) 152 { 153 NTSTATUS status; 154 155 if ((status = RtlGetActiveActivationContext(phActCtx))) 156 { 157 SetLastError(RtlNtStatusToDosError(status)); 158 return FALSE; 159 } 160 return TRUE; 161 } 162 163 /*********************************************************************** 164 * AddRefActCtx (KERNEL32.@) 165 * 166 * Add a reference to an activation context. 167 */ 168 void WINAPI AddRefActCtx(HANDLE hActCtx) 169 { 170 RtlAddRefActivationContext(hActCtx); 171 } 172 173 /*********************************************************************** 174 * ReleaseActCtx (KERNEL32.@) 175 * 176 * Release a reference to an activation context. 177 */ 178 void WINAPI ReleaseActCtx(HANDLE hActCtx) 179 { 180 RtlReleaseActivationContext(hActCtx); 181 } 182 183 /*********************************************************************** 184 * ZombifyActCtx (KERNEL32.@) 185 * 186 * Deactivate context without releasing it. 187 */ 188 BOOL WINAPI ZombifyActCtx(HANDLE hActCtx) 189 { 190 NTSTATUS status; 191 192 if ((status = RtlZombifyActivationContext(hActCtx))) 193 { 194 SetLastError(RtlNtStatusToDosError(status)); 195 return FALSE; 196 } 197 return TRUE; 198 } 199 #endif // !__REACTOS__ 200 201 /*********************************************************************** 202 * FindActCtxSectionStringA (KERNEL32.@) 203 * 204 * Find information about a string in an activation context. 205 */ 206 BOOL WINAPI FindActCtxSectionStringA(DWORD dwFlags, const GUID* lpExtGuid, 207 ULONG ulId, LPCSTR lpSearchStr, 208 PACTCTX_SECTION_KEYED_DATA pInfo) 209 { 210 LPWSTR search_str; 211 DWORD len; 212 BOOL ret; 213 214 TRACE("%08x %s %u %s %p\n", dwFlags, debugstr_guid(lpExtGuid), 215 ulId, debugstr_a(lpSearchStr), pInfo); 216 217 if (!lpSearchStr || !pInfo) 218 { 219 SetLastError(ERROR_INVALID_PARAMETER); 220 return FALSE; 221 } 222 223 len = MultiByteToWideChar(CP_ACP, 0, lpSearchStr, -1, NULL, 0); 224 search_str = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); 225 MultiByteToWideChar(CP_ACP, 0, lpSearchStr, -1, search_str, len); 226 227 ret = FindActCtxSectionStringW(dwFlags, lpExtGuid, ulId, search_str, pInfo); 228 229 HeapFree(GetProcessHeap(), 0, search_str); 230 return ret; 231 } 232 233 /*********************************************************************** 234 * FindActCtxSectionStringW (KERNEL32.@) 235 * 236 * Find information about a string in an activation context. 237 */ 238 BOOL WINAPI FindActCtxSectionStringW(DWORD dwFlags, const GUID* lpExtGuid, 239 ULONG ulId, LPCWSTR lpSearchStr, 240 PACTCTX_SECTION_KEYED_DATA pInfo) 241 { 242 UNICODE_STRING us; 243 NTSTATUS status; 244 245 if (!pInfo) 246 { 247 SetLastError(ERROR_INVALID_PARAMETER); 248 return FALSE; 249 } 250 251 RtlInitUnicodeString(&us, lpSearchStr); 252 if ((status = RtlFindActivationContextSectionString(dwFlags, lpExtGuid, ulId, &us, pInfo))) 253 { 254 SetLastError(RtlNtStatusToDosError(status)); 255 return FALSE; 256 } 257 return TRUE; 258 } 259 260 /*********************************************************************** 261 * FindActCtxSectionGuid (KERNEL32.@) 262 * 263 * Find information about a GUID in an activation context. 264 */ 265 BOOL WINAPI FindActCtxSectionGuid(DWORD dwFlags, const GUID* lpExtGuid, 266 ULONG ulId, const GUID* lpSearchGuid, 267 PACTCTX_SECTION_KEYED_DATA pInfo) 268 { 269 NTSTATUS status; 270 271 if ((status = RtlFindActivationContextSectionGuid(dwFlags, lpExtGuid, ulId, lpSearchGuid, pInfo))) 272 { 273 SetLastError(RtlNtStatusToDosError(status)); 274 return FALSE; 275 } 276 277 return TRUE; 278 } 279 280 #ifndef __REACTOS__ 281 /*********************************************************************** 282 * QueryActCtxW (KERNEL32.@) 283 * 284 * Get information about an activation context. 285 */ 286 BOOL WINAPI QueryActCtxW(DWORD dwFlags, HANDLE hActCtx, PVOID pvSubInst, 287 ULONG ulClass, PVOID pvBuff, SIZE_T cbBuff, 288 SIZE_T *pcbLen) 289 { 290 NTSTATUS status; 291 292 if ((status = RtlQueryInformationActivationContext( dwFlags, hActCtx, pvSubInst, ulClass, 293 pvBuff, cbBuff, pcbLen ))) 294 { 295 SetLastError(RtlNtStatusToDosError(status)); 296 return FALSE; 297 } 298 return TRUE; 299 } 300 #endif // !__REACTOS__ 301