0

我正在尝试通过 Visual c++ 使用任务计划。我正在使用 Ctask.h(从这里)来完成任务。但是,当我构建解决方案(使用 Visual Studio 11)时,它说

fatal error C1189: #error :  Please use the /MD switch for _AFXDLL builds

当我切换到 /MD 时,它给出了这个错误

ConsoleApplication12.obj : error LNK2019: unresolved external symbol "public: __thiscall CTask::CTask(void)" (??0CTask@@QAE@XZ) referenced in function _wmain
1>ConsoleApplication12.obj : error LNK2019: unresolved external symbol "public: void __thiscall CTask::SetStartDateTime(class ATL::CTime const &)" (?SetStartDateTime@CTask@@QAEXABVCTime@ATL@@@Z) referenced in function _wmain
1>ConsoleApplication12.obj : error LNK2019: unresolved external symbol "public: void __thiscall CTask::SetFrequency(enum CTask::ETaskFrequency)" (?SetFrequency@CTask@@QAEXW4ETaskFrequency@1@@Z) referenced in function _wmain
1>ConsoleApplication12.obj : error LNK2019: unresolved external symbol "public: void __thiscall CTask::SetProgram(wchar_t const *)" (?SetProgram@CTask@@QAEXPB_W@Z) referenced in function _wmain
1>ConsoleApplication12.obj : error LNK2019: unresolved external symbol "public: void __thiscall CTask::SetAccountName(wchar_t const *)" (?SetAccountName@CTask@@QAEXPB_W@Z) referenced in function _wmain
1>ConsoleApplication12.obj : error LNK2019: unresolved external symbol "public: long __thiscall CTask::SaveTask(wchar_t const *,int)const " (?SaveTask@CTask@@QBEJPB_WH@Z) referenced in function _wmain
1>ConsoleApplication12.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall CTask::~CTask(void)" (??1CTask@@UAE@XZ) referenced in function _wmain

其他链接选项也是如此。这是我输入的代码:

#include "stdafx.h"
#include "CTask.h"
#include <iostream>
using namespace std;




int _tmain(int argc, _TCHAR* argv[])
{
    CTask task;
    CTime time(2013, 03, 15, 7, 11, 0);
    LPCTSTR sTaskName( L"Task Name" );

    BOOL replace = TRUE;

    task.SetProgram( L"E:\\aaa.txt" );
    task.SetAccountName( L"harshilsharma63" );
    task.SetStartDateTime( time );
    task.SetFrequency( CTask::freqOnce );

    if( S_OK == task.SaveTask( sTaskName, replace))
    {
        cout << "task successfully created!";
        return 0;
    }
    else
    {
        cout << "task creation failed!";
        return 1;
    }


    return 0;
}

我已经将“在共享 DLL 中使用 MFC”设置为“在共享 DLL 中使用 MFC”。

4

2 回答 2

2

我没有看到任何迹象表明您实际上已将 CTask.cpp 放入您的项目中。仅包含标头会导致您看到的链接器错误,您也需要 .cpp。

于 2013-03-15T15:55:38.950 回答
1

You need add to your project the CTask.cpp as well as CTask.h. The original project http://www.codeproject.com/Articles/13089/Harnessing-the-task-scheduler can be compiled without any trouble - I just checked it!

于 2013-03-15T15:59:18.697 回答