Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

I sent a matrix,its row and column to a child window. However "Acess violation" & 'Memory cannot be reference" error occurs when I try to plot the data in the child dialogue. Why?

My OS is Win200 professional.
I'm running a data acquisition program. I'd got this main dialog which the user selects the input channel.
The child dialog should show the graph.
I'd initialise all the NI_DAQ configuration in the main dialog class. After acquiring the data, I send the matrix to the child window for it to plot. There is no compilation error.
However when I try to plot the data, Windows complained about Acess violation and Memory cannot be accessed error.
I'd attached my program below.
Download All
0 Kudos
Message 1 of 4
(3,017 Views)
Wynn:

I believe this problem is occurring because you are using the index operator (brackets "[","]") instead of the functional call operator (parentheses "(",")") in your code to access the matrix.

SigCh1Vect[i] = SigCh1Max[1,i];

The index operator is not defined for the matrix, because the C++ language does not allow a two-argument overload of this operator. Instead you have to use the function call operator for matrices and remember to use the index operator for vectors.

I believe that what is happening is that the compiler is using one of the defined cast operators on the matrix (operator DataType) to convert the symbol "SigCh1Max" into a double pointer. It then interprets the bracket as it would any array index operation. So the compile
r effectively sees:

SigCh1Vect[i] = *(((Real64*)SigCh1Max) + (1,i));

In this case, I believe the comma operator is defined to return the rightmost operand, or "i". Changing your code to

SigCh1Vect[i] = SigCh1Max(1,i);

should fix the problem. Please let me know if any issues exist after this fix.

In the next release of Measurement Studio, I will recommend that the index operator be defined on the matrix classes, even if it simply throws an exception. The existence of this operator will prevent problems like this from showing up.

Hope this helps,

-- Chris W.
Measurement Studio R&D
National Instruments
0 Kudos
Message 2 of 4
(3,017 Views)
Wynn:

I forgot to mention that the CNiMatrixT<>::CopyColumn() function is already defined that you can use instead of this for loop in your child window code. Since the index operator on CNiVector and the function call operator on CNiMatrix perform bounds-checking, in addition to being easier to use, this function will be faster than executing a for loop.

-- Chris
0 Kudos
Message 3 of 4
(3,017 Views)
I still got the problem after changing it.
I got 4 windows prompt:
The instruction at " " referenced memory at "0xcccccd44". The memory could not be read.

The instruction at " " referenced memory at "0x0x68677561". The memory could not be read.

The instruction at " " referenced memory at "0x5f4abf54". The memory could not be read.

The instruction at " " referenced memory at "0x5f4abf54". The memory could not be read.
Download All
0 Kudos
Message 4 of 4
(3,017 Views)