* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
+#ifdef __REACTOS__
+#include <wchar.h>
+#endif
+
#include "wshom_private.h"
+#include "wshom.h"
+
+#include "shellapi.h"
+#include "shlobj.h"
+#include "dispex.h"
-#include <shellapi.h>
-#include <shlobj.h>
-#include <dispex.h>
-#include <winreg.h>
+#include "wine/debug.h"
+#include "wine/heap.h"
-#include <wine/unicode.h>
+WINE_DEFAULT_DEBUG_CHANNEL(wshom);
typedef struct
{
if (!ref) {
CloseHandle(This->info.hThread);
CloseHandle(This->info.hProcess);
- HeapFree(GetProcessHeap(), 0, This);
+ heap_free(This);
}
return ref;
*ret = NULL;
- This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
+ This = heap_alloc(sizeof(*This));
if (!This)
return E_OUTOFMEMORY;
This->ref = 1;
if (!CreateProcessW(NULL, command, NULL, NULL, FALSE, 0, NULL, NULL, &si, &This->info)) {
- HeapFree(GetProcessHeap(), 0, This);
+ heap_free(This);
return HRESULT_FROM_WIN32(GetLastError());
}
TRACE("(%p) ref = %d\n", This, ref);
if (!ref)
- HeapFree(GetProcessHeap(), 0, This);
+ heap_free(This);
return ref;
}
return E_POINTER;
len = GetEnvironmentVariableW(name, NULL, 0);
- *value = SysAllocStringLen(NULL, len);
- if (!*value)
- return E_OUTOFMEMORY;
-
if (len)
- GetEnvironmentVariableW(name, *value, len+1);
+ {
+ *value = SysAllocStringLen(NULL, len - 1);
+ if (*value)
+ GetEnvironmentVariableW(name, *value, len);
+ }
+ else
+ *value = SysAllocStringLen(NULL, 0);
- return S_OK;
+ return *value ? S_OK : E_OUTOFMEMORY;
}
static HRESULT WINAPI WshEnvironment_put_Item(IWshEnvironment *iface, BSTR name, BSTR value)
{
WshEnvironment *This;
- This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
+ This = heap_alloc(sizeof(*This));
if (!This) return E_OUTOFMEMORY;
This->IWshEnvironment_iface.lpVtbl = &WshEnvironmentVtbl;
TRACE("(%p) ref = %d\n", This, ref);
if (!ref)
- HeapFree(GetProcessHeap(), 0, This);
+ heap_free(This);
return ref;
}
}
folder = V_BSTR(index);
- if (!strcmpiW(folder, desktopW))
+ if (!wcsicmp(folder, desktopW))
kind = CSIDL_DESKTOP;
- else if (!strcmpiW(folder, allusersdesktopW))
+ else if (!wcsicmp(folder, allusersdesktopW))
kind = CSIDL_COMMON_DESKTOPDIRECTORY;
- else if (!strcmpiW(folder, allusersprogramsW))
+ else if (!wcsicmp(folder, allusersprogramsW))
kind = CSIDL_COMMON_PROGRAMS;
else
{
return E_NOTIMPL;
}
-static HRESULT WINAPI WshCollection__NewEnum(IWshCollection *iface, IUnknown *Enum)
+static HRESULT WINAPI WshCollection__NewEnum(IWshCollection *iface, IUnknown **Enum)
{
WshCollection *This = impl_from_IWshCollection(iface);
FIXME("(%p)->(%p): stub\n", This, Enum);
{
WshCollection *This;
- This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
+ This = heap_alloc(sizeof(*This));
if (!This) return E_OUTOFMEMORY;
This->IWshCollection_iface.lpVtbl = &WshCollectionVtbl;
{
SysFreeString(This->path_link);
IShellLinkW_Release(This->link);
- HeapFree(GetProcessHeap(), 0, This);
+ heap_free(This);
}
return ref;
*Arguments = NULL;
- hr = IShellLinkW_GetArguments(This->link, buffW, sizeof(buffW)/sizeof(WCHAR));
+ hr = IShellLinkW_GetArguments(This->link, buffW, ARRAY_SIZE(buffW));
if (FAILED(hr))
return hr;
if (!IconPath)
return E_POINTER;
- hr = IShellLinkW_GetIconLocation(This->link, buffW, sizeof(buffW)/sizeof(WCHAR), &icon);
+ hr = IShellLinkW_GetIconLocation(This->link, buffW, ARRAY_SIZE(buffW), &icon);
if (FAILED(hr)) return hr;
- sprintfW(pathW, fmtW, buffW, icon);
+ swprintf(pathW, fmtW, buffW, icon);
*IconPath = SysAllocString(pathW);
if (!*IconPath) return E_OUTOFMEMORY;
TRACE("(%p)->(%s)\n", This, debugstr_w(IconPath));
/* scan for icon id */
- ptr = strrchrW(IconPath, ',');
+ ptr = wcsrchr(IconPath, ',');
if (!ptr)
{
WARN("icon index not found\n");
path = SysAllocStringLen(IconPath, ptr-IconPath);
/* skip spaces if any */
- while (isspaceW(*++ptr))
+ while (iswspace(*++ptr))
;
- icon = atoiW(ptr);
+ icon = wcstol(ptr, NULL, 10);
hr = IShellLinkW_SetIconLocation(This->link, path, icon);
SysFreeString(path);
return E_POINTER;
*WorkingDirectory = NULL;
- hr = IShellLinkW_GetWorkingDirectory(This->link, buffW, sizeof(buffW)/sizeof(WCHAR));
+ hr = IShellLinkW_GetWorkingDirectory(This->link, buffW, ARRAY_SIZE(buffW));
if (FAILED(hr)) return hr;
*WorkingDirectory = SysAllocString(buffW);
*shortcut = NULL;
- This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
+ This = heap_alloc(sizeof(*This));
if (!This) return E_OUTOFMEMORY;
This->IWshShortcut_iface.lpVtbl = &WshShortcutVtbl;
&IID_IShellLinkW, (void**)&This->link);
if (FAILED(hr))
{
- HeapFree(GetProcessHeap(), 0, This);
+ heap_free(This);
return hr;
}
if (!This->path_link)
{
IShellLinkW_Release(This->link);
- HeapFree(GetProcessHeap(), 0, This);
+ heap_free(This);
return E_OUTOFMEMORY;
}
return V_VT(arg) == VT_ERROR && V_ERROR(arg) == DISP_E_PARAMNOTFOUND;
}
+static WCHAR *split_command( BSTR cmd, WCHAR **params )
+{
+ WCHAR *ret, *ptr;
+ BOOL in_quotes = FALSE;
+
+ if (!(ret = heap_alloc((lstrlenW(cmd) + 1) * sizeof(WCHAR)))) return NULL;
+ lstrcpyW( ret, cmd );
+
+ *params = NULL;
+ for (ptr = ret; *ptr; ptr++)
+ {
+ if (*ptr == '"') in_quotes = !in_quotes;
+ else if (*ptr == ' ' && !in_quotes)
+ {
+ *ptr = 0;
+ *params = ptr + 1;
+ break;
+ }
+ }
+
+ return ret;
+}
+
static HRESULT WINAPI WshShell3_Run(IWshShell3 *iface, BSTR cmd, VARIANT *style, VARIANT *wait, DWORD *exit_code)
{
SHELLEXECUTEINFOW info;
int waitforprocess;
+ WCHAR *file, *params;
VARIANT s;
HRESULT hr;
+ BOOL ret;
TRACE("(%s %s %s %p)\n", debugstr_w(cmd), debugstr_variant(style), debugstr_variant(wait), exit_code);
waitforprocess = V_I4(&w);
}
+ if (!(file = split_command(cmd, ¶ms))) return E_OUTOFMEMORY;
+
memset(&info, 0, sizeof(info));
info.cbSize = sizeof(info);
info.fMask = waitforprocess ? SEE_MASK_NOASYNC | SEE_MASK_NOCLOSEPROCESS : SEE_MASK_DEFAULT;
- info.lpFile = cmd;
+ info.lpFile = file;
+ info.lpParameters = params;
info.nShow = V_I4(&s);
- if (!ShellExecuteExW(&info))
+ ret = ShellExecuteExW(&info);
+ heap_free( file );
+ if (!ret)
{
TRACE("ShellExecute failed, %d\n", GetLastError());
return HRESULT_FROM_WIN32(GetLastError());
{
if (waitforprocess)
{
+ WaitForSingleObject(info.hProcess, INFINITE);
GetExitCodeProcess(info.hProcess, exit_code);
CloseHandle(info.hProcess);
}
if (FAILED(hr))
return hr;
}
+#ifdef __REACTOS__
+ else
+ {
+ VariantChangeType(&timeout, &timeout, 0, VT_I4);
+ }
+#endif
VariantInit(¶m.type);
if (!is_optional_argument(type))
if (FAILED(hr))
return hr;
}
+#ifdef __REACTOS__
+ else
+ {
+ VariantChangeType(¶m.type, ¶m.type, 0, VT_I4);
+ }
+#endif
if (is_optional_argument(title))
param.title = *title;
};
int i;
- for (i = 0; i < sizeof(rootkeys)/sizeof(rootkeys[0]); i++) {
- if (!strncmpW(path, rootkeys[i].full, strlenW(rootkeys[i].full)))
+ for (i = 0; i < ARRAY_SIZE(rootkeys); i++) {
+ if (!wcsncmp(path, rootkeys[i].full, lstrlenW(rootkeys[i].full)))
return rootkeys[i].hkey;
- if (rootkeys[i].abbrev[0] && !strncmpW(path, rootkeys[i].abbrev, strlenW(rootkeys[i].abbrev)))
+ if (rootkeys[i].abbrev[0] && !wcsncmp(path, rootkeys[i].abbrev, lstrlenW(rootkeys[i].abbrev)))
return rootkeys[i].hkey;
}
*value = NULL;
/* at least one separator should be present */
- *subkey = strchrW(path, '\\');
+ *subkey = wcschr(path, '\\');
if (!*subkey)
return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
/* default value or not */
- if ((*subkey)[strlenW(*subkey)-1] == '\\') {
+ if ((*subkey)[lstrlenW(*subkey)-1] == '\\') {
(*subkey)++;
*value = NULL;
}
else {
- *value = strrchrW(*subkey, '\\');
+ *value = wcsrchr(*subkey, '\\');
if (*value - *subkey > 1) {
unsigned int len = *value - *subkey - 1;
WCHAR *ret;
- ret = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
+ ret = heap_alloc((len + 1)*sizeof(WCHAR));
if (!ret)
return E_OUTOFMEMORY;
if (ret == ERROR_SUCCESS) {
void *data;
- data = HeapAlloc(GetProcessHeap(), 0, datalen);
+ data = heap_alloc(datalen);
if (!data) {
hr = E_OUTOFMEMORY;
goto fail;
ret = RegGetValueW(root, subkey, val, RRF_RT_ANY, &type, data, &datalen);
if (ret) {
- HeapFree(GetProcessHeap(), 0, data);
+ heap_free(data);
hr = HRESULT_FROM_WIN32(ret);
goto fail;
}
bound.cElements = 0;
while (*ptr) {
bound.cElements++;
- ptr += strlenW(ptr)+1;
+ ptr += lstrlenW(ptr)+1;
}
sa = SafeArrayCreate(VT_VARIANT, 1, &bound);
while (*ptr) {
V_VT(v) = VT_BSTR;
V_BSTR(v) = SysAllocString(ptr);
- ptr += strlenW(ptr)+1;
+ ptr += lstrlenW(ptr)+1;
v++;
}
hr = E_FAIL;
};
- HeapFree(GetProcessHeap(), 0, data);
+ heap_free(data);
if (FAILED(hr))
VariantInit(value);
}
fail:
if (val)
- HeapFree(GetProcessHeap(), 0, subkey);
+ heap_free(subkey);
return hr;
}
if (V_VT(type) != VT_BSTR)
return E_INVALIDARG;
- if (!strcmpW(V_BSTR(type), regszW))
+ if (!wcscmp(V_BSTR(type), regszW))
regtype = REG_SZ;
- else if (!strcmpW(V_BSTR(type), regdwordW))
+ else if (!wcscmp(V_BSTR(type), regdwordW))
regtype = REG_DWORD;
- else if (!strcmpW(V_BSTR(type), regexpandszW))
+ else if (!wcscmp(V_BSTR(type), regexpandszW))
regtype = REG_EXPAND_SZ;
- else if (!strcmpW(V_BSTR(type), regbinaryW))
+ else if (!wcscmp(V_BSTR(type), regbinaryW))
regtype = REG_BINARY;
else {
FIXME("unrecognized value type %s\n", debugstr_w(V_BSTR(type)));
fail:
VariantClear(&v);
if (val)
- HeapFree(GetProcessHeap(), 0, subkey);
+ heap_free(subkey);
return hr;
}