Scheduler: Wanting to add new item to task list.
- From: Les Stockton <LesStockton@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 25 May 2005 09:10:01 -0700
I'm wanting to add a task to the scheduler, and followed instructions as best
I could from documentation I've found on the Microsoft site, as well as
elsewhere. The task gets added, but the name is garbled and can't seem to
get past it, even when hardcoding the name in the call to NewWorkItem, using
L"Test Task".
This is a C++ dll that I've written, which is called from a VB app. If I
could only get past this, then adding the other properties would be a cinch,
I think.
Here's the code:
CComModule _Module;
BEGIN_OBJECT_MAP(ObjectMap)
END_OBJECT_MAP()
/////////////////////////////////////////////////////////////////////////////
// DLL Entry Point
extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID
/*lpReserved*/)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
_Module.Init(ObjectMap, hInstance, &LIBID_TASKSCHEDULERLib);
DisableThreadLibraryCalls(hInstance);
}
else if (dwReason == DLL_PROCESS_DETACH)
_Module.Term();
return TRUE; // ok
}
/////////////////////////////////////////////////////////////////////////////
// Used to determine whether the DLL can be unloaded by OLE
STDAPI DllCanUnloadNow(void)
{
return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// Returns a class factory to create an object of the requested type
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
return _Module.GetClassObject(rclsid, riid, ppv);
}
/////////////////////////////////////////////////////////////////////////////
// DllRegisterServer - Adds entries to the system registry
STDAPI DllRegisterServer(void)
{
// registers object, typelib and all interfaces in typelib
return _Module.RegisterServer(TRUE);
}
/////////////////////////////////////////////////////////////////////////////
// DllUnregisterServer - Removes entries from the system registry
STDAPI DllUnregisterServer(void)
{
return _Module.UnregisterServer(TRUE);
}
int __stdcall AddNewTask(char *TaskName)
{
long status;
ITaskScheduler *pITS;
LPCWSTR pwszTaskName;
ITask *pITask;
IPersistFile *pIPersistFile;
LPCWSTR pwszComment;
status = 0;
// strcpy((char*)pwszTaskName,TaskName);
USES_CONVERSION;
pwszTaskName = L"Test Task";
// l =
MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,TaskName,strlen(TaskName),pwszTaskName,20);
// Call CoInitialize to initialize the COM library and then
// CoCreateInstance to get the Task Scheduler object.
//
status = CoInitialize(NULL);
if (SUCCEEDED(status))
{
status = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(status))
{
CoUninitialize();
return status;
}
}
else
{
// Must've had a failure in CoInitialize, and need to quit here.
return 1;
}
status = pITS->NewWorkItem(L"Test Task",
CLSID_CTask,
IID_ITask,
(IUnknown **)&pITask);
pITS->Release();
if (status == E_INVALIDARG)
{
CoUninitialize();
return status;
}
if (FAILED(status))
{
CoUninitialize();
return status;
}
// Call IUnknown::QueryInterface to get a pointer to IPersistFile and
// IPersistFile::Save, which will allow us to savethe new task to disk.
//
status = pITask->QueryInterface(IID_IPersistFile,
(void **) &pIPersistFile);
pITask->Release();
if (FAILED(status))
{
CoUninitialize();
return status;
}
status = pIPersistFile->Save(NULL, TRUE);
pIPersistFile->Release();
if (FAILED(status))
{
CoUninitialize();
return status;
}
return status;
}
I've tried all sorts of things, and it just doesn't seem to matter.
.
- Follow-Ups:
- Re: Scheduler: Wanting to add new item to task list.
- From: David Lowndes
- Re: Scheduler: Wanting to add new item to task list.
- Prev by Date: Re: Currently running applications
- Next by Date: Re: LoadLibraryEx (as datafile) and MorIcons.dll - extracting icons
- Previous by thread: Currently running applications
- Next by thread: Re: Scheduler: Wanting to add new item to task list.
- Index(es):
Relevant Pages
|
Loading