gdi32: Pre-allocate the points array in CreatePolyPolygonRgn.
[wine.git] / dlls / mstask / task.c
blob34d1fa010e162030e5669d8b933c4ea78fddb6f5
1 /*
2 * Copyright (C) 2008 Google (Roy Shea)
3 * Copyright (C) 2018 Dmitry Timoshkov
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <stdarg.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "objbase.h"
27 #include "taskschd.h"
28 #include "mstask.h"
29 #include "mstask_private.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(mstask);
34 typedef struct
36 ITask ITask_iface;
37 IPersistFile IPersistFile_iface;
38 LONG ref;
39 ITaskDefinition *task;
40 IExecAction *action;
41 LPWSTR task_name;
42 DWORD maxRunTime;
43 LPWSTR accountName;
44 } TaskImpl;
46 static inline TaskImpl *impl_from_ITask(ITask *iface)
48 return CONTAINING_RECORD(iface, TaskImpl, ITask_iface);
51 static inline TaskImpl *impl_from_IPersistFile( IPersistFile *iface )
53 return CONTAINING_RECORD(iface, TaskImpl, IPersistFile_iface);
56 static void TaskDestructor(TaskImpl *This)
58 TRACE("%p\n", This);
59 if (This->action)
60 IExecAction_Release(This->action);
61 ITaskDefinition_Release(This->task);
62 HeapFree(GetProcessHeap(), 0, This->task_name);
63 HeapFree(GetProcessHeap(), 0, This->accountName);
64 HeapFree(GetProcessHeap(), 0, This);
65 InterlockedDecrement(&dll_ref);
68 static HRESULT WINAPI MSTASK_ITask_QueryInterface(
69 ITask* iface,
70 REFIID riid,
71 void **ppvObject)
73 TaskImpl * This = impl_from_ITask(iface);
75 TRACE("IID: %s\n", debugstr_guid(riid));
76 if (ppvObject == NULL)
77 return E_POINTER;
79 if (IsEqualGUID(riid, &IID_IUnknown) ||
80 IsEqualGUID(riid, &IID_ITask))
82 *ppvObject = &This->ITask_iface;
83 ITask_AddRef(iface);
84 return S_OK;
86 else if (IsEqualGUID(riid, &IID_IPersistFile))
88 *ppvObject = &This->IPersistFile_iface;
89 ITask_AddRef(iface);
90 return S_OK;
93 WARN("Unknown interface: %s\n", debugstr_guid(riid));
94 *ppvObject = NULL;
95 return E_NOINTERFACE;
98 static ULONG WINAPI MSTASK_ITask_AddRef(
99 ITask* iface)
101 TaskImpl *This = impl_from_ITask(iface);
102 ULONG ref;
103 TRACE("\n");
104 ref = InterlockedIncrement(&This->ref);
105 return ref;
108 static ULONG WINAPI MSTASK_ITask_Release(
109 ITask* iface)
111 TaskImpl * This = impl_from_ITask(iface);
112 ULONG ref;
113 TRACE("\n");
114 ref = InterlockedDecrement(&This->ref);
115 if (ref == 0)
116 TaskDestructor(This);
117 return ref;
120 static HRESULT WINAPI MSTASK_ITask_CreateTrigger(
121 ITask* iface,
122 WORD *piNewTrigger,
123 ITaskTrigger **ppTrigger)
125 TRACE("(%p, %p, %p)\n", iface, piNewTrigger, ppTrigger);
126 return TaskTriggerConstructor((LPVOID *)ppTrigger);
129 static HRESULT WINAPI MSTASK_ITask_DeleteTrigger(
130 ITask* iface,
131 WORD iTrigger)
133 FIXME("(%p, %d): stub\n", iface, iTrigger);
134 return E_NOTIMPL;
137 static HRESULT WINAPI MSTASK_ITask_GetTriggerCount(
138 ITask* iface,
139 WORD *plCount)
141 FIXME("(%p, %p): stub\n", iface, plCount);
142 return E_NOTIMPL;
145 static HRESULT WINAPI MSTASK_ITask_GetTrigger(
146 ITask* iface,
147 WORD iTrigger,
148 ITaskTrigger **ppTrigger)
150 FIXME("(%p, %d, %p): stub\n", iface, iTrigger, ppTrigger);
151 return E_NOTIMPL;
154 static HRESULT WINAPI MSTASK_ITask_GetTriggerString(
155 ITask* iface,
156 WORD iTrigger,
157 LPWSTR *ppwszTrigger)
159 FIXME("(%p, %d, %p): stub\n", iface, iTrigger, ppwszTrigger);
160 return E_NOTIMPL;
163 static HRESULT WINAPI MSTASK_ITask_GetRunTimes(
164 ITask* iface,
165 const LPSYSTEMTIME pstBegin,
166 const LPSYSTEMTIME pstEnd,
167 WORD *pCount,
168 LPSYSTEMTIME *rgstTaskTimes)
170 FIXME("(%p, %p, %p, %p, %p): stub\n", iface, pstBegin, pstEnd, pCount,
171 rgstTaskTimes);
172 return E_NOTIMPL;
175 static HRESULT WINAPI MSTASK_ITask_GetNextRunTime(
176 ITask* iface,
177 SYSTEMTIME *pstNextRun)
179 FIXME("(%p, %p): stub\n", iface, pstNextRun);
180 return E_NOTIMPL;
183 static HRESULT WINAPI MSTASK_ITask_SetIdleWait(
184 ITask* iface,
185 WORD wIdleMinutes,
186 WORD wDeadlineMinutes)
188 FIXME("(%p, %d, %d): stub\n", iface, wIdleMinutes, wDeadlineMinutes);
189 return E_NOTIMPL;
192 static HRESULT WINAPI MSTASK_ITask_GetIdleWait(
193 ITask* iface,
194 WORD *pwIdleMinutes,
195 WORD *pwDeadlineMinutes)
197 FIXME("(%p, %p, %p): stub\n", iface, pwIdleMinutes, pwDeadlineMinutes);
198 return E_NOTIMPL;
201 static HRESULT WINAPI MSTASK_ITask_Run(
202 ITask* iface)
204 FIXME("(%p): stub\n", iface);
205 return E_NOTIMPL;
208 static HRESULT WINAPI MSTASK_ITask_Terminate(
209 ITask* iface)
211 FIXME("(%p): stub\n", iface);
212 return E_NOTIMPL;
215 static HRESULT WINAPI MSTASK_ITask_EditWorkItem(
216 ITask* iface,
217 HWND hParent,
218 DWORD dwReserved)
220 FIXME("(%p, %p, %d): stub\n", iface, hParent, dwReserved);
221 return E_NOTIMPL;
224 static HRESULT WINAPI MSTASK_ITask_GetMostRecentRunTime(
225 ITask* iface,
226 SYSTEMTIME *pstLastRun)
228 FIXME("(%p, %p): stub\n", iface, pstLastRun);
229 return E_NOTIMPL;
232 static HRESULT WINAPI MSTASK_ITask_GetStatus(
233 ITask* iface,
234 HRESULT *phrStatus)
236 FIXME("(%p, %p): stub\n", iface, phrStatus);
237 return E_NOTIMPL;
240 static HRESULT WINAPI MSTASK_ITask_GetExitCode(
241 ITask* iface,
242 DWORD *pdwExitCode)
244 FIXME("(%p, %p): stub\n", iface, pdwExitCode);
245 return E_NOTIMPL;
248 static HRESULT WINAPI MSTASK_ITask_SetComment(ITask *iface, LPCWSTR comment)
250 TaskImpl *This = impl_from_ITask(iface);
251 IRegistrationInfo *info;
252 HRESULT hr;
254 TRACE("(%p, %s)\n", iface, debugstr_w(comment));
256 if (!comment || !comment[0])
257 comment = NULL;
259 hr = ITaskDefinition_get_RegistrationInfo(This->task, &info);
260 if (hr == S_OK)
262 hr = IRegistrationInfo_put_Description(info, (BSTR)comment);
263 IRegistrationInfo_Release(info);
265 return hr;
268 static HRESULT WINAPI MSTASK_ITask_GetComment(ITask *iface, LPWSTR *comment)
270 TaskImpl *This = impl_from_ITask(iface);
271 IRegistrationInfo *info;
272 HRESULT hr;
273 BSTR description;
274 DWORD len;
276 TRACE("(%p, %p)\n", iface, comment);
278 hr = ITaskDefinition_get_RegistrationInfo(This->task, &info);
279 if (hr != S_OK) return hr;
281 hr = IRegistrationInfo_get_Description(info, &description);
282 if (hr == S_OK)
284 len = description ? lstrlenW(description) + 1 : 1;
285 *comment = CoTaskMemAlloc(len * sizeof(WCHAR));
286 if (*comment)
288 if (!description)
289 *comment[0] = 0;
290 else
291 lstrcpyW(*comment, description);
292 hr = S_OK;
294 else
295 hr = E_OUTOFMEMORY;
297 SysFreeString(description);
300 IRegistrationInfo_Release(info);
301 return hr;
304 static HRESULT WINAPI MSTASK_ITask_SetCreator(ITask *iface, LPCWSTR creator)
306 TaskImpl *This = impl_from_ITask(iface);
307 IRegistrationInfo *info;
308 HRESULT hr;
310 TRACE("(%p, %s)\n", iface, debugstr_w(creator));
312 if (!creator || !creator[0])
313 creator = NULL;
315 hr = ITaskDefinition_get_RegistrationInfo(This->task, &info);
316 if (hr == S_OK)
318 hr = IRegistrationInfo_put_Author(info, (BSTR)creator);
319 IRegistrationInfo_Release(info);
321 return hr;
324 static HRESULT WINAPI MSTASK_ITask_GetCreator(ITask *iface, LPWSTR *creator)
326 TaskImpl *This = impl_from_ITask(iface);
327 IRegistrationInfo *info;
328 HRESULT hr;
329 BSTR author;
330 DWORD len;
332 TRACE("(%p, %p)\n", iface, creator);
334 hr = ITaskDefinition_get_RegistrationInfo(This->task, &info);
335 if (hr != S_OK) return hr;
337 hr = IRegistrationInfo_get_Author(info, &author);
338 if (hr == S_OK)
340 len = author ? lstrlenW(author) + 1 : 1;
341 *creator = CoTaskMemAlloc(len * sizeof(WCHAR));
342 if (*creator)
344 if (!author)
345 *creator[0] = 0;
346 else
347 lstrcpyW(*creator, author);
348 hr = S_OK;
350 else
351 hr = E_OUTOFMEMORY;
353 SysFreeString(author);
356 IRegistrationInfo_Release(info);
357 return hr;
360 static HRESULT WINAPI MSTASK_ITask_SetWorkItemData(
361 ITask* iface,
362 WORD cBytes,
363 BYTE rgbData[])
365 FIXME("(%p, %d, %p): stub\n", iface, cBytes, rgbData);
366 return E_NOTIMPL;
369 static HRESULT WINAPI MSTASK_ITask_GetWorkItemData(
370 ITask* iface,
371 WORD *pcBytes,
372 BYTE **ppBytes)
374 FIXME("(%p, %p, %p): stub\n", iface, pcBytes, ppBytes);
375 return E_NOTIMPL;
378 static HRESULT WINAPI MSTASK_ITask_SetErrorRetryCount(
379 ITask* iface,
380 WORD wRetryCount)
382 FIXME("(%p, %d): stub\n", iface, wRetryCount);
383 return E_NOTIMPL;
386 static HRESULT WINAPI MSTASK_ITask_GetErrorRetryCount(
387 ITask* iface,
388 WORD *pwRetryCount)
390 FIXME("(%p, %p): stub\n", iface, pwRetryCount);
391 return E_NOTIMPL;
394 static HRESULT WINAPI MSTASK_ITask_SetErrorRetryInterval(
395 ITask* iface,
396 WORD wRetryInterval)
398 FIXME("(%p, %d): stub\n", iface, wRetryInterval);
399 return E_NOTIMPL;
402 static HRESULT WINAPI MSTASK_ITask_GetErrorRetryInterval(
403 ITask* iface,
404 WORD *pwRetryInterval)
406 FIXME("(%p, %p): stub\n", iface, pwRetryInterval);
407 return E_NOTIMPL;
410 static HRESULT WINAPI MSTASK_ITask_SetFlags(
411 ITask* iface,
412 DWORD dwFlags)
414 FIXME("(%p, 0x%08x): stub\n", iface, dwFlags);
415 return E_NOTIMPL;
418 static HRESULT WINAPI MSTASK_ITask_GetFlags(ITask *iface, DWORD *flags)
420 FIXME("(%p, %p): stub\n", iface, flags);
421 *flags = 0;
422 return S_OK;
425 static HRESULT WINAPI MSTASK_ITask_SetAccountInformation(
426 ITask* iface,
427 LPCWSTR pwszAccountName,
428 LPCWSTR pwszPassword)
430 DWORD n;
431 TaskImpl *This = impl_from_ITask(iface);
432 LPWSTR tmp_account_name;
434 TRACE("(%p, %s, %s): partial stub\n", iface, debugstr_w(pwszAccountName),
435 debugstr_w(pwszPassword));
437 if (pwszPassword)
438 FIXME("Partial stub ignores passwords\n");
440 n = (lstrlenW(pwszAccountName) + 1);
441 tmp_account_name = HeapAlloc(GetProcessHeap(), 0, n * sizeof(WCHAR));
442 if (!tmp_account_name)
443 return E_OUTOFMEMORY;
444 lstrcpyW(tmp_account_name, pwszAccountName);
445 HeapFree(GetProcessHeap(), 0, This->accountName);
446 This->accountName = tmp_account_name;
447 return S_OK;
450 static HRESULT WINAPI MSTASK_ITask_GetAccountInformation(
451 ITask* iface,
452 LPWSTR *ppwszAccountName)
454 DWORD n;
455 TaskImpl *This = impl_from_ITask(iface);
457 TRACE("(%p, %p): partial stub\n", iface, ppwszAccountName);
459 /* This implements the WinXP behavior when accountName has not yet
460 * set. Win2K behaves differently, returning SCHED_E_CANNOT_OPEN_TASK */
461 if (!This->accountName)
462 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
464 n = (lstrlenW(This->accountName) + 1);
465 *ppwszAccountName = CoTaskMemAlloc(n * sizeof(WCHAR));
466 if (!*ppwszAccountName)
467 return E_OUTOFMEMORY;
468 lstrcpyW(*ppwszAccountName, This->accountName);
469 return S_OK;
472 static HRESULT WINAPI MSTASK_ITask_SetApplicationName(ITask *iface, LPCWSTR appname)
474 TaskImpl *This = impl_from_ITask(iface);
475 DWORD len;
477 TRACE("(%p, %s)\n", iface, debugstr_w(appname));
479 /* Empty application name */
480 if (!appname || !appname[0])
481 return IExecAction_put_Path(This->action, NULL);
483 /* Attempt to set pwszApplicationName to a path resolved application name */
484 len = SearchPathW(NULL, appname, NULL, 0, NULL, NULL);
485 if (len)
487 LPWSTR tmp_name;
488 HRESULT hr;
490 tmp_name = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
491 if (!tmp_name)
492 return E_OUTOFMEMORY;
493 len = SearchPathW(NULL, appname, NULL, len, tmp_name, NULL);
494 if (len)
495 hr = IExecAction_put_Path(This->action, tmp_name);
496 else
497 hr = HRESULT_FROM_WIN32(GetLastError());
499 HeapFree(GetProcessHeap(), 0, tmp_name);
500 return hr;
503 /* If unable to path resolve name, simply set to appname */
504 return IExecAction_put_Path(This->action, (BSTR)appname);
507 static HRESULT WINAPI MSTASK_ITask_GetApplicationName(ITask *iface, LPWSTR *appname)
509 TaskImpl *This = impl_from_ITask(iface);
510 HRESULT hr;
511 BSTR path;
512 DWORD len;
514 TRACE("(%p, %p)\n", iface, appname);
516 hr = IExecAction_get_Path(This->action, &path);
517 if (hr != S_OK) return hr;
519 len = path ? lstrlenW(path) + 1 : 1;
520 *appname = CoTaskMemAlloc(len * sizeof(WCHAR));
521 if (*appname)
523 if (!path)
524 *appname[0] = 0;
525 else
526 lstrcpyW(*appname, path);
527 hr = S_OK;
529 else
530 hr = E_OUTOFMEMORY;
532 SysFreeString(path);
533 return hr;
536 static HRESULT WINAPI MSTASK_ITask_SetParameters(ITask *iface, LPCWSTR params)
538 TaskImpl *This = impl_from_ITask(iface);
540 TRACE("(%p, %s)\n", iface, debugstr_w(params));
542 /* Empty parameter list */
543 if (!params || !params[0])
544 params = NULL;
546 return IExecAction_put_Arguments(This->action, (BSTR)params);
549 static HRESULT WINAPI MSTASK_ITask_GetParameters(ITask *iface, LPWSTR *params)
551 TaskImpl *This = impl_from_ITask(iface);
552 HRESULT hr;
553 BSTR args;
554 DWORD len;
556 TRACE("(%p, %p)\n", iface, params);
558 hr = IExecAction_get_Arguments(This->action, &args);
559 if (hr != S_OK) return hr;
561 len = args ? lstrlenW(args) + 1 : 1;
562 *params = CoTaskMemAlloc(len * sizeof(WCHAR));
563 if (*params)
565 if (!args)
566 *params[0] = 0;
567 else
568 lstrcpyW(*params, args);
569 hr = S_OK;
571 else
572 hr = E_OUTOFMEMORY;
574 SysFreeString(args);
575 return hr;
578 static HRESULT WINAPI MSTASK_ITask_SetWorkingDirectory(ITask * iface, LPCWSTR workdir)
580 TaskImpl *This = impl_from_ITask(iface);
582 TRACE("(%p, %s)\n", iface, debugstr_w(workdir));
584 if (!workdir || !workdir[0])
585 workdir = NULL;
587 return IExecAction_put_WorkingDirectory(This->action, (BSTR)workdir);
590 static HRESULT WINAPI MSTASK_ITask_GetWorkingDirectory(ITask *iface, LPWSTR *workdir)
592 TaskImpl *This = impl_from_ITask(iface);
593 HRESULT hr;
594 BSTR dir;
595 DWORD len;
597 TRACE("(%p, %p)\n", iface, workdir);
599 hr = IExecAction_get_WorkingDirectory(This->action, &dir);
600 if (hr != S_OK) return hr;
602 len = dir ? lstrlenW(dir) + 1 : 1;
603 *workdir = CoTaskMemAlloc(len * sizeof(WCHAR));
604 if (*workdir)
606 if (!dir)
607 *workdir[0] = 0;
608 else
609 lstrcpyW(*workdir, dir);
610 hr = S_OK;
612 else
613 hr = E_OUTOFMEMORY;
615 SysFreeString(dir);
616 return hr;
619 static HRESULT WINAPI MSTASK_ITask_SetPriority(
620 ITask* iface,
621 DWORD dwPriority)
623 FIXME("(%p, 0x%08x): stub\n", iface, dwPriority);
624 return E_NOTIMPL;
627 static HRESULT WINAPI MSTASK_ITask_GetPriority(
628 ITask* iface,
629 DWORD *pdwPriority)
631 FIXME("(%p, %p): stub\n", iface, pdwPriority);
632 return E_NOTIMPL;
635 static HRESULT WINAPI MSTASK_ITask_SetTaskFlags(
636 ITask* iface,
637 DWORD dwFlags)
639 FIXME("(%p, 0x%08x): stub\n", iface, dwFlags);
640 return E_NOTIMPL;
643 static HRESULT WINAPI MSTASK_ITask_GetTaskFlags(ITask *iface, DWORD *flags)
645 FIXME("(%p, %p): stub\n", iface, flags);
646 *flags = 0;
647 return S_OK;
650 static HRESULT WINAPI MSTASK_ITask_SetMaxRunTime(
651 ITask* iface,
652 DWORD dwMaxRunTime)
654 TaskImpl *This = impl_from_ITask(iface);
656 TRACE("(%p, %d)\n", iface, dwMaxRunTime);
658 This->maxRunTime = dwMaxRunTime;
659 return S_OK;
662 static HRESULT WINAPI MSTASK_ITask_GetMaxRunTime(
663 ITask* iface,
664 DWORD *pdwMaxRunTime)
666 TaskImpl *This = impl_from_ITask(iface);
668 TRACE("(%p, %p)\n", iface, pdwMaxRunTime);
670 *pdwMaxRunTime = This->maxRunTime;
671 return S_OK;
674 static HRESULT WINAPI MSTASK_IPersistFile_QueryInterface(
675 IPersistFile* iface,
676 REFIID riid,
677 void **ppvObject)
679 TaskImpl *This = impl_from_IPersistFile(iface);
680 TRACE("(%p, %s, %p)\n", iface, debugstr_guid(riid), ppvObject);
681 return ITask_QueryInterface(&This->ITask_iface, riid, ppvObject);
684 static ULONG WINAPI MSTASK_IPersistFile_AddRef(
685 IPersistFile* iface)
687 TaskImpl *This = impl_from_IPersistFile(iface);
688 ULONG ref;
689 TRACE("\n");
690 ref = InterlockedIncrement(&This->ref);
691 return ref;
694 static ULONG WINAPI MSTASK_IPersistFile_Release(
695 IPersistFile* iface)
697 TaskImpl *This = impl_from_IPersistFile(iface);
698 ULONG ref;
699 TRACE("\n");
700 ref = InterlockedDecrement(&This->ref);
701 if (ref == 0)
702 TaskDestructor(This);
703 return ref;
706 static HRESULT WINAPI MSTASK_IPersistFile_GetClassID(
707 IPersistFile* iface,
708 CLSID *pClassID)
710 FIXME("(%p, %p): stub\n", iface, pClassID);
711 return E_NOTIMPL;
714 static HRESULT WINAPI MSTASK_IPersistFile_IsDirty(
715 IPersistFile* iface)
717 FIXME("(%p): stub\n", iface);
718 return E_NOTIMPL;
721 static HRESULT WINAPI MSTASK_IPersistFile_Load(
722 IPersistFile* iface,
723 LPCOLESTR pszFileName,
724 DWORD dwMode)
726 FIXME("(%p, %p, 0x%08x): stub\n", iface, pszFileName, dwMode);
727 return E_NOTIMPL;
730 static HRESULT WINAPI MSTASK_IPersistFile_Save(
731 IPersistFile* iface,
732 LPCOLESTR pszFileName,
733 BOOL fRemember)
735 FIXME("(%p, %p, %d): stub\n", iface, pszFileName, fRemember);
736 WARN("Returning S_OK but not writing to disk: %s %d\n",
737 debugstr_w(pszFileName), fRemember);
738 return S_OK;
741 static HRESULT WINAPI MSTASK_IPersistFile_SaveCompleted(
742 IPersistFile* iface,
743 LPCOLESTR pszFileName)
745 FIXME("(%p, %p): stub\n", iface, pszFileName);
746 return E_NOTIMPL;
749 static HRESULT WINAPI MSTASK_IPersistFile_GetCurFile(
750 IPersistFile* iface,
751 LPOLESTR *ppszFileName)
753 FIXME("(%p, %p): stub\n", iface, ppszFileName);
754 return E_NOTIMPL;
758 static const ITaskVtbl MSTASK_ITaskVtbl =
760 MSTASK_ITask_QueryInterface,
761 MSTASK_ITask_AddRef,
762 MSTASK_ITask_Release,
763 MSTASK_ITask_CreateTrigger,
764 MSTASK_ITask_DeleteTrigger,
765 MSTASK_ITask_GetTriggerCount,
766 MSTASK_ITask_GetTrigger,
767 MSTASK_ITask_GetTriggerString,
768 MSTASK_ITask_GetRunTimes,
769 MSTASK_ITask_GetNextRunTime,
770 MSTASK_ITask_SetIdleWait,
771 MSTASK_ITask_GetIdleWait,
772 MSTASK_ITask_Run,
773 MSTASK_ITask_Terminate,
774 MSTASK_ITask_EditWorkItem,
775 MSTASK_ITask_GetMostRecentRunTime,
776 MSTASK_ITask_GetStatus,
777 MSTASK_ITask_GetExitCode,
778 MSTASK_ITask_SetComment,
779 MSTASK_ITask_GetComment,
780 MSTASK_ITask_SetCreator,
781 MSTASK_ITask_GetCreator,
782 MSTASK_ITask_SetWorkItemData,
783 MSTASK_ITask_GetWorkItemData,
784 MSTASK_ITask_SetErrorRetryCount,
785 MSTASK_ITask_GetErrorRetryCount,
786 MSTASK_ITask_SetErrorRetryInterval,
787 MSTASK_ITask_GetErrorRetryInterval,
788 MSTASK_ITask_SetFlags,
789 MSTASK_ITask_GetFlags,
790 MSTASK_ITask_SetAccountInformation,
791 MSTASK_ITask_GetAccountInformation,
792 MSTASK_ITask_SetApplicationName,
793 MSTASK_ITask_GetApplicationName,
794 MSTASK_ITask_SetParameters,
795 MSTASK_ITask_GetParameters,
796 MSTASK_ITask_SetWorkingDirectory,
797 MSTASK_ITask_GetWorkingDirectory,
798 MSTASK_ITask_SetPriority,
799 MSTASK_ITask_GetPriority,
800 MSTASK_ITask_SetTaskFlags,
801 MSTASK_ITask_GetTaskFlags,
802 MSTASK_ITask_SetMaxRunTime,
803 MSTASK_ITask_GetMaxRunTime
806 static const IPersistFileVtbl MSTASK_IPersistFileVtbl =
808 MSTASK_IPersistFile_QueryInterface,
809 MSTASK_IPersistFile_AddRef,
810 MSTASK_IPersistFile_Release,
811 MSTASK_IPersistFile_GetClassID,
812 MSTASK_IPersistFile_IsDirty,
813 MSTASK_IPersistFile_Load,
814 MSTASK_IPersistFile_Save,
815 MSTASK_IPersistFile_SaveCompleted,
816 MSTASK_IPersistFile_GetCurFile
819 HRESULT TaskConstructor(ITaskService *service, const WCHAR *task_name, ITask **task)
821 TaskImpl *This;
822 ITaskDefinition *taskdef;
823 IActionCollection *actions;
824 HRESULT hr;
826 TRACE("(%s, %p)\n", debugstr_w(task_name), task);
828 hr = ITaskService_NewTask(service, 0, &taskdef);
829 if (hr != S_OK) return hr;
831 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
832 if (!This)
834 ITaskDefinition_Release(taskdef);
835 return E_OUTOFMEMORY;
838 This->ITask_iface.lpVtbl = &MSTASK_ITaskVtbl;
839 This->IPersistFile_iface.lpVtbl = &MSTASK_IPersistFileVtbl;
840 This->ref = 1;
841 This->task = taskdef;
842 This->task_name = heap_strdupW(task_name);
843 This->accountName = NULL;
845 /* Default time is 3 days = 259200000 ms */
846 This->maxRunTime = 259200000;
848 hr = ITaskDefinition_get_Actions(This->task, &actions);
849 if (hr == S_OK)
851 hr = IActionCollection_Create(actions, TASK_ACTION_EXEC, (IAction **)&This->action);
852 IActionCollection_Release(actions);
853 if (hr == S_OK)
855 *task = &This->ITask_iface;
856 InterlockedIncrement(&dll_ref);
857 return S_OK;
861 ITaskDefinition_Release(This->task);
862 ITask_Release(&This->ITask_iface);
863 return hr;