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
24 #include "wine/port.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
)
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
);
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
);
105 HeapFree(GetProcessHeap(), 0, src
);
106 HeapFree(GetProcessHeap(), 0, assdir
);
107 HeapFree(GetProcessHeap(), 0, resname
);
108 HeapFree(GetProcessHeap(), 0, appname
);
112 /***********************************************************************
113 * CreateActCtxW (KERNEL32.@)
115 * Create an activation context.
117 HANDLE WINAPI
CreateActCtxW(PCACTCTXW pActCtx
)
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
;
132 /***********************************************************************
133 * ActivateActCtx (KERNEL32.@)
135 * Activate an activation context.
137 BOOL WINAPI
ActivateActCtx(HANDLE hActCtx
, ULONG_PTR
*ulCookie
)
141 if ((status
= RtlActivateActivationContext( 0, hActCtx
, ulCookie
)))
143 SetLastError(RtlNtStatusToDosError(status
));
149 /***********************************************************************
150 * DeactivateActCtx (KERNEL32.@)
152 * Deactivate an activation context.
154 BOOL WINAPI
DeactivateActCtx(DWORD dwFlags
, ULONG_PTR ulCookie
)
156 RtlDeactivateActivationContext( dwFlags
, ulCookie
);
160 /***********************************************************************
161 * GetCurrentActCtx (KERNEL32.@)
163 * Get the current activation context.
165 BOOL WINAPI
GetCurrentActCtx(HANDLE
* phActCtx
)
169 if ((status
= RtlGetActiveActivationContext(phActCtx
)))
171 SetLastError(RtlNtStatusToDosError(status
));
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
)
206 if ((status
= RtlZombifyActivationContext(hActCtx
)))
208 SetLastError(RtlNtStatusToDosError(status
));
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
)
227 TRACE("%08x %s %u %s %p\n", dwFlags
, debugstr_guid(lpExtGuid
),
228 ulId
, debugstr_a(lpSearchStr
), pInfo
);
230 if (!lpSearchStr
|| !pInfo
)
232 SetLastError(ERROR_INVALID_PARAMETER
);
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
);
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
)
260 SetLastError(ERROR_INVALID_PARAMETER
);
264 RtlInitUnicodeString(&us
, lpSearchStr
);
265 if ((status
= RtlFindActivationContextSectionString(dwFlags
, lpExtGuid
, ulId
, &us
, pInfo
)))
267 SetLastError(RtlNtStatusToDosError(status
));
273 /***********************************************************************
274 * FindActCtxSectionGuid (KERNEL32.@)
276 * Find information about a GUID in an activation context.
278 BOOL WINAPI
FindActCtxSectionGuid(DWORD dwFlags
, const GUID
* lpExtGuid
,
279 ULONG ulId
, const GUID
* lpSearchGuid
,
280 PACTCTX_SECTION_KEYED_DATA pInfo
)
284 if ((status
= RtlFindActivationContextSectionGuid(dwFlags
, lpExtGuid
, ulId
, lpSearchGuid
, pInfo
)))
286 SetLastError(RtlNtStatusToDosError(status
));
293 /***********************************************************************
294 * QueryActCtxW (KERNEL32.@)
296 * Get information about an activation context.
298 BOOL WINAPI
QueryActCtxW(DWORD dwFlags
, HANDLE hActCtx
, PVOID pvSubInst
,
299 ULONG ulClass
, PVOID pvBuff
, SIZE_T cbBuff
,
304 if ((status
= RtlQueryInformationActivationContext( dwFlags
, hActCtx
, pvSubInst
, ulClass
,
305 pvBuff
, cbBuff
, pcbLen
)))
307 SetLastError(RtlNtStatusToDosError(status
));