Reference to Task object in MS Project

Hi,

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
"Task")??

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
reAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MFCGuyCommented:
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  
//Application->GetActiveProject()

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

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...

Bye,
MFCGuy
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
reAuthor Commented:
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.
0
MFCGuyCommented:
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
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

reAuthor Commented:
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.
0
MFCGuyCommented:
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,
MFCGuy
0
reAuthor Commented:
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.

re.
0
MFCGuyCommented:
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,
MFCGuy

0
reAuthor Commented:
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:
task1.LinkSuccessors(COleVariant(task2));

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.
0
MFCGuyCommented:
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
task1.LinkSuccessors(temp);

Sorry, I can't test it myself.

Hop I helped,
MFCGuy
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.