diff --git a/dlls/mstask/Makefile.in b/dlls/mstask/Makefile.in index 9fb78ee339f..31d2eca92a1 100644 --- a/dlls/mstask/Makefile.in +++ b/dlls/mstask/Makefile.in @@ -3,7 +3,7 @@ TOPOBJDIR = ../.. SRCDIR = @srcdir@ VPATH = @srcdir@ MODULE = mstask.dll -IMPORTS = uuid kernel32 +IMPORTS = uuid ole32 kernel32 C_SRCS = \ factory.c \ diff --git a/dlls/mstask/mstask_private.h b/dlls/mstask/mstask_private.h index e5de0dcb5f0..b0892fe91d1 100644 --- a/dlls/mstask/mstask_private.h +++ b/dlls/mstask/mstask_private.h @@ -58,6 +58,7 @@ typedef struct const IPersistFileVtbl *persistVtbl; LONG ref; LPWSTR taskName; + LPWSTR applicationName; } TaskImpl; extern HRESULT TaskConstructor(LPCWSTR pwszTaskName, LPVOID *ppObj); diff --git a/dlls/mstask/task.c b/dlls/mstask/task.c index 8a24b872f3f..f1f542638bd 100644 --- a/dlls/mstask/task.c +++ b/dlls/mstask/task.c @@ -323,16 +323,69 @@ static HRESULT WINAPI MSTASK_ITask_SetApplicationName( ITask* iface, LPCWSTR pwszApplicationName) { - FIXME("(%p, %s): stub\n", iface, debugstr_w(pwszApplicationName)); - return E_NOTIMPL; + DWORD n; + TaskImpl *This = (TaskImpl *)iface; + LPWSTR tmp_name; + + TRACE("(%p, %s)\n", iface, debugstr_w(pwszApplicationName)); + + /* Empty application name */ + if (pwszApplicationName[0] == 0) + { + HeapFree(GetProcessHeap(), 0, This->applicationName); + This->applicationName = NULL; + return S_OK; + } + + /* Attempt to set pwszApplicationName to a path resolved application name */ + n = SearchPathW(NULL, pwszApplicationName, NULL, 0, NULL, NULL); + if (n) + { + tmp_name = HeapAlloc(GetProcessHeap(), 0, n * sizeof(WCHAR)); + if (!tmp_name) + return E_OUTOFMEMORY; + n = SearchPathW(NULL, pwszApplicationName, NULL, n, tmp_name, NULL); + if (n) + { + HeapFree(GetProcessHeap(), 0, This->applicationName); + This->applicationName = tmp_name; + return S_OK; + } + else + HeapFree(GetProcessHeap(), 0, tmp_name); + } + + /* If unable to path resolve name, simply set to pwszApplicationName */ + n = (lstrlenW(pwszApplicationName) + 1); + tmp_name = HeapAlloc(GetProcessHeap(), 0, n * sizeof(WCHAR)); + if (!tmp_name) + return E_OUTOFMEMORY; + lstrcpyW(tmp_name, pwszApplicationName); + HeapFree(GetProcessHeap(), 0, This->applicationName); + This->applicationName = tmp_name; + return S_OK; } static HRESULT WINAPI MSTASK_ITask_GetApplicationName( ITask* iface, LPWSTR *ppwszApplicationName) { - FIXME("(%p, %p): stub\n", iface, ppwszApplicationName); - return E_NOTIMPL; + DWORD n; + TaskImpl *This = (TaskImpl *)iface; + + TRACE("(%p, %p)\n", iface, ppwszApplicationName); + + n = This->applicationName ? lstrlenW(This->applicationName) + 1 : 1; + *ppwszApplicationName = CoTaskMemAlloc(n * sizeof(WCHAR)); + if (!*ppwszApplicationName) + return E_OUTOFMEMORY; + + if (!This->applicationName) + *ppwszApplicationName[0] = 0; + else + lstrcpyW(*ppwszApplicationName, This->applicationName); + + return S_OK; } static HRESULT WINAPI MSTASK_ITask_SetParameters( @@ -571,6 +624,7 @@ HRESULT TaskConstructor(LPCWSTR pwszTaskName, LPVOID *ppObj) return E_OUTOFMEMORY; } lstrcpyW(This->taskName, pwszTaskName); + This->applicationName = NULL; *ppObj = &This->lpVtbl; InterlockedIncrement(&dll_ref); diff --git a/dlls/mstask/tests/task.c b/dlls/mstask/tests/task.c index 7e9e831e1f7..ff35f52ed72 100644 --- a/dlls/mstask/tests/task.c +++ b/dlls/mstask/tests/task.c @@ -118,10 +118,10 @@ static void test_SetApplicationName_GetApplicationName(void) /* Attempt getting before setting application name */ hres = ITask_GetApplicationName(test_task, &stored_name); - todo_wine ok(hres == S_OK, "GetApplicationName failed: %08x\n", hres); + ok(hres == S_OK, "GetApplicationName failed: %08x\n", hres); if (hres == S_OK) { - todo_wine ok(!lstrcmpW(stored_name, empty), + ok(!lstrcmpW(stored_name, empty), "Got %s, expected empty string\n", dbgstr_w(stored_name)); CoTaskMemFree(stored_name); } @@ -129,14 +129,14 @@ static void test_SetApplicationName_GetApplicationName(void) /* Set application name to a non-existent application and then get * the application name that is actually stored */ hres = ITask_SetApplicationName(test_task, non_application_name); - todo_wine ok(hres == S_OK, "Failed setting name %s: %08x\n", + ok(hres == S_OK, "Failed setting name %s: %08x\n", dbgstr_w(non_application_name), hres); hres = ITask_GetApplicationName(test_task, &stored_name); - todo_wine ok(hres == S_OK, "GetApplicationName failed: %08x\n", hres); + ok(hres == S_OK, "GetApplicationName failed: %08x\n", hres); if (hres == S_OK) { full_name = path_resolve_name(non_application_name); - todo_wine ok(!lstrcmpW(stored_name, full_name), "Got %s, expected %s\n", + ok(!lstrcmpW(stored_name, full_name), "Got %s, expected %s\n", dbgstr_w(stored_name), dbgstr_w(full_name)); CoTaskMemFree(stored_name); } @@ -144,14 +144,14 @@ static void test_SetApplicationName_GetApplicationName(void) /* Set a valid application name with program type extension and then * get the stored name */ hres = ITask_SetApplicationName(test_task, notepad_exe); - todo_wine ok(hres == S_OK, "Failed setting name %s: %08x\n", + ok(hres == S_OK, "Failed setting name %s: %08x\n", dbgstr_w(notepad_exe), hres); hres = ITask_GetApplicationName(test_task, &stored_name); - todo_wine ok(hres == S_OK, "GetApplicationName failed: %08x\n", hres); + ok(hres == S_OK, "GetApplicationName failed: %08x\n", hres); if (hres == S_OK) { full_name = path_resolve_name(notepad_exe); - todo_wine ok(!lstrcmpW(stored_name, full_name), "Got %s, expected %s\n", + ok(!lstrcmpW(stored_name, full_name), "Got %s, expected %s\n", dbgstr_w(stored_name), dbgstr_w(full_name)); CoTaskMemFree(stored_name); } @@ -159,13 +159,13 @@ static void test_SetApplicationName_GetApplicationName(void) /* Set a valid application name without program type extension and * then get the stored name */ hres = ITask_SetApplicationName(test_task, notepad); - todo_wine ok(hres == S_OK, "Failed setting name %s: %08x\n", dbgstr_w(notepad), hres); + ok(hres == S_OK, "Failed setting name %s: %08x\n", dbgstr_w(notepad), hres); hres = ITask_GetApplicationName(test_task, &stored_name); - todo_wine ok(hres == S_OK, "GetApplicationName failed: %08x\n", hres); + ok(hres == S_OK, "GetApplicationName failed: %08x\n", hres); if (hres == S_OK) { full_name = path_resolve_name(notepad); - todo_wine ok(!lstrcmpW(stored_name, full_name), "Got %s, expected %s\n", + ok(!lstrcmpW(stored_name, full_name), "Got %s, expected %s\n", dbgstr_w(stored_name), dbgstr_w(full_name)); CoTaskMemFree(stored_name); } @@ -174,26 +174,26 @@ static void test_SetApplicationName_GetApplicationName(void) * to a non-existant application and then get the name that is * actually stored */ hres = ITask_SetApplicationName(test_task, non_application_name); - todo_wine ok(hres == S_OK, "Failed setting name %s: %08x\n", + ok(hres == S_OK, "Failed setting name %s: %08x\n", dbgstr_w(non_application_name), hres); hres = ITask_GetApplicationName(test_task, &stored_name); - todo_wine ok(hres == S_OK, "GetApplicationName failed: %08x\n", hres); + ok(hres == S_OK, "GetApplicationName failed: %08x\n", hres); if (hres == S_OK) { full_name = path_resolve_name(non_application_name); - todo_wine ok(!lstrcmpW(stored_name, full_name), "Got %s, expected %s\n", + ok(!lstrcmpW(stored_name, full_name), "Got %s, expected %s\n", dbgstr_w(stored_name), dbgstr_w(full_name)); CoTaskMemFree(stored_name); } /* Clear application name */ hres = ITask_SetApplicationName(test_task, empty); - todo_wine ok(hres == S_OK, "Failed setting name %s: %08x\n", dbgstr_w(empty), hres); + ok(hres == S_OK, "Failed setting name %s: %08x\n", dbgstr_w(empty), hres); hres = ITask_GetApplicationName(test_task, &stored_name); - todo_wine ok(hres == S_OK, "GetApplicationName failed: %08x\n", hres); + ok(hres == S_OK, "GetApplicationName failed: %08x\n", hres); if (hres == S_OK) { - todo_wine ok(!lstrcmpW(stored_name, empty), + ok(!lstrcmpW(stored_name, empty), "Got %s, expected empty string\n", dbgstr_w(stored_name)); CoTaskMemFree(stored_name); }