04-02-2009 07:02 AM
hello,
I have a Write() - function which agrees array handed over which writes to me different worth in a file. if I liked to call now this function with a button the following error comes:
FATAL RUN-TIME ERROR: Dynamic memory is corrupt.
if I call the function in the main (), NO error comes.
can somebody say to me what I have made wrong?
Thanks
int CVICALLBACK GenerateFileCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
STRUCT_STEP_VALUES ARRGenerate;
switch (event)
{
case EVENT_COMMIT:
ARRGenerate = WriteFile( arrayWriteFile );
WriteOutputFile( &ARRGenerate );
break;
}
return 0;
}
04-06-2009 10:06 PM - edited 04-06-2009 10:08 PM
I'll take a crack at this ...
I think by "worth" you may mean "values", and "agrees" means "accepts", "handed over" means "passed in". Looks like auto-translation maybe
If ARRGenerate is the returned array address (i.e.. array name) from your function WriteFile, then when you reference it with the address operator & you''re getting the address of the address of the array, not the address of the array.
So when you call WriteOutputFile (&ARRGenerate) you could get a memory violation.
Maybe it should be this:
WriteOutputFile (ARRGenerate);
In C, the name of the array is actually a pointer to the first element of the array. So to get the address of the array, you just use its name, you don't need to reference it again with the & operator.
Menchar
04-06-2009 10:18 PM
My bad -
&arrayname evaluates the same as arrayname in C ... so ignore previous post ...
Where is arrayWriteFile defined? Is it WriteFile ( ) or WriteOutputFile ( ) that gives the error?
Menchar