[Webinar] Streamline your web hosting managementRegister Today


Reference to Task object in MS Project

Posted on 1997-04-15
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
Question by:re
  • 5
  • 4

Accepted Solution

MFCGuy earned 200 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

607 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