2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: dll/win32/kernel32/wine/actctx.c
5 * PURPOSE: Activation contexts
6 * PROGRAMMERS: Jacek Caban for CodeWeavers
9 * Dmitry Chapyshev (dmitry@reactos.org)
13 /* Partly synched with Wine 1.7.17 */
19 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(0, (PVOID
)pActCtx
, 0, NULL
, NULL
, &hActCtx
)))
113 SetLastError(RtlNtStatusToDosError(status
));
114 return INVALID_HANDLE_VALUE
;
119 /***********************************************************************
120 * FindActCtxSectionStringA (KERNEL32.@)
122 * Find information about a string in an activation context.
124 BOOL WINAPI
FindActCtxSectionStringA(DWORD dwFlags
, const GUID
* lpExtGuid
,
125 ULONG ulId
, LPCSTR lpSearchStr
,
126 PACTCTX_SECTION_KEYED_DATA pInfo
)
132 TRACE("%08x %s %u %s %p\n", dwFlags
, debugstr_guid(lpExtGuid
),
133 ulId
, debugstr_a(lpSearchStr
), pInfo
);
137 SetLastError(ERROR_INVALID_PARAMETER
);
141 len
= MultiByteToWideChar(CP_ACP
, 0, lpSearchStr
, -1, NULL
, 0);
142 search_str
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
143 MultiByteToWideChar(CP_ACP
, 0, lpSearchStr
, -1, search_str
, len
);
145 ret
= FindActCtxSectionStringW(dwFlags
, lpExtGuid
, ulId
, search_str
, pInfo
);
147 HeapFree(GetProcessHeap(), 0, search_str
);
151 /***********************************************************************
152 * FindActCtxSectionStringW (KERNEL32.@)
154 * Find information about a string in an activation context.
156 BOOL WINAPI
FindActCtxSectionStringW(DWORD dwFlags
, const GUID
* lpExtGuid
,
157 ULONG ulId
, LPCWSTR lpSearchStr
,
158 PACTCTX_SECTION_KEYED_DATA pInfo
)
163 RtlInitUnicodeString(&us
, lpSearchStr
);
164 if ((status
= RtlFindActivationContextSectionString(dwFlags
, lpExtGuid
, ulId
, &us
, pInfo
)))
166 SetLastError(RtlNtStatusToDosError(status
));
172 /***********************************************************************
173 * FindActCtxSectionGuid (KERNEL32.@)
175 * Find information about a GUID in an activation context.
177 BOOL WINAPI
FindActCtxSectionGuid(DWORD dwFlags
, const GUID
* lpExtGuid
,
178 ULONG ulId
, const GUID
* lpSearchGuid
,
179 PACTCTX_SECTION_KEYED_DATA pInfo
)
183 if ((status
= RtlFindActivationContextSectionGuid(dwFlags
, lpExtGuid
, ulId
, lpSearchGuid
, pInfo
)))
185 SetLastError(RtlNtStatusToDosError(status
));