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 */
18 static ULONG gDebugChannel
= actctx
;
20 #define ACTCTX_FAKE_HANDLE ((HANDLE) 0xf00baa)
22 /***********************************************************************
23 * CreateActCtxA (KERNEL32.@)
25 * Create an activation context.
27 HANDLE WINAPI
CreateActCtxA(PCACTCTXA pActCtx
)
31 HANDLE ret
= INVALID_HANDLE_VALUE
;
32 LPWSTR src
= NULL
, assdir
= NULL
, resname
= NULL
, appname
= NULL
;
34 TRACE("%p %08x\n", pActCtx
, pActCtx
? pActCtx
->dwFlags
: 0);
36 if (!pActCtx
|| pActCtx
->cbSize
!= sizeof(*pActCtx
))
38 SetLastError(ERROR_INVALID_PARAMETER
);
39 return INVALID_HANDLE_VALUE
;
42 actw
.cbSize
= sizeof(actw
);
43 actw
.dwFlags
= pActCtx
->dwFlags
;
44 if (pActCtx
->lpSource
)
46 len
= MultiByteToWideChar(CP_ACP
, 0, pActCtx
->lpSource
, -1, NULL
, 0);
47 src
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
48 if (!src
) return INVALID_HANDLE_VALUE
;
49 MultiByteToWideChar(CP_ACP
, 0, pActCtx
->lpSource
, -1, src
, len
);
53 if (actw
.dwFlags
& ACTCTX_FLAG_PROCESSOR_ARCHITECTURE_VALID
)
54 actw
.wProcessorArchitecture
= pActCtx
->wProcessorArchitecture
;
55 if (actw
.dwFlags
& ACTCTX_FLAG_LANGID_VALID
)
56 actw
.wLangId
= pActCtx
->wLangId
;
57 if (actw
.dwFlags
& ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID
)
59 len
= MultiByteToWideChar(CP_ACP
, 0, pActCtx
->lpAssemblyDirectory
, -1, NULL
, 0);
60 assdir
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
61 if (!assdir
) goto done
;
62 MultiByteToWideChar(CP_ACP
, 0, pActCtx
->lpAssemblyDirectory
, -1, assdir
, len
);
63 actw
.lpAssemblyDirectory
= assdir
;
65 if (actw
.dwFlags
& ACTCTX_FLAG_RESOURCE_NAME_VALID
)
67 if ((ULONG_PTR
)pActCtx
->lpResourceName
>> 16)
69 len
= MultiByteToWideChar(CP_ACP
, 0, pActCtx
->lpResourceName
, -1, NULL
, 0);
70 resname
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
71 if (!resname
) goto done
;
72 MultiByteToWideChar(CP_ACP
, 0, pActCtx
->lpResourceName
, -1, resname
, len
);
73 actw
.lpResourceName
= resname
;
75 else actw
.lpResourceName
= (LPCWSTR
)pActCtx
->lpResourceName
;
77 if (actw
.dwFlags
& ACTCTX_FLAG_APPLICATION_NAME_VALID
)
79 len
= MultiByteToWideChar(CP_ACP
, 0, pActCtx
->lpApplicationName
, -1, NULL
, 0);
80 appname
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
81 if (!appname
) goto done
;
82 MultiByteToWideChar(CP_ACP
, 0, pActCtx
->lpApplicationName
, -1, appname
, len
);
83 actw
.lpApplicationName
= appname
;
85 if (actw
.dwFlags
& ACTCTX_FLAG_HMODULE_VALID
)
86 actw
.hModule
= pActCtx
->hModule
;
88 ret
= CreateActCtxW(&actw
);
91 HeapFree(GetProcessHeap(), 0, src
);
92 HeapFree(GetProcessHeap(), 0, assdir
);
93 HeapFree(GetProcessHeap(), 0, resname
);
94 HeapFree(GetProcessHeap(), 0, appname
);
98 /***********************************************************************
99 * CreateActCtxW (KERNEL32.@)
101 * Create an activation context.
103 HANDLE WINAPI
CreateActCtxW(PCACTCTXW pActCtx
)
108 TRACE("%p %08x\n", pActCtx
, pActCtx
? pActCtx
->dwFlags
: 0);
110 if ((status
= RtlCreateActivationContext(&hActCtx
, (PVOID
*)pActCtx
)))
112 SetLastError(RtlNtStatusToDosError(status
));
113 return INVALID_HANDLE_VALUE
;
118 /***********************************************************************
119 * ActivateActCtx (KERNEL32.@)
121 * Activate an activation context.
123 BOOL WINAPI
ActivateActCtx(HANDLE hActCtx
, ULONG_PTR
*ulCookie
)
127 if ((status
= RtlActivateActivationContext( 0, hActCtx
, ulCookie
)))
129 SetLastError(RtlNtStatusToDosError(status
));
135 /***********************************************************************
136 * DeactivateActCtx (KERNEL32.@)
138 * Deactivate an activation context.
140 BOOL WINAPI
DeactivateActCtx(DWORD dwFlags
, ULONG_PTR ulCookie
)
142 RtlDeactivateActivationContext( dwFlags
, ulCookie
);
146 /***********************************************************************
147 * GetCurrentActCtx (KERNEL32.@)
149 * Get the current activation context.
151 BOOL WINAPI
GetCurrentActCtx(HANDLE
* phActCtx
)
155 if ((status
= RtlGetActiveActivationContext(phActCtx
)))
157 SetLastError(RtlNtStatusToDosError(status
));
163 /***********************************************************************
164 * AddRefActCtx (KERNEL32.@)
166 * Add a reference to an activation context.
168 void WINAPI
AddRefActCtx(HANDLE hActCtx
)
170 RtlAddRefActivationContext(hActCtx
);
173 /***********************************************************************
174 * ReleaseActCtx (KERNEL32.@)
176 * Release a reference to an activation context.
178 void WINAPI
ReleaseActCtx(HANDLE hActCtx
)
180 RtlReleaseActivationContext(hActCtx
);
183 /***********************************************************************
184 * ZombifyActCtx (KERNEL32.@)
186 * Release a reference to an activation context.
188 BOOL WINAPI
ZombifyActCtx(HANDLE hActCtx
)
190 FIXME("%p\n", hActCtx
);
191 if (hActCtx
!= ACTCTX_FAKE_HANDLE
)
196 /***********************************************************************
197 * FindActCtxSectionStringA (KERNEL32.@)
199 * Find information about a string in an activation context.
201 BOOL WINAPI
FindActCtxSectionStringA(DWORD dwFlags
, const GUID
* lpExtGuid
,
202 ULONG ulId
, LPCSTR lpSearchStr
,
203 PACTCTX_SECTION_KEYED_DATA pInfo
)
209 TRACE("%08x %s %u %s %p\n", dwFlags
, debugstr_guid(lpExtGuid
),
210 ulId
, debugstr_a(lpSearchStr
), pInfo
);
214 SetLastError(ERROR_INVALID_PARAMETER
);
218 len
= MultiByteToWideChar(CP_ACP
, 0, lpSearchStr
, -1, NULL
, 0);
219 search_str
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
220 MultiByteToWideChar(CP_ACP
, 0, lpSearchStr
, -1, search_str
, len
);
222 ret
= FindActCtxSectionStringW(dwFlags
, lpExtGuid
, ulId
, search_str
, pInfo
);
224 HeapFree(GetProcessHeap(), 0, search_str
);
228 /***********************************************************************
229 * FindActCtxSectionStringW (KERNEL32.@)
231 * Find information about a string in an activation context.
233 BOOL WINAPI
FindActCtxSectionStringW(DWORD dwFlags
, const GUID
* lpExtGuid
,
234 ULONG ulId
, LPCWSTR lpSearchStr
,
235 PACTCTX_SECTION_KEYED_DATA pInfo
)
240 RtlInitUnicodeString(&us
, lpSearchStr
);
241 if ((status
= RtlFindActivationContextSectionString(dwFlags
, lpExtGuid
, ulId
, &us
, pInfo
)))
243 SetLastError(RtlNtStatusToDosError(status
));
249 /***********************************************************************
250 * FindActCtxSectionGuid (KERNEL32.@)
252 * Find information about a GUID in an activation context.
254 BOOL WINAPI
FindActCtxSectionGuid(DWORD dwFlags
, const GUID
* lpExtGuid
,
255 ULONG ulId
, const GUID
* lpSearchGuid
,
256 PACTCTX_SECTION_KEYED_DATA pInfo
)
258 FIXME("%08x %s %u %s %p\n", dwFlags
, debugstr_guid(lpExtGuid
),
259 ulId
, debugstr_guid(lpSearchGuid
), pInfo
);
260 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
264 /***********************************************************************
265 * QueryActCtxW (KERNEL32.@)
267 * Get information about an activation context.
269 BOOL WINAPI
QueryActCtxW(DWORD dwFlags
, HANDLE hActCtx
, PVOID pvSubInst
,
270 ULONG ulClass
, PVOID pvBuff
, SIZE_T cbBuff
,
275 if ((status
= RtlQueryInformationActivationContext( dwFlags
, hActCtx
, pvSubInst
, ulClass
,
276 pvBuff
, cbBuff
, pcbLen
)))
278 SetLastError(RtlNtStatusToDosError(status
));