ws2_32: Sending 0 bytes shouldn't cause an infinite loop.
[wine/hacks.git] / dlls / kernel32 / actctx.c
blob84c29cdf7e6bba8362f94c2f524649c5ce89fdda
1 /*
2 * Activation contexts
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
23 #include "config.h"
24 #include "wine/port.h"
26 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winerror.h"
30 #include "winnls.h"
31 #include "winternl.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(actctx);
37 #define ACTCTX_FAKE_HANDLE ((HANDLE) 0xf00baa)
39 /***********************************************************************
40 * CreateActCtxA (KERNEL32.@)
42 * Create an activation context.
44 HANDLE WINAPI CreateActCtxA(PCACTCTXA pActCtx)
46 ACTCTXW actw;
47 SIZE_T len;
48 HANDLE ret = INVALID_HANDLE_VALUE;
49 LPWSTR src = NULL, assdir = NULL, resname = NULL, appname = NULL;
51 TRACE("%p %08x\n", pActCtx, pActCtx ? pActCtx->dwFlags : 0);
53 if (!pActCtx || pActCtx->cbSize != sizeof(*pActCtx))
55 SetLastError(ERROR_INVALID_PARAMETER);
56 return INVALID_HANDLE_VALUE;
59 actw.cbSize = sizeof(actw);
60 actw.dwFlags = pActCtx->dwFlags;
61 if (pActCtx->lpSource)
63 len = MultiByteToWideChar(CP_ACP, 0, pActCtx->lpSource, -1, NULL, 0);
64 src = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
65 if (!src) return INVALID_HANDLE_VALUE;
66 MultiByteToWideChar(CP_ACP, 0, pActCtx->lpSource, -1, src, len);
68 actw.lpSource = src;
70 if (actw.dwFlags & ACTCTX_FLAG_PROCESSOR_ARCHITECTURE_VALID)
71 actw.wProcessorArchitecture = pActCtx->wProcessorArchitecture;
72 if (actw.dwFlags & ACTCTX_FLAG_LANGID_VALID)
73 actw.wLangId = pActCtx->wLangId;
74 if (actw.dwFlags & ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID)
76 len = MultiByteToWideChar(CP_ACP, 0, pActCtx->lpAssemblyDirectory, -1, NULL, 0);
77 assdir = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
78 if (!assdir) goto done;
79 MultiByteToWideChar(CP_ACP, 0, pActCtx->lpAssemblyDirectory, -1, assdir, len);
80 actw.lpAssemblyDirectory = assdir;
82 if (actw.dwFlags & ACTCTX_FLAG_RESOURCE_NAME_VALID)
84 if ((ULONG_PTR)pActCtx->lpResourceName >> 16)
86 len = MultiByteToWideChar(CP_ACP, 0, pActCtx->lpResourceName, -1, NULL, 0);
87 resname = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
88 if (!resname) goto done;
89 MultiByteToWideChar(CP_ACP, 0, pActCtx->lpResourceName, -1, resname, len);
90 actw.lpResourceName = resname;
92 else actw.lpResourceName = (LPWSTR)pActCtx->lpResourceName;
94 if (actw.dwFlags & ACTCTX_FLAG_APPLICATION_NAME_VALID)
96 len = MultiByteToWideChar(CP_ACP, 0, pActCtx->lpApplicationName, -1, NULL, 0);
97 appname = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
98 if (!appname) goto done;
99 MultiByteToWideChar(CP_ACP, 0, pActCtx->lpApplicationName, -1, appname, len);
100 actw.lpApplicationName = appname;
102 if (actw.dwFlags & ACTCTX_FLAG_HMODULE_VALID)
103 actw.hModule = pActCtx->hModule;
105 ret = CreateActCtxW(&actw);
107 done:
108 HeapFree(GetProcessHeap(), 0, src);
109 HeapFree(GetProcessHeap(), 0, assdir);
110 HeapFree(GetProcessHeap(), 0, resname);
111 HeapFree(GetProcessHeap(), 0, appname);
112 return ret;
115 /***********************************************************************
116 * CreateActCtxW (KERNEL32.@)
118 * Create an activation context.
120 HANDLE WINAPI CreateActCtxW(PCACTCTXW pActCtx)
122 NTSTATUS status;
123 HANDLE hActCtx;
125 TRACE("%p %08x\n", pActCtx, pActCtx ? pActCtx->dwFlags : 0);
127 if ((status = RtlCreateActivationContext(&hActCtx, pActCtx)))
129 SetLastError(RtlNtStatusToDosError(status));
130 return INVALID_HANDLE_VALUE;
132 return hActCtx;
135 /***********************************************************************
136 * ActivateActCtx (KERNEL32.@)
138 * Activate an activation context.
140 BOOL WINAPI ActivateActCtx(HANDLE hActCtx, ULONG_PTR *ulCookie)
142 NTSTATUS status;
144 if ((status = RtlActivateActivationContext( 0, hActCtx, ulCookie )))
146 SetLastError(RtlNtStatusToDosError(status));
147 return FALSE;
149 return TRUE;
152 /***********************************************************************
153 * DeactivateActCtx (KERNEL32.@)
155 * Deactivate an activation context.
157 BOOL WINAPI DeactivateActCtx(DWORD dwFlags, ULONG_PTR ulCookie)
159 RtlDeactivateActivationContext( dwFlags, ulCookie );
160 return TRUE;
163 /***********************************************************************
164 * GetCurrentActCtx (KERNEL32.@)
166 * Get the current activation context.
168 BOOL WINAPI GetCurrentActCtx(HANDLE* phActCtx)
170 NTSTATUS status;
172 if ((status = RtlGetActiveActivationContext(phActCtx)))
174 SetLastError(RtlNtStatusToDosError(status));
175 return FALSE;
177 return TRUE;
180 /***********************************************************************
181 * AddRefActCtx (KERNEL32.@)
183 * Add a reference to an activation context.
185 void WINAPI AddRefActCtx(HANDLE hActCtx)
187 RtlAddRefActivationContext(hActCtx);
190 /***********************************************************************
191 * ReleaseActCtx (KERNEL32.@)
193 * Release a reference to an activation context.
195 void WINAPI ReleaseActCtx(HANDLE hActCtx)
197 RtlReleaseActivationContext(hActCtx);
200 /***********************************************************************
201 * ZombifyActCtx (KERNEL32.@)
203 * Release a reference to an activation context.
205 BOOL WINAPI ZombifyActCtx(HANDLE hActCtx)
207 FIXME("%p\n", hActCtx);
208 if (hActCtx != ACTCTX_FAKE_HANDLE)
209 return FALSE;
210 return TRUE;
213 /***********************************************************************
214 * FindActCtxSectionStringA (KERNEL32.@)
216 * Find information about a GUID in an activation context.
218 BOOL WINAPI FindActCtxSectionStringA(DWORD dwFlags, const GUID* lpExtGuid,
219 ULONG ulId, LPCSTR lpSearchStr,
220 PACTCTX_SECTION_KEYED_DATA pInfo)
222 FIXME("%08x %s %u %s %p\n", dwFlags, debugstr_guid(lpExtGuid),
223 ulId, debugstr_a(lpSearchStr), pInfo);
224 SetLastError( ERROR_CALL_NOT_IMPLEMENTED);
225 return FALSE;
228 /***********************************************************************
229 * FindActCtxSectionStringW (KERNEL32.@)
231 * Find information about a GUID in an activation context.
233 BOOL WINAPI FindActCtxSectionStringW(DWORD dwFlags, const GUID* lpExtGuid,
234 ULONG ulId, LPCWSTR lpSearchStr,
235 PACTCTX_SECTION_KEYED_DATA pInfo)
237 FIXME("%08x %s %u %s %p\n", dwFlags, debugstr_guid(lpExtGuid),
238 ulId, debugstr_w(lpSearchStr), pInfo);
240 if (lpExtGuid)
242 FIXME("expected lpExtGuid == NULL\n");
243 SetLastError(ERROR_INVALID_PARAMETER);
244 return FALSE;
247 if (dwFlags & ~FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX)
249 FIXME("unknown dwFlags %08x\n", dwFlags);
250 SetLastError(ERROR_INVALID_PARAMETER);
251 return FALSE;
254 if (!pInfo || pInfo->cbSize < sizeof (ACTCTX_SECTION_KEYED_DATA))
256 SetLastError(ERROR_INVALID_PARAMETER);
257 return FALSE;
260 pInfo->ulDataFormatVersion = 1;
261 pInfo->lpData = NULL;
262 pInfo->lpSectionGlobalData = NULL;
263 pInfo->ulSectionGlobalDataLength = 0;
264 pInfo->lpSectionBase = NULL;
265 pInfo->ulSectionTotalLength = 0;
266 pInfo->hActCtx = ACTCTX_FAKE_HANDLE;
267 pInfo->ulAssemblyRosterIndex = 0;
269 return TRUE;
272 /***********************************************************************
273 * FindActCtxSectionGuid (KERNEL32.@)
275 * Find information about a GUID in an activation context.
277 BOOL WINAPI FindActCtxSectionGuid(DWORD dwFlags, const GUID* lpExtGuid,
278 ULONG ulId, const GUID* lpSearchGuid,
279 PACTCTX_SECTION_KEYED_DATA pInfo)
281 FIXME("%08x %s %u %s %p\n", dwFlags, debugstr_guid(lpExtGuid),
282 ulId, debugstr_guid(lpSearchGuid), pInfo);
283 SetLastError( ERROR_CALL_NOT_IMPLEMENTED);
284 return FALSE;
287 /***********************************************************************
288 * QueryActCtxW (KERNEL32.@)
290 * Get information about an activation context.
292 BOOL WINAPI QueryActCtxW(DWORD dwFlags, HANDLE hActCtx, PVOID pvSubInst,
293 ULONG ulClass, PVOID pvBuff, SIZE_T cbBuff,
294 SIZE_T *pcbLen)
296 FIXME("%08x %p %p %u %p %ld %p\n", dwFlags, hActCtx,
297 pvSubInst, ulClass, pvBuff, cbBuff, pcbLen);
298 /* this makes Adobe Photoshop 7.0 happy */
299 SetLastError( ERROR_CALL_NOT_IMPLEMENTED);
300 return FALSE;