task.c 19.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * Copyright (C) 2008 Google (Roy Shea)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include "mstask_private.h"
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(mstask);

24 25 26 27 28
static inline TaskImpl *impl_from_IPersistFile( IPersistFile *iface )
{
    return (TaskImpl*) ((char*)(iface) - FIELD_OFFSET(TaskImpl, persistVtbl));
}

29 30 31
static void TaskDestructor(TaskImpl *This)
{
    TRACE("%p\n", This);
32
    HeapFree(GetProcessHeap(), 0, This->accountName);
33
    HeapFree(GetProcessHeap(), 0, This->comment);
34
    HeapFree(GetProcessHeap(), 0, This->parameters);
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
    HeapFree(GetProcessHeap(), 0, This->taskName);
    HeapFree(GetProcessHeap(), 0, This);
    InterlockedDecrement(&dll_ref);
}

static HRESULT WINAPI MSTASK_ITask_QueryInterface(
        ITask* iface,
        REFIID riid,
        void **ppvObject)
{
    TaskImpl * This = (TaskImpl *)iface;

    TRACE("IID: %s\n", debugstr_guid(riid));
    if (ppvObject == NULL)
        return E_POINTER;

    if (IsEqualGUID(riid, &IID_IUnknown) ||
            IsEqualGUID(riid, &IID_ITask))
    {
        *ppvObject = &This->lpVtbl;
        ITask_AddRef(iface);
        return S_OK;
    }
58 59 60 61 62 63
    else if (IsEqualGUID(riid, &IID_IPersistFile))
    {
        *ppvObject = &This->persistVtbl;
        ITask_AddRef(iface);
        return S_OK;
    }
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96

    WARN("Unknown interface: %s\n", debugstr_guid(riid));
    *ppvObject = NULL;
    return E_NOINTERFACE;
}

static ULONG WINAPI MSTASK_ITask_AddRef(
        ITask* iface)
{
    TaskImpl *This = (TaskImpl *)iface;
    ULONG ref;
    TRACE("\n");
    ref = InterlockedIncrement(&This->ref);
    return ref;
}

static ULONG WINAPI MSTASK_ITask_Release(
        ITask* iface)
{
    TaskImpl * This = (TaskImpl *)iface;
    ULONG ref;
    TRACE("\n");
    ref = InterlockedDecrement(&This->ref);
    if (ref == 0)
        TaskDestructor(This);
    return ref;
}

static HRESULT WINAPI MSTASK_ITask_CreateTrigger(
        ITask* iface,
        WORD *piNewTrigger,
        ITaskTrigger **ppTrigger)
{
97 98
    TRACE("(%p, %p, %p)\n", iface, piNewTrigger, ppTrigger);
    return TaskTriggerConstructor((LPVOID *)ppTrigger);
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
}

