I have a function which is to Enumerate Project Tasks. Each Task goes into it's own __gc class, and therefore is in a class array. With unmanaged C++ it is easy to change the data a pointer points to. However, this managed C++ seems to garbage collect when the original pointer leaves the scope.
I am using /oldSyntax line.
Here is some brief code of my function. Please note that CSchedTask is __gc class CSchedTask.
EnumScheduleTasks(String *ProjectID, CSchedTask *Tasks)
MyDataset *dsTasks =
//... more code is here which defines iTasks, int iTasks = ...;
CSchedTask __pin *cTasks = new CSchedTask*[iTasks];
cTasks = new CSchedTask();
strQuery = S"SELECT * FROM HS_ProjectTask WHERE ProjectID = '";
cstrcat(&strQuery, S"' AND ProjectElementID Is NULL ORDER BY Sequence");
dsTasks->SQLText = strQuery;
//Populate cTasks class array with Tasks values.
cTasks->ProjectTaskID = dsTasks->ReadString(S
cTasks->ProjectComponentID = dsTasks->ReadString(S"ProjectComponentID");
cTasks->IsDetailedSchedule = dsTasks->ReadShort("IsDetailedSchedule");
cTasks->IsComplete = dsTasks->ReadShort("IsComplete");
cTasks->IsStartDateFixed = dsTasks->ReadShort("IsStartDateFixed");
cTasks->Duration = Convert::ToUInt32(dsTasks->ReadString(S"Duration"));
cTasks->StartDate = dsTasks->ReadDateTime("StartDate");
cTasks->EndDate = dsTasks->ReadDateTime("EndDate");
//Tasks array now is equal to cTasks array. After this function ends, the array Tasks points to is <undefined value>
Tasks = cTasks;
The calling code is below:
int iTasks = EnumScheduleTasks(S"C7D2D63F2FD84C18AD9EB9BBF66D585E", cTask);
At this point cTask is undefined and contains no data.
Any help is greatly appreciated. I'm likely missing something incredibly simple.