Solved

Reference to Task object in MS Project

Posted on 1997-04-15
9
425 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:re
  • 5
  • 4
9 Comments
 
LVL 1

Accepted Solution

by:
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  
//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
 

Author Comment

by:re
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.
0
 
LVL 1

Expert Comment

by:MFCGuy
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
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:re
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.
0
 
LVL 1

Expert Comment

by:MFCGuy
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,
MFCGuy
0
 

Author Comment

by:re
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.

re.
0
 
LVL 1

Expert Comment

by:MFCGuy
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,
MFCGuy

0
 

Author Comment

by:re
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:
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
 
LVL 1

Expert Comment

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

Sorry, I can't test it myself.

Hop I helped,
MFCGuy
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Question regarding Copy/Paste 16 95
Folder Comparison 12 54
java ^ examples 8 65
"Black Box" Testing of Control System Software 2 49
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

805 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