Scheduler: Wanting to add new item to task list.



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.


.



Relevant Pages

  • Scheduler: Wanting to add a task
    ... This is a C++ dll that I've written, which is called from a VB app. ... STDAPI DllCanUnloadNow ... typelib and all interfaces in typelib ... // DllUnregisterServer - Removes entries from the system registry ...
    (microsoft.public.win32.programmer.ole)
  • Scheduler question
    ... I know this might not be the perfect forum, but wasn't sure where to ask, and ... This is a C++ dll that I've written, which is called from a VB app. ... STDAPI DllCanUnloadNow ... // DllUnregisterServer - Removes entries from the system registry ...
    (microsoft.public.win32.programmer.kernel)
  • regsvr32 error: Could not locate DllRegisterServer entry point
    ... I have written a very simplistic COM dll and to my dismay when I try to ... register it with regsvr32 I recieve the error message that the dll was loaded ... In my desparation I even broke down STDAPI ...
    (microsoft.public.win32.programmer.ole)

Loading