我正在尝试通过 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”。