Reference to Task object in MS Project

Posted on 1997-04-15
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
Question by:re
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4

Accepted Solution

MFCGuy earned 100 total points
ID: 1301019
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...


Author Comment

ID: 1301020
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.

Expert Comment

ID: 1301021
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 1301022
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.

Expert Comment

ID: 1301023
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,

Author Comment

ID: 1301024
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.


Expert Comment

ID: 1301025
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,


Author Comment

ID: 1301026
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.

Expert Comment

ID: 1301027
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,

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
repeatSeparator  java  challenge 13 58
isEverywhere  challenge 19 85
matchUp  challenge 6 76
Thin secure Windows 10 5 107
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question