We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


Reference to Task object in MS Project

re asked
Medium Priority
Last Modified: 2013-11-20

I already have a OLE client program which starts MSProject 4.1a on my WinNT 4.0 machine using OLE objects.

I know how to open a file remotely and how to add tasks and so on. But it seems not to be easy to get a reference to
one only task inside a MSProject workspace. Is there a way to get a reference to one single task (a variable from class

If I have this it's then simple to manipulate the task.

As an additional explanation: If I have a reference to the Application (in this case MS Project itself) then I can get a reference to all the tasks just by calling GetTasks(), but there is no direct way to get a reference to only one task

Thanks in advance, re
Watch Question

Override GetTasks to pass a parameter like this:
in your Project .h (pj4en32.h?)
class Project ...
   LPDISPATCH GetTasks(const VARIANT& index);

in the .cpp (pj4en32.cpp?)
LPDISPATCH Project::GetTasks(const VARIANT& index)
      LPDISPATCH result;
      static BYTE parms[] = VTS_VARIANT;
      InvokeHelper(0x1, DISPATCH_METHOD, VT_DISPATCH, (void*)&result, parms, &index);
      return result;

Call it like this
//project is an object returned from  

      //Get first task and set its date
LPDISPATCH tmpDisp = project.GetTasks(COleVariant(short(1)));
ProjectTask task;
//Set First Task start date

Any function call that has different forms according to the Project on-line help can be overridden in a similar manner.  Why ClassWizard doesn't generate all the overriden functions, I'll never know...


Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Thanks very much for your answer.

I typed in the code you gave me and everything compiles fine.
As far as I know your code works (the answers you gave me to older questions). But for me it's now not provable if your code really works. Maybe you know a simple solution for that.

I'm working on Windows NT Workstation 4.0 (Service Pack 2) and I cannot start MS Project remotely any more. I checked the registry but the entry for "MSProject.Application" is still there. I don't understand why this OLE object can't be created.

Another phenomena which happens is the following: If I double-click on a project file created by MS Project and MS Project isn't started then I get a message saying that the permissions are not correct. I checked all the permissions in the path to MS Project and they are all set, so that the program can be started.

I can start MS Project directly by double clicking on its icon, no problem.

Is there a simple way to solve this or does a tool like Norton Utilities can solve this or do I really have to reinstall the complete system to solve??

Thanks in advance, re.

Sorry, no ideas come to mind.

I've heard sp2 is not up to par, however.

I doubt you have to reinstall the whole, maybe just uninstall/install MSProject


Hi MFCGuy,

just uninstalling and reinstalling of an application doesn't solve that problem. I think I have to wait for Norton Utilities.

Thanks, re.

How is Norton Utilities going to solve a permissions problem?

If you are Local Administrator on your NT box (assuming you are on a domain, otherwise this will probably work anyway), set the permissions from C:\ on down to whatever you want, e.g. Full Control by your id.  Make sure to check "Replace Permission on subdirectories"

Maybe that will help,


Maybe I explained something wrong.

There is no permissions problem!! That's what the system tells me but there is nothing wrong. Look!! If I double click on the MSProject icon itself then MSProject starts and runs correctly. If I try to start it by double clicking on a file created by MSProject, then I get this message telling permission problems. And if I use OLE to start project I get an error message saying it was impossible to create the OLE object. This happens when the registry database is searched for an entry called "MSProject.Application". I think that there is only a registry error. If you double click a file (not the application itself) then, I think, the system looks in the registry for an application belonging to that file and then starts it. In my case there is something wrong in the registry, so the system can't find the MSProject application entry and tells me something about a permission problem that doesn't exist. If it would exist, there would be no possiblity to start the application itself either.
But I wonder that I can see the registry entry of MSProject by searching in the "regedit.exe" program and the system can't. But maybe there is something else the system needs and it doesn't exist or is wrong.

So I think, a tool like Norton can maybe recreate the registry database and solve that problem.


You are right, I read your note wrong.

If there is a registry problem, you could try uninstalling
MSProject, deleting all the registry entries relating to MSProject (assuming you know what they are or can find them all)
and reinstall.  At a minimum since the symptoms seem to be be the association of .mpp with MSProject, you could delete those entries in HKEY_CLASSES_ROOT (.mpp) and reinstall.

There are permissions on the registry, too, in case that is the problem...

You could always restore from your rescue disk.  :-)

I'm sure that didn't help,



Hi MFCGuy,

I just solved my problem with the NT OS just by formatting the harddisk and reinstalling everything.

Oh, by the way your code example to manipulate a single task is really fine.

OK, now back to the problem I have now. I tried to link two single tasks in MS Project together, so that one of them is the successor of the other. For this I wanted to use the method "LinkSuccessors()". I redefined this method so that it needs only one parameter, which is the successor task itself. The problem I have is, that I don't know which data type to pass as parameter.
The definition of this method looks like this:
void LinkSuccessors(const VARIANT& Tasks);

I have a variable of type "Task", which can not be passed (compiler error).
I have also a variable of type "LPDISPATCH" which also can't be passed (compiler error). Both times I tried to type cast the variables to "COle Variant", like this:

A third way I tried was to pass the row number (for example: short(2)), but this didn't work at run time, because the OLE server told a wrong data type to be passed.

So I wanted to find out what to do. The "VARIANT" help in VC++ shows the complete structure and tells which data types are allowed to pass as COleVariant. So I looked into the help of MSProject. It says that "task" is "A Task object or Tasks collection.  The task you specify with the task argument becomes a successor to the tasks you specify with the object expression.  Required."

So this doesn't help any further, because "object" can mean different data types.

So please can you tell me how to find out which data type to pass in especially this situation and in general.

Thanks in advance, re.

I haven't done what you area asking but from looking at the help, I would try doing the following:

COleVariant temp;
temp.pdispVal = task2;  //set the VT_DISPATCH prtion of COleVariant

Sorry, I can't test it myself.

Hop I helped,
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.