2004-01-30 23:57:21 +01:00
|
|
|
/*
|
|
|
|
* Activation contexts
|
|
|
|
*
|
|
|
|
* Copyright 2004 Jon Griffiths
|
2007-05-07 21:49:40 +02:00
|
|
|
* Copyright 2007 Eric Pouech
|
|
|
|
* Copyright 2007 Jacek Caban for CodeWeavers
|
2004-01-30 23:57:21 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-01-30 23:57:21 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
2007-05-07 21:49:40 +02:00
|
|
|
#include "winnls.h"
|
2007-07-19 17:01:04 +02:00
|
|
|
#include "winternl.h"
|
2004-01-30 23:57:21 +01:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(actctx);
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateActCtxA (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Create an activation context.
|
|
|
|
*/
|
2019-04-23 20:11:14 +02:00
|
|
|
HANDLE WINAPI DECLSPEC_HOTPATCH CreateActCtxA(PCACTCTXA pActCtx)
|
2004-01-30 23:57:21 +01:00
|
|
|
{
|
2007-05-07 21:49:40 +02:00
|
|
|
ACTCTXW actw;
|
|
|
|
SIZE_T len;
|
|
|
|
HANDLE ret = INVALID_HANDLE_VALUE;
|
|
|
|
LPWSTR src = NULL, assdir = NULL, resname = NULL, appname = NULL;
|
2006-03-07 10:24:24 +01:00
|
|
|
|
2007-05-07 21:49:40 +02:00
|
|
|
TRACE("%p %08x\n", pActCtx, pActCtx ? pActCtx->dwFlags : 0);
|
|
|
|
|
2007-07-19 17:01:04 +02:00
|
|
|
if (!pActCtx || pActCtx->cbSize != sizeof(*pActCtx))
|
2007-05-07 21:49:40 +02:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
actw.cbSize = sizeof(actw);
|
|
|
|
actw.dwFlags = pActCtx->dwFlags;
|
|
|
|
if (pActCtx->lpSource)
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, pActCtx->lpSource, -1, NULL, 0);
|
|
|
|
src = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
if (!src) return INVALID_HANDLE_VALUE;
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pActCtx->lpSource, -1, src, len);
|
|
|
|
}
|
|
|
|
actw.lpSource = src;
|
|
|
|
|
|
|
|
if (actw.dwFlags & ACTCTX_FLAG_PROCESSOR_ARCHITECTURE_VALID)
|
|
|
|
actw.wProcessorArchitecture = pActCtx->wProcessorArchitecture;
|
|
|
|
if (actw.dwFlags & ACTCTX_FLAG_LANGID_VALID)
|
|
|
|
actw.wLangId = pActCtx->wLangId;
|
|
|
|
if (actw.dwFlags & ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID)
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, pActCtx->lpAssemblyDirectory, -1, NULL, 0);
|
|
|
|
assdir = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
if (!assdir) goto done;
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pActCtx->lpAssemblyDirectory, -1, assdir, len);
|
|
|
|
actw.lpAssemblyDirectory = assdir;
|
|
|
|
}
|
|
|
|
if (actw.dwFlags & ACTCTX_FLAG_RESOURCE_NAME_VALID)
|
|
|
|
{
|
2007-05-11 11:19:38 +02:00
|
|
|
if ((ULONG_PTR)pActCtx->lpResourceName >> 16)
|
2007-05-07 21:49:40 +02:00
|
|
|
{
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, pActCtx->lpResourceName, -1, NULL, 0);
|
|
|
|
resname = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
if (!resname) goto done;
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pActCtx->lpResourceName, -1, resname, len);
|
|
|
|
actw.lpResourceName = resname;
|
|
|
|
}
|
2007-08-30 10:18:25 +02:00
|
|
|
else actw.lpResourceName = (LPCWSTR)pActCtx->lpResourceName;
|
2007-05-07 21:49:40 +02:00
|
|
|
}
|
|
|
|
if (actw.dwFlags & ACTCTX_FLAG_APPLICATION_NAME_VALID)
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, pActCtx->lpApplicationName, -1, NULL, 0);
|
|
|
|
appname = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
if (!appname) goto done;
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pActCtx->lpApplicationName, -1, appname, len);
|
|
|
|
actw.lpApplicationName = appname;
|
|
|
|
}
|
|
|
|
if (actw.dwFlags & ACTCTX_FLAG_HMODULE_VALID)
|
|
|
|
actw.hModule = pActCtx->hModule;
|
|
|
|
|
|
|
|
ret = CreateActCtxW(&actw);
|
|
|
|
|
|
|
|
done:
|
|
|
|
HeapFree(GetProcessHeap(), 0, src);
|
|
|
|
HeapFree(GetProcessHeap(), 0, assdir);
|
|
|
|
HeapFree(GetProcessHeap(), 0, resname);
|
|
|
|
HeapFree(GetProcessHeap(), 0, appname);
|
|
|
|
return ret;
|
2004-01-30 23:57:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateActCtxW (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Create an activation context.
|
|
|
|
*/
|
2019-04-23 20:11:14 +02:00
|
|
|
HANDLE WINAPI DECLSPEC_HOTPATCH CreateActCtxW(PCACTCTXW pActCtx)
|
2004-01-30 23:57:21 +01:00
|
|
|
{
|
2007-07-19 17:01:04 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
HANDLE hActCtx;
|
2006-03-07 10:24:24 +01:00
|
|
|
|
2007-05-07 21:49:47 +02:00
|
|
|
TRACE("%p %08x\n", pActCtx, pActCtx ? pActCtx->dwFlags : 0);
|
|
|
|
|
2007-07-19 17:01:04 +02:00
|
|
|
if ((status = RtlCreateActivationContext(&hActCtx, pActCtx)))
|
2007-05-07 21:49:47 +02:00
|
|
|
{
|
2007-07-19 17:01:04 +02:00
|
|
|
SetLastError(RtlNtStatusToDosError(status));
|
2007-05-07 21:49:47 +02:00
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
2007-07-19 17:01:04 +02:00
|
|
|
return hActCtx;
|
2004-01-30 23:57:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ActivateActCtx (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Activate an activation context.
|
|
|
|
*/
|
2004-02-27 22:28:34 +01:00
|
|
|
BOOL WINAPI ActivateActCtx(HANDLE hActCtx, ULONG_PTR *ulCookie)
|
2004-01-30 23:57:21 +01:00
|
|
|
{
|
2007-07-19 17:07:48 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if ((status = RtlActivateActivationContext( 0, hActCtx, ulCookie )))
|
|
|
|
{
|
|
|
|
SetLastError(RtlNtStatusToDosError(status));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2004-01-30 23:57:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DeactivateActCtx (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Deactivate an activation context.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DeactivateActCtx(DWORD dwFlags, ULONG_PTR ulCookie)
|
|
|
|
{
|
2007-07-19 17:07:48 +02:00
|
|
|
RtlDeactivateActivationContext( dwFlags, ulCookie );
|
|
|
|
return TRUE;
|
2004-01-30 23:57:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetCurrentActCtx (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Get the current activation context.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetCurrentActCtx(HANDLE* phActCtx)
|
|
|
|
{
|
2007-07-19 17:07:48 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if ((status = RtlGetActiveActivationContext(phActCtx)))
|
|
|
|
{
|
|
|
|
SetLastError(RtlNtStatusToDosError(status));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2004-01-30 23:57:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* AddRefActCtx (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Add a reference to an activation context.
|
|
|
|
*/
|
|
|
|
void WINAPI AddRefActCtx(HANDLE hActCtx)
|
|
|
|
{
|
2007-07-19 17:01:04 +02:00
|
|
|
RtlAddRefActivationContext(hActCtx);
|
2004-01-30 23:57:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ReleaseActCtx (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Release a reference to an activation context.
|
|
|
|
*/
|
|
|
|
void WINAPI ReleaseActCtx(HANDLE hActCtx)
|
|
|
|
{
|
2007-07-19 17:01:04 +02:00
|
|
|
RtlReleaseActivationContext(hActCtx);
|
2004-01-30 23:57:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ZombifyActCtx (KERNEL32.@)
|
|
|
|
*
|
2013-09-02 12:30:50 +02:00
|
|
|
* Deactivate context without releasing it.
|
2004-01-30 23:57:21 +01:00
|
|
|
*/
|
|
|
|
BOOL WINAPI ZombifyActCtx(HANDLE hActCtx)
|
|
|
|
{
|
2013-09-02 12:30:50 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if ((status = RtlZombifyActivationContext(hActCtx)))
|
|
|
|
{
|
|
|
|
SetLastError(RtlNtStatusToDosError(status));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2004-01-30 23:57:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FindActCtxSectionStringA (KERNEL32.@)
|
|
|
|
*
|
2009-12-17 21:57:23 +01:00
|
|
|
* Find information about a string in an activation context.
|
2004-01-30 23:57:21 +01:00
|
|
|
*/
|
|
|
|
BOOL WINAPI FindActCtxSectionStringA(DWORD dwFlags, const GUID* lpExtGuid,
|
|
|
|
ULONG ulId, LPCSTR lpSearchStr,
|
2004-02-27 22:28:34 +01:00
|
|
|
PACTCTX_SECTION_KEYED_DATA pInfo)
|
2004-01-30 23:57:21 +01:00
|
|
|
{
|
2007-07-25 20:37:49 +02:00
|
|
|
LPWSTR search_str;
|
|
|
|
DWORD len;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
TRACE("%08x %s %u %s %p\n", dwFlags, debugstr_guid(lpExtGuid),
|
|
|
|
ulId, debugstr_a(lpSearchStr), pInfo);
|
|
|
|
|
2015-03-16 03:38:58 +01:00
|
|
|
if (!lpSearchStr || !pInfo)
|
2007-07-25 20:37:49 +02:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, lpSearchStr, -1, NULL, 0);
|
|
|
|
search_str = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, lpSearchStr, -1, search_str, len);
|
|
|
|
|
|
|
|
ret = FindActCtxSectionStringW(dwFlags, lpExtGuid, ulId, search_str, pInfo);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, search_str);
|
|
|
|
return ret;
|
2004-01-30 23:57:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FindActCtxSectionStringW (KERNEL32.@)
|
|
|
|
*
|
2009-12-17 21:57:23 +01:00
|
|
|
* Find information about a string in an activation context.
|
2004-01-30 23:57:21 +01:00
|
|
|
*/
|
|
|
|
BOOL WINAPI FindActCtxSectionStringW(DWORD dwFlags, const GUID* lpExtGuid,
|
|
|
|
ULONG ulId, LPCWSTR lpSearchStr,
|
2004-02-27 22:28:34 +01:00
|
|
|
PACTCTX_SECTION_KEYED_DATA pInfo)
|
2004-01-30 23:57:21 +01:00
|
|
|
{
|
2007-07-25 20:37:36 +02:00
|
|
|
UNICODE_STRING us;
|
|
|
|
NTSTATUS status;
|
2006-10-05 08:12:35 +02:00
|
|
|
|
2015-03-16 03:38:58 +01:00
|
|
|
if (!pInfo)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-07-25 20:37:36 +02:00
|
|
|
RtlInitUnicodeString(&us, lpSearchStr);
|
|
|
|
if ((status = RtlFindActivationContextSectionString(dwFlags, lpExtGuid, ulId, &us, pInfo)))
|
|
|
|
{
|
|
|
|
SetLastError(RtlNtStatusToDosError(status));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2004-01-30 23:57:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FindActCtxSectionGuid (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Find information about a GUID in an activation context.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI FindActCtxSectionGuid(DWORD dwFlags, const GUID* lpExtGuid,
|
|
|
|
ULONG ulId, const GUID* lpSearchGuid,
|
2004-02-27 22:28:34 +01:00
|
|
|
PACTCTX_SECTION_KEYED_DATA pInfo)
|
2004-01-30 23:57:21 +01:00
|
|
|
{
|
2013-07-31 07:09:27 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if ((status = RtlFindActivationContextSectionGuid(dwFlags, lpExtGuid, ulId, lpSearchGuid, pInfo)))
|
|
|
|
{
|
|
|
|
SetLastError(RtlNtStatusToDosError(status));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2004-01-30 23:57:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* QueryActCtxW (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Get information about an activation context.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI QueryActCtxW(DWORD dwFlags, HANDLE hActCtx, PVOID pvSubInst,
|
|
|
|
ULONG ulClass, PVOID pvBuff, SIZE_T cbBuff,
|
|
|
|
SIZE_T *pcbLen)
|
|
|
|
{
|
2007-07-25 18:17:36 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if ((status = RtlQueryInformationActivationContext( dwFlags, hActCtx, pvSubInst, ulClass,
|
|
|
|
pvBuff, cbBuff, pcbLen )))
|
|
|
|
{
|
|
|
|
SetLastError(RtlNtStatusToDosError(status));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2004-01-30 23:57:21 +01:00
|
|
|
}
|
2018-03-23 09:14:12 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* QueryActCtxSettingsW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI QueryActCtxSettingsW( DWORD flags, HANDLE ctx, const WCHAR *ns, const WCHAR *settings,
|
|
|
|
WCHAR *buffer, SIZE_T size, SIZE_T *written )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if ((status = RtlQueryActivationContextApplicationSettings( flags, ctx, ns, settings,
|
|
|
|
buffer, size, written )))
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError( status ));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|