static HRESULT WINAPI MSTASK_ITask_DeleteTrigger(
        ITask* iface,
        WORD iTrigger)
{
    FIXME("(%p, %d): stub\n", iface, iTrigger);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_GetTriggerCount(
        ITask* iface,
        WORD *plCount)
{
    FIXME("(%p, %p): stub\n", iface, plCount);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_GetTrigger(
        ITask* iface,
        WORD iTrigger,
        ITaskTrigger **ppTrigger)
{
    FIXME("(%p, %d, %p): stub\n", iface, iTrigger, ppTrigger);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_GetTriggerString(
        ITask* iface,
        WORD iTrigger,
        LPWSTR *ppwszTrigger)
{
    FIXME("(%p, %d, %p): stub\n", iface, iTrigger, ppwszTrigger);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_GetRunTimes(
        ITask* iface,
        const LPSYSTEMTIME pstBegin,
        const LPSYSTEMTIME pstEnd,
        WORD *pCount,
        LPSYSTEMTIME *rgstTaskTimes)
{
    FIXME("(%p, %p, %p, %p, %p): stub\n", iface, pstBegin, pstEnd, pCount,
            rgstTaskTimes);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_GetNextRunTime(
        ITask* iface,
        SYSTEMTIME *pstNextRun)
{
    FIXME("(%p, %p): stub\n", iface, pstNextRun);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_SetIdleWait(
        ITask* iface,
        WORD wIdleMinutes,
        WORD wDeadlineMinutes)
{
    FIXME("(%p, %d, %d): stub\n", iface, wIdleMinutes, wDeadlineMinutes);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_GetIdleWait(
        ITask* iface,
        WORD *pwIdleMinutes,
        WORD *pwDeadlineMinutes)
{
    FIXME("(%p, %p, %p): stub\n", iface, pwIdleMinutes, pwDeadlineMinutes);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_Run(
        ITask* iface)
{
    FIXME("(%p): stub\n", iface);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_Terminate(
        ITask* iface)
{
    FIXME("(%p): stub\n", iface);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_EditWorkItem(
        ITask* iface,
        HWND hParent,
        DWORD dwReserved)
{
    FIXME("(%p, %p, %d): stub\n", iface, hParent, dwReserved);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_GetMostRecentRunTime(
        ITask* iface,
        SYSTEMTIME *pstLastRun)
{
    FIXME("(%p, %p): stub\n", iface, pstLastRun);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_GetStatus(
        ITask* iface,
        HRESULT *phrStatus)
{
    FIXME("(%p, %p): stub\n", iface, phrStatus);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_GetExitCode(
        ITask* iface,
        DWORD *pdwExitCode)
{
    FIXME("(%p, %p): stub\n", iface, pdwExitCode);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_SetComment(
        ITask* iface,
        LPCWSTR pwszComment)
{
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
    DWORD n;
    TaskImpl *This = (TaskImpl *)iface;
    LPWSTR tmp_comment;

    TRACE("(%p, %s)\n", iface, debugstr_w(pwszComment));

    /* Empty comment */
    if (pwszComment[0] == 0)
    {
        HeapFree(GetProcessHeap(), 0, This->comment);
        This->comment = NULL;
        return S_OK;
    }

    /* Set to pwszComment */
    n = (lstrlenW(pwszComment) + 1);
    tmp_comment = HeapAlloc(GetProcessHeap(), 0, n * sizeof(WCHAR));
    if (!tmp_comment)
        return E_OUTOFMEMORY;
    lstrcpyW(tmp_comment, pwszComment);
    HeapFree(GetProcessHeap(), 0, This->comment);
    This->comment = tmp_comment;

    return S_OK;
248 249 250 251 252 253
}

static HRESULT WINAPI MSTASK_ITask_GetComment(
        ITask* iface,
        LPWSTR *ppwszComment)
{
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
    DWORD n;
    TaskImpl *This = (TaskImpl *)iface;

    TRACE("(%p, %p)\n", iface, ppwszComment);

    n = This->comment ? lstrlenW(This->comment) + 1 : 1;
    *ppwszComment = CoTaskMemAlloc(n * sizeof(WCHAR));
    if (!*ppwszComment)
        return E_OUTOFMEMORY;

    if (!This->comment)
        *ppwszComment[0] = 0;
    else
        lstrcpyW(*ppwszComment, This->comment);

    return S_OK;
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
}

static HRESULT WINAPI MSTASK_ITask_SetCreator(
        ITask* iface,
        LPCWSTR pwszCreator)
{
    FIXME("(%p, %p): stub\n", iface, pwszCreator);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_GetCreator(
        ITask* iface,
        LPWSTR *ppwszCreator)
{
    FIXME("(%p, %p): stub\n", iface, ppwszCreator);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_SetWorkItemData(
        ITask* iface,
        WORD cBytes,
        BYTE rgbData[])
{
    FIXME("(%p, %d, %p): stub\n", iface, cBytes, rgbData);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_GetWorkItemData(
        ITask* iface,
        WORD *pcBytes,
        BYTE **ppBytes)
{
    FIXME("(%p, %p, %p): stub\n", iface, pcBytes, ppBytes);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_SetErrorRetryCount(
        ITask* iface,
        WORD wRetryCount)
{
    FIXME("(%p, %d): stub\n", iface, wRetryCount);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_GetErrorRetryCount(
        ITask* iface,
        WORD *pwRetryCount)
{
    FIXME("(%p, %p): stub\n", iface, pwRetryCount);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_SetErrorRetryInterval(
        ITask* iface,
        WORD wRetryInterval)
{
    FIXME("(%p, %d): stub\n", iface, wRetryInterval);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_GetErrorRetryInterval(
        ITask* iface,
        WORD *pwRetryInterval)
{
    FIXME("(%p, %p): stub\n", iface, pwRetryInterval);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_SetFlags(
        ITask* iface,
        DWORD dwFlags)
{
    FIXME("(%p, 0x%08x): stub\n", iface, dwFlags);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_GetFlags(
        ITask* iface,
        DWORD *pdwFlags)
{
    FIXME("(%p, %p): stub\n", iface, pdwFlags);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_SetAccountInformation(
        ITask* iface,
        LPCWSTR pwszAccountName,
        LPCWSTR pwszPassword)
{
359 360 361 362 363
    DWORD n;
    TaskImpl *This = (TaskImpl *)iface;
    LPWSTR tmp_account_name;

    TRACE("(%p, %s, %s): partial stub\n", iface, debugstr_w(pwszAccountName),
364
            debugstr_w(pwszPassword));
365 366 367 368 369 370 371 372 373 374 375 376

    if (pwszPassword)
        FIXME("Partial stub ignores passwords\n");

    n = (lstrlenW(pwszAccountName) + 1);
    tmp_account_name = HeapAlloc(GetProcessHeap(), 0, n * sizeof(WCHAR));
    if (!tmp_account_name)
        return E_OUTOFMEMORY;
    lstrcpyW(tmp_account_name, pwszAccountName);
    HeapFree(GetProcessHeap(), 0, This->accountName);
    This->accountName = tmp_account_name;
    return S_OK;
377 378 379 380 381 382
}

static HRESULT WINAPI MSTASK_ITask_GetAccountInformation(
        ITask* iface,
        LPWSTR *ppwszAccountName)
{
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
    DWORD n;
    TaskImpl *This = (TaskImpl *)iface;

    TRACE("(%p, %p): partial stub\n", iface, ppwszAccountName);

    /* This implements the WinXP behavior when accountName has not yet
     * set.  Win2K behaves differently, returning SCHED_E_CANNOT_OPEN_TASK */
    if (!This->accountName)
        return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);

    n = (lstrlenW(This->accountName) + 1);
    *ppwszAccountName = CoTaskMemAlloc(n * sizeof(WCHAR));
    if (!*ppwszAccountName)
        return E_OUTOFMEMORY;
    lstrcpyW(*ppwszAccountName, This->accountName);
    return S_OK;
399 400 401 402 403 404
}

static HRESULT WINAPI MSTASK_ITask_SetApplicationName(
        ITask* iface,
        LPCWSTR pwszApplicationName)
{
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
    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;
446 447 448 449 450 451
}

static HRESULT WINAPI MSTASK_ITask_GetApplicationName(
        ITask* iface,
        LPWSTR *ppwszApplicationName)
{
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
    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;
468 469 470 471 472 473
}

static HRESULT WINAPI MSTASK_ITask_SetParameters(
        ITask* iface,
        LPCWSTR pwszParameters)
{
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
    DWORD n;
    TaskImpl *This = (TaskImpl *)iface;
    LPWSTR tmp_parameters;

    TRACE("(%p, %s)\n", iface, debugstr_w(pwszParameters));

    /* Empty parameter list */
    if (pwszParameters[0] == 0)
    {
        HeapFree(GetProcessHeap(), 0, This->parameters);
        This->parameters = NULL;
        return S_OK;
    }

    /* Set to pwszParameters */
    n = (lstrlenW(pwszParameters) + 1);
    tmp_parameters = HeapAlloc(GetProcessHeap(), 0, n * sizeof(WCHAR));
    if (!tmp_parameters)
        return E_OUTOFMEMORY;
    lstrcpyW(tmp_parameters, pwszParameters);
    HeapFree(GetProcessHeap(), 0, This->parameters);
    This->parameters = tmp_parameters;
    return S_OK;
497 498 499 500 501 502
}

static HRESULT WINAPI MSTASK_ITask_GetParameters(
        ITask* iface,
        LPWSTR *ppwszParameters)
{
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
    DWORD n;
    TaskImpl *This = (TaskImpl *)iface;

    TRACE("(%p, %p)\n", iface, ppwszParameters);

    n = This->parameters ? lstrlenW(This->parameters) + 1 : 1;
    *ppwszParameters = CoTaskMemAlloc(n * sizeof(WCHAR));
    if (!*ppwszParameters)
        return E_OUTOFMEMORY;

    if (!This->parameters)
        *ppwszParameters[0] = 0;
    else
        lstrcpyW(*ppwszParameters, This->parameters);

    return S_OK;
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
}

static HRESULT WINAPI MSTASK_ITask_SetWorkingDirectory(
        ITask* iface,
        LPCWSTR pwszWorkingDirectory)
{
    FIXME("(%p, %s): stub\n", iface, debugstr_w(pwszWorkingDirectory));
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_GetWorkingDirectory(
        ITask* iface,
        LPWSTR *ppwszWorkingDirectory)
{
    FIXME("(%p, %p): stub\n", iface, ppwszWorkingDirectory);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_SetPriority(
        ITask* iface,
        DWORD dwPriority)
{
    FIXME("(%p, 0x%08x): stub\n", iface, dwPriority);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_GetPriority(
        ITask* iface,
        DWORD *pdwPriority)
{
    FIXME("(%p, %p): stub\n", iface, pdwPriority);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_SetTaskFlags(
        ITask* iface,
        DWORD dwFlags)
{
    FIXME("(%p, 0x%08x): stub\n", iface, dwFlags);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_GetTaskFlags(
        ITask* iface,
        DWORD *pdwFlags)
{
    FIXME("(%p, %p): stub\n", iface, pdwFlags);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_ITask_SetMaxRunTime(
        ITask* iface,
        DWORD dwMaxRunTime)
{
573 574 575 576 577 578
    TaskImpl *This = (TaskImpl *)iface;

    TRACE("(%p, %d)\n", iface, dwMaxRunTime);

    This->maxRunTime = dwMaxRunTime;
    return S_OK;
579 580 581 582 583 584
}

static HRESULT WINAPI MSTASK_ITask_GetMaxRunTime(
        ITask* iface,
        DWORD *pdwMaxRunTime)
{
585 586 587 588 589 590
    TaskImpl *This = (TaskImpl *)iface;

    TRACE("(%p, %p)\n", iface, pdwMaxRunTime);

    *pdwMaxRunTime = This->maxRunTime;
    return S_OK;
591 592 593 594 595 596 597
}

static HRESULT WINAPI MSTASK_IPersistFile_QueryInterface(
        IPersistFile* iface,
        REFIID riid,
        void **ppvObject)
{
598 599 600
    TaskImpl *This = impl_from_IPersistFile(iface);
    TRACE("(%p, %s, %p)\n", iface, debugstr_guid(riid), ppvObject);
    return ITask_QueryInterface((ITask *) This, riid, ppvObject);
601 602 603 604 605
}

static ULONG WINAPI MSTASK_IPersistFile_AddRef(
        IPersistFile* iface)
{
606 607 608 609 610
    TaskImpl *This = impl_from_IPersistFile(iface);
    ULONG ref;
    TRACE("\n");
    ref = InterlockedIncrement(&This->ref);
    return ref;
611 612 613 614 615
}

static ULONG WINAPI MSTASK_IPersistFile_Release(
        IPersistFile* iface)
{
616 617 618 619 620 621 622
    TaskImpl *This = impl_from_IPersistFile(iface);
    ULONG ref;
    TRACE("\n");
    ref = InterlockedDecrement(&This->ref);
    if (ref == 0)
        TaskDestructor(This);
    return ref;
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654
}

static HRESULT WINAPI MSTASK_IPersistFile_GetClassID(
        IPersistFile* iface,
        CLSID *pClassID)
{
    FIXME("(%p, %p): stub\n", iface, pClassID);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_IPersistFile_IsDirty(
        IPersistFile* iface)
{
    FIXME("(%p): stub\n", iface);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_IPersistFile_Load(
        IPersistFile* iface,
        LPCOLESTR pszFileName,
        DWORD dwMode)
{
    FIXME("(%p, %p, 0x%08x): stub\n", iface, pszFileName, dwMode);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_IPersistFile_Save(
        IPersistFile* iface,
        LPCOLESTR pszFileName,
        BOOL fRemember)
{
    FIXME("(%p, %p, %d): stub\n", iface, pszFileName, fRemember);
655 656 657
    WARN("Returning S_OK but not writing to disk: %s %d\n",
            debugstr_w(pszFileName), fRemember);
    return S_OK;
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759
}

static HRESULT WINAPI MSTASK_IPersistFile_SaveCompleted(
        IPersistFile* iface,
        LPCOLESTR pszFileName)
{
    FIXME("(%p, %p): stub\n", iface, pszFileName);
    return E_NOTIMPL;
}

static HRESULT WINAPI MSTASK_IPersistFile_GetCurFile(
        IPersistFile* iface,
        LPOLESTR *ppszFileName)
{
    FIXME("(%p, %p): stub\n", iface, ppszFileName);
    return E_NOTIMPL;
}


static const ITaskVtbl MSTASK_ITaskVtbl =
{
    MSTASK_ITask_QueryInterface,
    MSTASK_ITask_AddRef,
    MSTASK_ITask_Release,
    MSTASK_ITask_CreateTrigger,
    MSTASK_ITask_DeleteTrigger,
    MSTASK_ITask_GetTriggerCount,
    MSTASK_ITask_GetTrigger,
    MSTASK_ITask_GetTriggerString,
    MSTASK_ITask_GetRunTimes,
    MSTASK_ITask_GetNextRunTime,
    MSTASK_ITask_SetIdleWait,
    MSTASK_ITask_GetIdleWait,
    MSTASK_ITask_Run,
    MSTASK_ITask_Terminate,
    MSTASK_ITask_EditWorkItem,
    MSTASK_ITask_GetMostRecentRunTime,
    MSTASK_ITask_GetStatus,
    MSTASK_ITask_GetExitCode,
    MSTASK_ITask_SetComment,
    MSTASK_ITask_GetComment,
    MSTASK_ITask_SetCreator,
    MSTASK_ITask_GetCreator,
    MSTASK_ITask_SetWorkItemData,
    MSTASK_ITask_GetWorkItemData,
    MSTASK_ITask_SetErrorRetryCount,
    MSTASK_ITask_GetErrorRetryCount,
    MSTASK_ITask_SetErrorRetryInterval,
    MSTASK_ITask_GetErrorRetryInterval,
    MSTASK_ITask_SetFlags,
    MSTASK_ITask_GetFlags,
    MSTASK_ITask_SetAccountInformation,
    MSTASK_ITask_GetAccountInformation,
    MSTASK_ITask_SetApplicationName,
    MSTASK_ITask_GetApplicationName,
    MSTASK_ITask_SetParameters,
    MSTASK_ITask_GetParameters,
    MSTASK_ITask_SetWorkingDirectory,
    MSTASK_ITask_GetWorkingDirectory,
    MSTASK_ITask_SetPriority,
    MSTASK_ITask_GetPriority,
    MSTASK_ITask_SetTaskFlags,
    MSTASK_ITask_GetTaskFlags,
    MSTASK_ITask_SetMaxRunTime,
    MSTASK_ITask_GetMaxRunTime
};

static const IPersistFileVtbl MSTASK_IPersistFileVtbl =
{
    MSTASK_IPersistFile_QueryInterface,
    MSTASK_IPersistFile_AddRef,
    MSTASK_IPersistFile_Release,
    MSTASK_IPersistFile_GetClassID,
    MSTASK_IPersistFile_IsDirty,
    MSTASK_IPersistFile_Load,
    MSTASK_IPersistFile_Save,
    MSTASK_IPersistFile_SaveCompleted,
    MSTASK_IPersistFile_GetCurFile
};

HRESULT TaskConstructor(LPCWSTR pwszTaskName, LPVOID *ppObj)
{
    TaskImpl *This;
    int n;

    TRACE("(%s, %p)\n", debugstr_w(pwszTaskName), ppObj);

    This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
    if (!This)
        return E_OUTOFMEMORY;

    This->lpVtbl = &MSTASK_ITaskVtbl;
    This->persistVtbl = &MSTASK_IPersistFileVtbl;
    This->ref = 1;
    n = (lstrlenW(pwszTaskName) + 1) * sizeof(WCHAR);
    This->taskName = HeapAlloc(GetProcessHeap(), 0, n);
    if (!This->taskName)
    {
        HeapFree(GetProcessHeap(), 0, This);
        return E_OUTOFMEMORY;
    }
    lstrcpyW(This->taskName, pwszTaskName);
760
    This->applicationName = NULL;
761
    This->parameters = NULL;
762
    This->comment = NULL;
763
    This->accountName = NULL;
764

765 766 767
    /* Default time is 3 days = 259200000 ms */
    This->maxRunTime = 259200000;

768 769 770 771
    *ppObj = &This->lpVtbl;
    InterlockedIncrement(&dll_ref);
    return S_OK;
}