I'm currently working on a project with a few other people, who are sadly no longer available for reference material. This project uses C# for the GUI, and C++ for updating our archaic database. At the moment, I have this function in C#:
[DllImport("Synch.DLL", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
//Synch bool Synch(void * voidPtr, const TCHAR * databaseDir, const TCHAR * truckDir)
static extern Int32 Synch(IntPtr pSync, string databaseDir, string destDir, ref bool[] wholeFiles);
wholeFiles is an array of booleans used to determine if certain files should be synced or not, based on user input.
The C++ is supposed to take in this array, and be able to flip some of the bools to true or false as certain conditions are met.
if (numSyncRecords > 0){
Log::WriteVerbose(_T(" %d recs, %d differences found"), (int) numRecsUsed, (int) numSynRecords);
if(wholeFiles[sourceFileID]){
CString tempPath = _T("");
tempPath += destDir;
tempPath += fileName;
DeleteFile(tempPath);
}
else
wholeFiles[sourceFileID] = false;
}
else
wholeFiles[sourceFileID] = false;
In the case above, I pass in Trues, and if there are no changes to the file, set it to false to avoid processing a file that doesn't need it.
Now, my issue is, when the C++ code is finished, there are still True marks when they should be set to false. If I send it in by ref, then I get a stack overflow. Without ref, the array doesn't seem to change.
Edit: This was requested.
SYNC_API Int32 Synch(void * voidPtr, const TCHAR * databaseDir, const TCHAR * truckDir, bool wholeFiles[])
Edit2: I have, in the C++ code, a log statement that loops over the array and outputs true/false once per line per position in the wholeFiles array, and I end up with the appropriate log output, but when I look at the Array on the C# code after that is done, it's unchanged.