本文整理汇总了C++中ITask::QueryInterface方法的典型用法代码示例。如果您正苦于以下问题:C++ ITask::QueryInterface方法的具体用法?C++ ITask::QueryInterface怎么用?C++ ITask::QueryInterface使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITask
的用法示例。
在下文中一共展示了ITask::QueryInterface方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SaveTask
//.........这里部分代码省略.........
// Try to delete the existing task. If the delete succeeds, then
// we proceed. Otherwise, we'll bail out with an error.
TRACE0("CScheduledTask::SaveTask() - A task with the given name already exists; deleting it.\n");
hr = CScheduledTask::DeleteTask ( szTaskName );
if ( FAILED(hr) )
{
TRACE1("CScheduledTask::SaveTask() - couldn't delete existing task! Bailing out. Return = 0x%08X\n",
(DWORD) hr );
return hr;
}
}
}
// Create a new task.
hr = pISched->NewWorkItem ( T2COLE ( szTaskName ), CLSID_CTask,
IID_ITask, &pIUnk );
if ( FAILED(hr) )
{
TRACE1("CScheduledTask::SaveTask() - couldn't create a new work item. Return = 0x%08X\n",
(DWORD) hr );
return hr;
}
// We now have an IUnknown pointer. This is queried for an ITask
// pointer on the work item we just added.
hr = pIUnk->QueryInterface ( IID_ITask, (void **) &pITask );
if ( FAILED(hr) )
{
TRACE1("CScheduledTask::SaveTask() - QI() on IUnknown failed to get an ITask. Return = 0x%08X\n",
(DWORD) hr );
return hr;
}
// Clean up the IUnknown, as we are done with it.
pIUnk->Release();
pIUnk = NULL;
// Set the program name.
hr = pITask->SetApplicationName ( T2COLE( (LPCTSTR) m_sProgramPath ));
if ( FAILED(hr) )
{
TRACE1("CScheduledTask::SaveTask() - failed to set application. Return = 0x%08X\n",
(DWORD) hr );
return hr;
}
// Set the app's parameters.
if ( m_sParameters.GetLength() > 0 )
{
hr = pITask->SetParameters ( T2COLE( (LPCTSTR) m_sParameters ));
示例2: setScheduleTask
//.........这里部分代码省略.........
hr = pITask->CreateTrigger(&piNewTrigger, &pITaskTrigger);
if (FAILED(hr)) {
char* msg = readSystemErrorMsg(hr);
setErrorF(getLastErrorCode(), ERR_SCHED_CREATE_TRIGGER, hr, msg);
delete [] msg;
goto error;
}
}
else {
hr = pITask->GetTrigger(0, &pITaskTrigger);
if (FAILED(hr)) {
char* msg = readSystemErrorMsg(hr);
setErrorF(getLastErrorCode(), ERR_SCHED_GET_TRIGGER, hr, msg);
delete [] msg;
goto error;
}
}
//////////////////////////////////////////////////////
// Define TASK_TRIGGER structure.
// Start time is derived from NOW.
//////////////////////////////////////////////////////
TASK_TRIGGER pTrigger;
ZeroMemory(&pTrigger, sizeof (TASK_TRIGGER));
time_t timer;
time(&timer);
struct tm* now = localtime(&timer);
int minToSet = minNum;
if (minToSet == 1440) {
minToSet = 1439; // this because the windows scheduler thrown an error if
// the value is a day
}
pTrigger.wBeginDay = now->tm_mday; // START = NOW.
// TASK_TRIGGER uses wBeginMonth in interval (1,12), but tm_mon is in interval (0,11)
pTrigger.wBeginMonth = now->tm_mon + 1;
pTrigger.wBeginYear = now->tm_year + 1900; // 'struct tm' has year from 1900...
pTrigger.wStartHour = now->tm_hour;
pTrigger.wStartMinute = now->tm_min - 1; // -1 to avoid starting a sync right now!
pTrigger.cbTriggerSize = sizeof (TASK_TRIGGER) ;
pTrigger.MinutesDuration = 1440; // Duration = fixed 1 day.
pTrigger.MinutesInterval = minToSet;
pTrigger.TriggerType = TASK_TIME_TRIGGER_DAILY; // Manage only DAILY schedules!
pTrigger.Type.Daily.DaysInterval = dayNum;
//////////////////////////////////////////////////////
//
// Set trigger criteria.
//
hr = pITaskTrigger->SetTrigger(&pTrigger);
if (FAILED(hr)) {
if (hr == E_INVALIDARG) {
setErrorF(getLastErrorCode(), ERR_SCHED_SET_TRIGGER, hr, ERR_SCHED_INVALID_PARAM);
}
else {
char* msg = readSystemErrorMsg(hr);
setErrorF(getLastErrorCode(), ERR_SCHED_SET_TRIGGER, hr, msg);
delete [] msg;
}
goto error;
}
//
// Call IUnknown::QueryInterface to get a pointer to IPersistFile.
//
hr = pITask->QueryInterface(IID_IPersistFile, (void **)&pIPersistFile);
if (FAILED(hr)) {
char* msg = readSystemErrorMsg(hr);
setErrorF(getLastErrorCode(), ERR_SCHED_QUERY_INTERFACE, hr, msg);
delete [] msg;
goto error;
}
pITask->Release();
pITaskTrigger->Release();
//
// Save the task to disk.
//
hr = pIPersistFile->Save(NULL, TRUE);
if (FAILED(hr)) {
char* msg = readSystemErrorMsg(hr);
setErrorF(getLastErrorCode(), ERR_SCHED_SAVE, hr, msg);
delete [] msg;
goto error;
}
pIPersistFile->Release();
LOG.info(INFO_SCHED_TASK_CREATED);
CoUninitialize();
return 0;
error:
CoUninitialize();
LOG.error(getLastErrorMsg());
return 1;
}
示例3: SaveTask
//.........这里部分代码省略.........
TRACE0("CTask::SaveTask() - A task with the given name already exists; failing.\n");
return HRESULT_FROM_WIN32 ( ERROR_FILE_EXISTS );
}
else
{
//probujemy usunac istniejace zadanie, by zrobic miejsce dla naszego.
TRACE0("CTask::SaveTask() - A task with the given name already exists; deleting it.\n");
hr = CTask::DeleteTask ( szTaskName );
if ( FAILED(hr) )
{
TRACE1("CTask::SaveTask() - couldn't delete existing task! Bailing out. Return = 0x%08X\n",
(DWORD) hr );
return hr;
}
}
}
// tworzymy nowe zadanie.
hr = pISched->NewWorkItem ( T2COLE ( szTaskName ), CLSID_CTask,
IID_ITask, &pIUnk );
if ( FAILED(hr) )
{
TRACE1("CTask::SaveTask() - couldn't create a new work item. Return = 0x%08X\n",
(DWORD) hr );
return hr;
}
//mamy wskaznik do IUnknown, odpytujemy go, aby uzyskac
//wskaznik do interfejsu ITask
hr = pIUnk->QueryInterface ( IID_ITask, (void **) &pITask );
if ( FAILED(hr) )
{
TRACE1("CTask::SaveTask() - QI() on IUnknown failed to get an ITask. Return = 0x%08X\n",
(DWORD) hr );
return hr;
}
// wskaznika do IUnknown juz nie potrzebujemy
pIUnk->Release();
pIUnk = NULL;
// ustawiamy nazwe dla aplikacji
hr = pITask->SetApplicationName ( T2COLE( (LPCTSTR) m_sProgramPath ));
if ( FAILED(hr) )
{
TRACE1("CTask::SaveTask() - failed to set application. Return = 0x%08X\n",
(DWORD) hr );
return hr;
}
// ustawiamy parametry dla aplikacji
if ( m_sParameters.GetLength() > 0 )
{
hr = pITask->SetParameters ( T2COLE( (LPCTSTR) m_sParameters ));
if ( FAILED(hr) )
{