2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: dll/win32/kernel32/misc/actctx.c
5 * PURPOSE: Activation contexts
6 * PROGRAMMERS: Jacek Caban for CodeWeavers
9 * Dmitry Chapyshev (dmitry@reactos.org)
13 /* synched with wine 1.1.26 */
17 #include "wine/debug.h"
19 WINE_DEFAULT_DEBUG_CHANNEL(actctx
);
21 #define ACTCTX_FAKE_HANDLE ((HANDLE) 0xf00baa)
23 /***********************************************************************
24 * CreateActCtxA (KERNEL32.@)
26 * Create an activation context.
28 HANDLE WINAPI
CreateActCtxA(PCACTCTXA pActCtx
)
32 HANDLE ret
= INVALID_HANDLE_VALUE
;
33 LPWSTR src
= NULL
, assdir
= NULL
, resname
= NULL
, appname
= NULL
;
35 TRACE("%p %08x\n", pActCtx
, pActCtx
? pActCtx
->dwFlags
: 0);
37 if (!pActCtx
|| pActCtx
->cbSize
!= sizeof(*pActCtx
))
39 SetLastError(ERROR_INVALID_PARAMETER
);
40 return INVALID_HANDLE_VALUE
;
43 actw
.cbSize
= sizeof(actw
);
44 actw
.dwFlags
= pActCtx
->dwFlags
;
45 if (pActCtx
->lpSource
)
47 len
= MultiByteToWideChar(CP_ACP
, 0, pActCtx
->lpSource
, -1, NULL
, 0);
48 src
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
49 if (!src
) return INVALID_HANDLE_VALUE
;
50 MultiByteToWideChar(CP_ACP
, 0, pActCtx
->lpSource
, -1, src
, len
);
54 if (actw
.dwFlags
& ACTCTX_FLAG_PROCESSOR_ARCHITECTURE_VALID
)
55 actw
.wProcessorArchitecture
= pActCtx
->wProcessorArchitecture
;
56 if (actw
.dwFlags
& ACTCTX_FLAG_LANGID_VALID
)
57 actw
.wLangId
= pActCtx
->wLangId
;
58 if (actw
.dwFlags
& ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID
)
60 len
= MultiByteToWideChar(CP_ACP
, 0, pActCtx
->lpAssemblyDirectory
, -1, NULL
, 0);
61 assdir
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
62 if (!assdir
) goto done
;
63 MultiByteToWideChar(CP_ACP
, 0, pActCtx
->lpAssemblyDirectory
, -1, assdir
, len
);
64 actw
.lpAssemblyDirectory
= assdir
;
66 if (actw
.dwFlags
& ACTCTX_FLAG_RESOURCE_NAME_VALID
)
68 if ((ULONG_PTR
)pActCtx
->lpResourceName
>> 16)
70 len
= MultiByteToWideChar(CP_ACP
, 0, pActCtx
->lpResourceName
, -1, NULL
, 0);
71 resname
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
72 if (!resname
) goto done
;
73 MultiByteToWideChar(CP_ACP
, 0, pActCtx
->lpResourceName
, -1, resname
, len
);
74 actw
.lpResourceName
= resname
;
76 else actw
.lpResourceName
= (LPCWSTR
)pActCtx
->lpResourceName
;
78 if (actw
.dwFlags
& ACTCTX_FLAG_APPLICATION_NAME_VALID
)
80 len
= MultiByteToWideChar(CP_ACP
, 0, pActCtx
->lpApplicationName
, -1, NULL
, 0);
81 appname
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
82 if (!appname
) goto done
;
83 MultiByteToWideChar(CP_ACP
, 0, pActCtx
->lpApplicationName
, -1, appname
, len
);
84 actw
.lpApplicationName
= appname
;
86 if (actw
.dwFlags
& ACTCTX_FLAG_HMODULE_VALID
)
87 actw
.hModule
= pActCtx
->hModule
;
89 ret
= CreateActCtxW(&actw
);
92 HeapFree(GetProcessHeap(), 0, src
);
93 HeapFree(GetProcessHeap(), 0, assdir
);
94 HeapFree(GetProcessHeap(), 0, resname
);
95 HeapFree(GetProcessHeap(), 0, appname
);
99 /***********************************************************************
100 * CreateActCtxW (KERNEL32.@)
102 * Create an activation context.
104 HANDLE WINAPI
CreateActCtxW(PCACTCTXW pActCtx
)
109 TRACE("%p %08x\n", pActCtx
, pActCtx
? pActCtx
->dwFlags
: 0);
111 if ((status
= RtlCreateActivationContext(&hActCtx
, (PVOID
*)pActCtx
)))
113 SetLastError(RtlNtStatusToDosError(status
));
114 return INVALID_HANDLE_VALUE
;
119 /***********************************************************************
120 * ActivateActCtx (KERNEL32.@)
122 * Activate an activation context.
124 BOOL WINAPI
ActivateActCtx(HANDLE hActCtx
, ULONG_PTR
*ulCookie
)
128 if ((status
= RtlActivateActivationContext( 0, hActCtx
, ulCookie
)))
130 SetLastError(RtlNtStatusToDosError(status
));
136 /***********************************************************************
137 * DeactivateActCtx (KERNEL32.@)
139 * Deactivate an activation context.
141 BOOL WINAPI
DeactivateActCtx(DWORD dwFlags
, ULONG_PTR ulCookie
)
143 RtlDeactivateActivationContext( dwFlags
, ulCookie
);
147 /***********************************************************************
148 * GetCurrentActCtx (KERNEL32.@)
150 * Get the current activation context.
152 BOOL WINAPI
GetCurrentActCtx(HANDLE
* phActCtx
)
156 if ((status
= RtlGetActiveActivationContext(phActCtx
)))
158 SetLastError(RtlNtStatusToDosError(status
));
164 /***********************************************************************
165 * AddRefActCtx (KERNEL32.@)
167 * Add a reference to an activation context.
169 void WINAPI
AddRefActCtx(HANDLE hActCtx
)
171 RtlAddRefActivationContext(hActCtx
);
174 /***********************************************************************
175 * ReleaseActCtx (KERNEL32.@)
177 * Release a reference to an activation context.
179 void WINAPI
ReleaseActCtx(HANDLE hActCtx
)
181 RtlReleaseActivationContext(hActCtx
);
184 /***********************************************************************
185 * ZombifyActCtx (KERNEL32.@)
187 * Release a reference to an activation context.
189 BOOL WINAPI
ZombifyActCtx(HANDLE hActCtx
)
191 FIXME("%p\n", hActCtx
);
192 if (hActCtx
!= ACTCTX_FAKE_HANDLE
)
197 /***********************************************************************
198 * FindActCtxSectionStringA (KERNEL32.@)
200 * Find information about a GUID in an activation context.
202 BOOL WINAPI
FindActCtxSectionStringA(DWORD dwFlags
, const GUID
* lpExtGuid
,
203 ULONG ulId
, LPCSTR lpSearchStr
,
204 PACTCTX_SECTION_KEYED_DATA pInfo
)
210 TRACE("%08x %s %u %s %p\n", dwFlags
, debugstr_guid(lpExtGuid
),
211 ulId
, debugstr_a(lpSearchStr
), pInfo
);
215 SetLastError(ERROR_INVALID_PARAMETER
);
219 len
= MultiByteToWideChar(CP_ACP
, 0, lpSearchStr
, -1, NULL
, 0);
220 search_str
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
221 MultiByteToWideChar(CP_ACP
, 0, lpSearchStr
, -1, search_str
, len
);
223 ret
= FindActCtxSectionStringW(dwFlags
, lpExtGuid
, ulId
, search_str
, pInfo
);
225 HeapFree(GetProcessHeap(), 0, search_str
);
229 /***********************************************************************
230 * FindActCtxSectionStringW (KERNEL32.@)
232 * Find information about a GUID in an activation context.
234 BOOL WINAPI
FindActCtxSectionStringW(DWORD dwFlags
, const GUID
* lpExtGuid
,
235 ULONG ulId
, LPCWSTR lpSearchStr
,
236 PACTCTX_SECTION_KEYED_DATA pInfo
)
241 RtlInitUnicodeString(&us
, lpSearchStr
);
242 if ((status
= RtlFindActivationContextSectionString(dwFlags
, lpExtGuid
, ulId
, &us
, pInfo
)))
244 SetLastError(RtlNtStatusToDosError(status
));
250 /***********************************************************************
251 * FindActCtxSectionGuid (KERNEL32.@)
253 * Find information about a GUID in an activation context.
255 BOOL WINAPI
FindActCtxSectionGuid(DWORD dwFlags
, const GUID
* lpExtGuid
,
256 ULONG ulId
, const GUID
* lpSearchGuid
,
257 PACTCTX_SECTION_KEYED_DATA pInfo
)
259 FIXME("%08x %s %u %s %p\n", dwFlags
, debugstr_guid(lpExtGuid
),
260 ulId
, debugstr_guid(lpSearchGuid
), pInfo
);
261 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
265 /***********************************************************************
266 * QueryActCtxW (KERNEL32.@)
268 * Get information about an activation context.
270 BOOL WINAPI
QueryActCtxW(DWORD dwFlags
, HANDLE hActCtx
, PVOID pvSubInst
,
271 ULONG ulClass
, PVOID pvBuff
, SIZE_T cbBuff
,
276 if ((status
= RtlQueryInformationActivationContext( dwFlags
, hActCtx
, pvSubInst
, ulClass
,
277 pvBuff
, cbBuff
, pcbLen
)))
279 SetLastError(RtlNtStatusToDosError(status
));